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.
- About The Project
- Features
- API Documentation
- Tech Stack
- Getting Started
- Makefile Commands
- CI/CD Pipeline
- Project Structure
- Contact
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.
The API provides a complete set of features for a modern subscription-based service:
- 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
USERandADMINroles to protect sensitive endpoints.
- 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.
- Subscription Reporting: Generate business reports with date-range filters to view metrics.
- Plan Management: Update details of existing meal plans.
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
- Language: Go
- Web Framework: Fiber v2
- Database: PostgreSQL
- ORM: GORM
- Containerization: Docker & Docker Compose
- Development Tool: Make
- Deployment: Ubuntu VM
- CI/CD: GitHub Actions
Follow these instructions to get the backend service running on your local machine for development.
- Go (v1.20 or later)
- Docker & Docker Compose
- Make (optional, but recommended for convenience)
- swag (for generating API docs)
-
Clone the repository:
git clone https://github.com/jevvonn/sea-catering-be.git cd sea-catering-be -
Configure Environment Variables: Create a
.envfile from the example. The default database values are pre-configured to work with the provideddocker-compose.yml.cp .env.example .env
Open the new
.envfile 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
-
Start the Database: This command will start a PostgreSQL container in the background.
docker-compose up -d
-
Install Go Dependencies:
go mod tidy
-
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
- Using Make:
-
Run the Application: Now you can start the API server.
- Using Make:
make run
- Using Go CLI:
The server will now be running at
go run cmd/api/main.go
http://localhost:3001.
- Using Make:
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.
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
pushto themainbranch.
The workflow connects to the production VM via SSH and executes a deployment script. The script performs the following steps on the server:
- Navigates to the project directory (
cd sea-catering-be). - Pulls the latest changes from the
mainbranch (git pull). - 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.
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).
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
Jevon Mozart - jmcb1602@gmail.com
Project Link: https://github.com/jevvonn/sea-catering-be