How igor-baiborodine/campsite-booking-go works
Project Type and Purpose
• This is a standalone Go‐based backend microservice that exposes a gRPC API for managing campsites and bookings.
• Clients call RPC methods (CreateCampsite, CreateBooking, UpdateBooking, CancelBooking, GetBooking, GetCampsites, GetVacantDates).
• Data is persisted in a PostgreSQL database.
• The project follows a layered (hexagonal/clean) architecture with clear separation of concerns (application, domain, infrastructure).
Key Directories and Their Roles
• cmd/main.go: application entry point—builds config, logger, DB connection, gRPC server and registers services.
• internal/config: holds configuration loading logic (env/flags).
• internal/logger: centralized logging setup.
• internal/grpc: gRPC server setup and interceptors (logging, validation).
• internal/application: core use‐case layer implementing commands (create/update/cancel) and queries (get bookings, get campsites, get vacant dates), plus validation and decorators.
• internal/domain: domain entities (Booking, Campsite), domain interfaces (repositories, validators) and business rules.
• internal/postgres: PostgreSQL adapters implementing domain repository interfaces; SQL queries and helpers.
• internal/service: composition roots—wiring repositories, validators, and application services.
• internal/waiter: utility to wait for dependencies (e.g. DB readiness).
• db: SQL migration scripts and DB initialization.
• datagenerator: stand‐alone tool to generate sample data.
• docker & k8s: containerization and orchestration manifests.
• tests: end‐to‐end/performance and concurrency tests.
Architectural Patterns
• Hexagonal/Clean Architecture:
• Inner circle – domain entities & interfaces.
• Application services – orchestrate commands and queries against domain.
• Adapters – gRPC transport and Postgres persistence.
• Dependency Injection: components wired in cmd/main or internal/service.
• gRPC Interceptors: for logging, error handling, validation.
• Migrations + test containers for integration testing.
Components
• External Clients (e.g. CLI, other microservices)
• gRPC API Layer
• Server & Interceptors
• Protobuf-generated stubs
• Application Layer
• Command Handlers
• Query Handlers
• Validators & Decorators
• Domain Layer
• Entities (Campsite, Booking)
• Interfaces (BookingRepository, CampsiteRepository, BookingValidator)
• Infrastructure Layer
• Postgres Adapter (SQL queries, connection)
• Configuration & Logger
• PostgreSQL Database
• Auxiliary Tools (DataGenerator)
• CI/CD & Deployment
• Docker images
• Kubernetes manifests
• Migrations
Relationships and Data Flows
• Client → gRPC API Layer: RPC call
• gRPC → Application Layer: calls command/query handler
• Application → Domain: applies business rules
• Domain → Infrastructure: calls repository interfaces
• Infrastructure → Postgres: executes SQL
• Responses flow back in reverse order
• Cross‐cutting: Config & Logger injected at startup; Interceptors apply to every RPC.