Skip to content

Ablebil/sea-catering-be

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

73 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Sea Catering API

Sea Catering Backend API is a backend application for a catering service built with Go using Clean Architecture. This application provides services for managing meal plans, subscriptions, user authentication, testimonials, and payment integration.


Tech Stack

  • Language: Go 1.23.2
  • Web Framework: Fiber v2
  • Database: PostgreSQL
  • Cache: Redis
  • ORM: GORM
  • Authentication: JWT
  • Payment Gateway: Midtrans
  • File Storage: Supabase Storage
  • Containerization: Docker & Docker Compose
  • Documentation: Swagger

Features

  • πŸ” Authentication & Authorization: JWT-based auth with Google OAuth
  • πŸ‘€ User Management: Registration, login, profile management
  • 🍽️ Meal Plan Management: CRUD operations for meal plans
  • πŸ“ Subscription System: Subscription management with payment integration
  • πŸ’¬ Testimonials: User reviews and ratings
  • πŸ’³ Payment Integration: Midtrans payment gateway
  • πŸ“§ Email Service: Email notifications
  • πŸ“ File Upload: Image upload to Supabase storage
  • πŸ“Š Analytics: Dashboard stats for admin
  • πŸ”„ Caching: Redis for optimal performance

Folder Structure

.
β”œβ”€β”€ .dockerignore              # Docker ignore file
β”œβ”€β”€ .env                       # Environment variables (local)
β”œβ”€β”€ .env.example               # Template environment variables
β”œβ”€β”€ .gitignore                 # Git ignore file
β”œβ”€β”€ docker-compose.yaml        # Docker compose configuration
β”œβ”€β”€ Dockerfile                 # Docker build file
β”œβ”€β”€ go.mod                     # Go module file
β”œβ”€β”€ go.sum                     # Go module checksums
β”œβ”€β”€ Makefile                   # Build automation
β”œβ”€β”€ README.md                  # Project documentation
β”œβ”€β”€ cmd/                       # Application entry points
β”‚   └── api/
β”‚       └── main.go            # Main application entry point
β”œβ”€β”€ config/                    # Configuration
β”‚   └── config.go              # Application configuration setup
β”œβ”€β”€ docs/                      # API Documentation
β”‚   β”œβ”€β”€ docs.go                # Swagger documentation generator
β”‚   β”œβ”€β”€ swagger.json           # Swagger JSON specification
β”‚   └── swagger.yaml           # Swagger YAML specification
└── internal/                  # Internal application code
    β”œβ”€β”€ app/                   # Application domains
    β”‚   β”œβ”€β”€ auth/              # Authentication domain
    β”‚   β”‚   β”œβ”€β”€ interface/
    β”‚   β”‚   β”‚   └── rest/      # REST API handlers
    β”‚   β”‚   β”œβ”€β”€ repository/    # Data access layer
    β”‚   β”‚   └── usecase/       # Business logic layer
    β”‚   β”œβ”€β”€ meal_plan/         # Meal Plan domain
    β”‚   β”‚   β”œβ”€β”€ interface/
    β”‚   β”‚   β”‚   └── rest/      # REST API handlers
    β”‚   β”‚   β”œβ”€β”€ repository/    # Data access layer
    β”‚   β”‚   └── usecase/       # Business logic layer
    β”‚   β”œβ”€β”€ subscription/      # Subscription domain
    β”‚   β”‚   β”œβ”€β”€ interface/
    β”‚   β”‚   β”‚   └── rest/      # REST API handlers
    β”‚   β”‚   β”œβ”€β”€ repository/    # Data access layer
    β”‚   β”‚   └── usecase/       # Business logic layer
    β”‚   β”œβ”€β”€ testimonial/       # Testimonial domain
    β”‚   β”‚   β”œβ”€β”€ interface/
    β”‚   β”‚   β”‚   └── rest/      # REST API handlers
    β”‚   β”‚   β”œβ”€β”€ repository/    # Data access layer
    β”‚   β”‚   └── usecase/       # Business logic layer
    β”‚   └── user/              # User domain
    β”‚       β”œβ”€β”€ interface/
    β”‚       β”‚   └── rest/      # REST API handlers
    β”‚       β”œβ”€β”€ repository/    # Data access layer
    β”‚       └── usecase/       # Business logic layer
    β”œβ”€β”€ bootstrap/             # Application initialization
    β”‚   └── bootstrap.go       # Dependency injection & app setup
    β”œβ”€β”€ domain/                # Domain models
    β”‚   β”œβ”€β”€ dto/               # Data Transfer Objects
    β”‚   β”‚   β”œβ”€β”€ auth.go        # Authentication DTOs
    β”‚   β”‚   β”œβ”€β”€ meal_plan.go   # Meal Plan DTOs
    β”‚   β”‚   β”œβ”€β”€ subscription.go# Subscription DTOs
    β”‚   β”‚   β”œβ”€β”€ testimonial.go # Testimonial DTOs
    β”‚   β”‚   └── user.go        # User DTOs
    β”‚   └── entity/            # Database entities
    β”‚       β”œβ”€β”€ meal_plan.go   # Meal Plan entity
    β”‚       β”œβ”€β”€ subscription.go# Subscription entity
    β”‚       β”œβ”€β”€ testimonial.go # Testimonial entity
    β”‚       └── user.go        # User entity
    β”œβ”€β”€ infra/                 # Infrastructure layer
    β”‚   β”œβ”€β”€ email/             # Email service implementation
    β”‚   β”œβ”€β”€ fiber/             # Fiber web framework setup
    β”‚   β”œβ”€β”€ jwt/               # JWT token implementation
    β”‚   β”œβ”€β”€ midtrans/          # Midtrans payment gateway
    β”‚   β”œβ”€β”€ oauth/             # OAuth implementation (Google)
    β”‚   β”œβ”€β”€ postgresql/        # PostgreSQL database setup
    β”‚   β”‚   β”œβ”€β”€ migration.go   # Database migrations
    β”‚   β”‚   β”œβ”€β”€ postgresql.go  # Database connection
    β”‚   β”‚   └── seed.go        # Database seeding
    β”‚   β”œβ”€β”€ redis/             # Redis cache implementation
    β”‚   β”œβ”€β”€ response/          # HTTP response utilities
    β”‚   └── supabase/          # Supabase storage integration
    β”œβ”€β”€ middleware/            # HTTP middlewares
    β”‚   β”œβ”€β”€ authentication.go  # Authentication middleware
    β”‚   β”œβ”€β”€ authorization.go   # Authorization middleware
    β”‚   └── middleware.go      # Middleware interface
    └── pkg/                   # Shared packages
        β”œβ”€β”€ helper/            # Helper utilities
        β”œβ”€β”€ limiter/           # Rate limiting
        └── scheduler/         # Background job scheduler

