Skip to content

jevvonn/sea-catering-be

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SEA Catering πŸ₯• - Backend API

This repository contains the backend service for the SEA Catering application. It is a robust RESTful API built with Go (Golang) and the Fiber web framework, providing all the necessary business logic for user authentication, subscription management, and administrative reporting.

Language Framework Database CI/CD


Table of Contents

About The Project

This backend service is the powerhouse behind the SEA Catering platform. It handles all data persistence, user management, and core functionalities. It's designed to be scalable, secure, and efficient, exposing a clean REST API for web application to consume.

Features

The API provides a complete set of features for a modern subscription-based service:

πŸ” Authentication & Authorization

  • User Registration: Securely register new users.
  • JWT-Based Login: Authenticate users and issue JSON Web Tokens (JWT) for session management.
  • Session Validation: An endpoint to verify a user's token and retrieve their session data.
  • Role-Based Access Control (RBAC): Differentiates between USER and ADMIN roles to protect sensitive endpoints.

πŸ‘¨πŸ» User-Facing Features

  • View Meal Plans: Fetch a list of all available meal plans.
  • Create Subscriptions: Subscribe to a meal plan with custom options (meal types, delivery days, allergies).
  • Manage Subscriptions: View, update (e.g., pause/resume), and cancel personal subscriptions.
  • Submit Testimonials: Provide feedback and ratings.

πŸ‘‘ Admin-Facing Features

  • Subscription Reporting: Generate business reports with date-range filters to view metrics.
  • Plan Management: Update details of existing meal plans.

API Documentation

This API is documented using Swagger 2.0.

  • Live Documentation: You can access the live Swagger UI here: https://sea-catering-api.bccdev.id/docs

  • Local Documentation: After running the server locally, the Swagger UI will be available at http://localhost:3001/docs/index.html.

To regenerate the documentation from code comments, you can use the following commands:

  • Using Make:
    make generate-docs
  • Using Go CLI:
    swag init -g cmd/api/main.go

Tech Stack

Getting Started

Follow these instructions to get the backend service running on your local machine for development.

Prerequisites

Local Setup

  1. Clone the repository:

    git clone https://github.com/jevvonn/sea-catering-be.git
    cd sea-catering-be
  2. Configure Environment Variables: Create a .env file from the example. The default database values are pre-configured to work with the provided docker-compose.yml.

    cp .env.example .env

    Open the new .env file and fill all the values.

    APP_ENV=development # or production
    APP_PORT=3001
    
    DB_USER=postgres
    DB_PASSWORD=yourpassword
    DB_NAME=sea_catering_db
    DB_HOST=localhost
    DB_PORT=5432
    
    # Generate a strong secret with: openssl rand -base64 32
    JWT_SECRET=your-super-strong-jwt-secret
  3. Start the Database: This command will start a PostgreSQL container in the background.

    docker-compose up -d
  4. Install Go Dependencies:

    go mod tidy
  5. Initialize the Database (First-Time Setup Only): For the first time, you need to run migrations to create the tables and then seed the database with initial data.

    Step 5a: Run Migrations

    • Using Make:
      make migrate-up
    • Using Go CLI:
      go run cmd/api/main.go -m up

    Step 5b: Seed the Database

    • Using Make:
      make db-seed
    • Using Go CLI:
      go run cmd/api/main.go -s
  6. Run the Application: Now you can start the API server.

    • Using Make:
      make run
    • Using Go CLI:
      go run cmd/api/main.go
      The server will now be running at http://localhost:3001.

Makefile Commands

This project includes a Makefile to simplify common development tasks.

  • make run: Starts the application server.
  • make migrate-up: Applies all pending database migrations.
  • make migrate-down: Drop all the database table and data.
  • make db-seed: Seeds the database with initial data (e.g., user roles, meal plans).
  • make generate-docs: Regenerates the Swagger API documentation.

CI/CD Pipeline

This project uses a pull-based deployment strategy automated with GitHub Actions.

  • Workflow File: .github/workflows/deploy.yml
  • Trigger: The workflow is triggered on every push to the main branch.

Deployment Process:

The workflow connects to the production VM via SSH and executes a deployment script. The script performs the following steps on the server:

  1. Navigates to the project directory (cd sea-catering-be).
  2. Pulls the latest changes from the main branch (git pull).
  3. Uses Docker Compose to rebuild the application's Docker image and restart the service in the background (sudo docker compose up -d --build).

This approach ensures the application is always running the latest code from the main branch, with the build process happening directly on the target server.

Required GitHub Secrets:

For the deployment action to work, the following secrets must be configured in the GitHub repository settings:

  • SERVER_HOST: The IP address or domain of the deployment server.
  • SERVER_USER: The username for SSH login.
  • SSH_PRIVATE_KEY: The private SSH key for authenticating with the server.
  • SERVER_PASSPHRASE: The passphrase for the SSH key, if it has one.
  • SERVER_PORT: The SSH port of the server (usually 22).

Project Structure

The project follows a standard Go application layout to separate concerns.

/
β”œβ”€β”€ cmd/
β”‚   └── api/
β”‚       └── main.go         # Main application entry point
β”œβ”€β”€ config/                 # Environment variable and configuration loading
β”œβ”€β”€ docs/                   # Swagger documentation files
β”œβ”€β”€ internal/               # Main application logic
β”‚   β”œβ”€β”€ domain/             # Domain models (entities and dtos)
β”‚   β”œβ”€β”€ middleware/         # Custom Fiber middleware (e.g., auth)
β”‚   β”œβ”€β”€ app/                # Application handler, usecases, and repositories
β”‚   β”œβ”€β”€ service/            # Business logic
β”‚   └── ...                 # Other internal packages
β”œβ”€β”€ .github/workflows/      # CI/CD workflow definitions
β”œβ”€β”€ docker-compose.yml      # Docker configuration for local database
└── go.mod                  # Go module dependencies

Contact

Jevon Mozart - jmcb1602@gmail.com

Project Link: https://github.com/jevvonn/sea-catering-be

About

SEA Catering πŸ₯• - Backend API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors