Introduction
The Reservations backend is built with Go, following clean architecture principles with a clear separation between domain models, business logic, and data access layers.Technology Stack
Go
Version 1.25.1 - Primary backend language
Chi Router
Lightweight HTTP router for building REST APIs
PostgreSQL
Primary database with pgx/v5 driver
JWT
Authentication using JSON Web Tokens
Architecture Overview
The backend follows a layered architecture pattern:Folder Structure
cmd/ - Application Bootstrap
cmd/ - Application Bootstrap
Contains the application entry point and configuration loading:
- main.go - Initializes the application, sets up database connection, and starts the HTTP server
- config/ - Environment variable loading and validation
internal/api/ - HTTP Layer
internal/api/ - HTTP Layer
Handles HTTP requests and routes:
- router.go - Defines all API routes and middleware
- handler/ - HTTP request handlers organized by domain
- middleware/ - Authentication, authorization, and request processing
internal/domain/ - Domain Layer
internal/domain/ - Domain Layer
Core business entities and repository interfaces:
- Domain models (Booking, Merchant, Customer, etc.)
- Repository interfaces defining data operations
- Pure business entities with no external dependencies
internal/service/ - Business Logic
internal/service/ - Business Logic
Service layer implementing business rules:
- booking/ - Booking creation, cancellation, and management
- merchant/ - Merchant operations and dashboard
- customer/ - Customer management and blacklisting
- catalog/ - Service and product catalog
- auth/ - Authentication and OAuth
internal/repository/ - Data Access
internal/repository/ - Data Access
Database implementations of repository interfaces:
- db/ - PostgreSQL implementations using pgx
- Transaction management
- SQL query execution
Key Dependencies
Application Bootstrap
The application initialization follows this flow:Load Configuration
Environment variables are loaded and validated from the
.env filebackend/cmd/main.go:23-24
Wire Dependencies
Repositories, services, and handlers are instantiated in the app package
backend/internal/app/app.go:47-68
Environment Configuration
The backend requires the following environment variables:Database Configuration
Database Configuration
JWT Configuration
JWT Configuration
OAuth Configuration
OAuth Configuration
Email Configuration
Email Configuration
Design Principles
Clean Architecture
Clear separation of concerns with domain, service, and repository layers
Dependency Injection
Services receive dependencies through constructors for testability
Repository Pattern
Data access abstracted behind interfaces defined in the domain layer
Transaction Management
Coordinated database operations using transaction manager
Next Steps
Domain Models
Explore core business entities
Services
Learn about business logic layer
Repositories
Understand data access patterns