Structure Explanation

/cmd

Application entry point. Contains the main.go file which initializes and runs the application.

/config

Application configuration that reads environment variables and sets up global configuration.

/docs

API documentation generated by Swagger for endpoint documentation.

/internal/app

Domain-driven design where each domain has:

  • interface/rest: HTTP handlers for the REST API
  • repository: Data access layer for database operations
  • usecase: Business logic layer

/internal/bootstrap

Dependency injection and application initialization. Manages all dependencies and routing.

/internal/domain

  • dto: Data Transfer Objects for requests/responses
  • entity: Database models with GORM tags

/internal/infra

Infrastructure layer containing implementations for:

  • email: Service for sending emails
  • fiber: Web framework setup
  • jwt: JWT token management
  • midtrans: Payment gateway integration
  • oauth: Google OAuth implementation
  • postgresql: Database connection and operations
  • redis: Caching layer
  • response: Standardized HTTP responses
  • supabase: File storage integration

/internal/middleware

HTTP middlewares for authentication, authorization, and more.

/internal/pkg

Shared utilities and packages that can be used across the application.


Setup & Installation

Prerequisites

  • Go 1.23.2+
  • Docker & Docker Compose
  • PostgreSQL (if not using Docker)
  • Redis (if not using Docker)

Environment Variables

Copy the .env.example file to .env and fill it with the appropriate values:

cp .env.example .env

Fill in the required environment variables

Running the Application

Using Docker (Recommended)

# Clone the repository
git clone <repository-url>
cd sea-catering-be

# Run with Docker Compose
make run
# or
docker-compose up

# Rebuild containers
make build
# or
docker-compose up --build

Running Locally

# Install dependencies
go mod download

# Run the application
go run cmd/api/main.go

Make Commands

make run                   # Run the application with Docker
make build                 # Rebuild containers
make stop                  # Stop containers
make logs                  # View logs
make restart               # Restart containers
make down-remove-volumes   # Stop and remove volumes

API Documentation

Once the application is running, the Swagger API documentation can be accessed at:

http://localhost:8080/swagger/

API Endpoints

Authentication

  • POST /api/v1/auth/register - Register a new user
  • POST /api/v1/auth/login - Login user
  • GET /api/v1/auth/google - Google OAuth login
  • GET /api/v1/auth/google/callback - Google OAuth callback
  • POST /api/v1/auth/refresh - Refresh token
  • POST /api/v1/auth/logout - Logout user

Meal Plans

  • GET /api/v1/meal-plans/ - Get all meal plans
  • GET /api/v1/meal-plans/:id - Get meal plan by ID

Subscriptions

  • POST /api/v1/subscriptions/ - Create a new subscription
  • GET /api/v1/subscriptions/ - Get user subscriptions
  • PUT /api/v1/subscriptions/:id/pause - Pause a subscription
  • DELETE /api/v1/subscriptions/:id - Cancel a subscription

Admin Endpoints

  • POST /api/v1/meal-plans/admin/ - Create a new meal plan
  • GET /api/v1/subscriptions/admin/stats/new - New subscriptions stats
  • GET /api/v1/subscriptions/admin/stats/mrr - Monthly recurring revenue
  • GET /api/v1/subscriptions/admin/stats/active-total - Total active subscriptions
  • GET /api/v1/subscriptions/admin/stats/reactivations - Reactivation stats

Database

The application uses PostgreSQL with GORM as the ORM. The database will be automatically migrated and seeded when the application is first run.

Seeded Data

The application will automatically add initial data:

  • Users: Admin and sample users
  • Meal Plans: Diet Plan, Protein Plan, Royal Plan, Vegan Plan
  • Testimonials: Sample testimonials

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published