# hnam161098/booking architecture

> Architecture diagram of the GitHub repository hnam161098/booking, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hnam161098/booking
- Repository: https://github.com/hnam161098/booking

## Overview

##### Project Type and Purpose
- This is a microservices-based full-stack Golang application.
- It consists of two independent services (customer and booking), each with its own client and server.
- Communication uses gRPC for service calls; Gin is used in the client for routing; MongoDB and Elasticsearch back the data layer.

##### File-Structure Analysis
- Top-level directories:
- server – two independent services: server/customer and server/booking
- client – corresponding clients: client/customer and client/booking
- database_connection – MongoDB and Elasticsearch connectors
- config – global configuration loader
- helpers – shared utility functions (errors, types, ES helper)
- protoc + pb – .proto definitions and generated Go interfaces
- Naming convention follows “service-centric” grouping (controller, handler, models, testing).
- Each service has its own main.go, tests, mocks, and model definitions.

##### README Insights
- Confirms microservice design: independent customer and booking services that do not block each other on failure.
- Tech stack: Go, MongoDB, Elasticsearch, gRPC, Gin.
- Code-generation step using protoc for .proto → pb Go files.

##### Main Components
a. Clients:
- Booking Client (Gin router → gRPC stubs)
- Customer Client (Gin router → gRPC stubs)
b. Servers (microservices):
- Booking Service (gRPC server, handlers, controllers, DB managers)
- Customer Service (gRPC server, handlers, controllers, DB managers)
c. Databases:
- MongoDB instance
- Elasticsearch cluster
d. Shared Libraries/Utilities:
- config service loader
- database_connection layer
- helpers package
e. Code-gen pipeline: protoc → pb interfaces
f. External Tools: grpcui for runtime testing

##### Interactions & Data Flows
- Client → gRPC stub call → corresponding server endpoint
- Server handler → controller → dbmanager → database_connection (MongoDB or ES) → return to client
- Optional service-to-service calls (e.g., Booking Service querying Customer Service) via gRPC
- Config and Helpers are loaded at startup by both clients and servers

##### Architectural Patterns & Principles
- Microservices: two separately deployable processes
- Layered architecture within each service: Handler → Controller → Model/DB manager
- API contract via Protocol Buffers (strongly typed, cross-service)
- Dependency injection through config and database_connection modules
- Resilience: isolation ensures one service crash does not affect the other

##### Detailed Components to Capture
- client/customer/app & client/booking/app: Gin router & route definitions
- pb interfaces: booking.pb.go, customer.pb.go
- server/.../handler: business logic entry points
- server/.../controller: mapping between requests and models
- database_connection: elasticsearch.go, mongodb.go
- helpers: error handling and shared types
- protoc folder: .proto definitions driving contract

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Customer Side"
    direction TB
    CCapp["Customer Client (Gin Router)"]:::client
    CCstub["gRPC Stub"]:::client
    CServer["Customer gRPC Server"]:::server
    CHandler["Handler"]:::server
    CController["Controller"]:::server
    CDBMgr["DB Manager"]:::server
    CDB["MongoDB/Elasticsearch"]:::db

    CCapp -->|"HTTP JSON"| CCstub
    CCstub -->|"gRPC Call"| CServer
    CServer --> CHandler
    CHandler --> CController
    CController --> CDBMgr
    CDBMgr -->|"Mongo Query/ES Search"| CDB
  end

  subgraph "Booking Side"
    direction TB
    BCapp["Booking Client (Gin Router)"]:::client
    BCstub["gRPC Stub"]:::client
    BServer["Booking gRPC Server"]:::server
    BHandler["Handler"]:::server
    BController["Controller"]:::server
    BDBMgr["DB Manager"]:::server
    BDB["MongoDB/Elasticsearch"]:::db

    BCapp -->|"HTTP JSON"| BCstub
    BCstub -->|"gRPC Call"| BServer
    BServer --> BHandler
    BHandler --> BController
    BController --> BDBMgr
    BDBMgr -->|"Mongo Query/ES Search"| BDB
  end

  subgraph "Shared Utilities"
    direction TB
    Config["Config Loader"]:::util
    MongoConn["MongoDB Connector"]:::util
    ESConn["Elasticsearch Connector"]:::util
    Helpers["Shared Helpers"]:::util

    Config --> CCapp
    Config --> BCapp
    Config --> CServer
    Config --> BServer
    MongoConn --> CDBMgr
    ESConn --> BDBMgr
    Helpers --> CHandler
    Helpers --> BHandler
  end

  subgraph "Code Generation"
    direction TB
    Proto[".proto Definitions"]:::codegen
    PB["Generated pb Interfaces"]:::codegen

    Proto -.-> PB
    PB --> CCstub
    PB --> BCstub
    PB --> CServer
    PB --> BServer
  end

  click CCapp "https://github.com/hnam161098/booking/blob/master/client/customer/main.go"
  click BCapp "https://github.com/hnam161098/booking/blob/master/client/booking/main.go"
  click CServer "https://github.com/hnam161098/booking/blob/master/server/customer/main.go"
  click CHandler "https://github.com/hnam161098/booking/blob/master/server/customer/handler/customer.go"
  click CController "https://github.com/hnam161098/booking/tree/master/server/customer/controller"
  click CDBMgr "https://github.com/hnam161098/booking/blob/master/server/customer/handler/dbmanager.go"
  click BServer "https://github.com/hnam161098/booking/blob/master/server/booking/main.go"
  click BHandler "https://github.com/hnam161098/booking/blob/master/server/booking/handler/booking.go"
  click BController "https://github.com/hnam161098/booking/tree/master/server/booking/controller"
  click BDBMgr "https://github.com/hnam161098/booking/blob/master/server/booking/handler/dbmanager.go"
  click MongoConn "https://github.com/hnam161098/booking/blob/master/database_connection/mongodb.go"
  click ESConn "https://github.com/hnam161098/booking/blob/master/database_connection/elasticsearch.go"
  click Config "https://github.com/hnam161098/booking/blob/master/config/config.go"
  click Helpers "https://github.com/hnam161098/booking/tree/master/helpers"
  click PB "https://github.com/hnam161098/booking/tree/master/pb"
  click Proto "https://github.com/hnam161098/booking/tree/master/protoc"

  classDef client fill:#D0E8FF,stroke:#1E70BF,color:#1E70BF
  classDef server fill:#DFF7D7,stroke:#3E8E41,color:#3E8E41
  classDef db fill:#FFE5B4,stroke:#E69A00,color:#E69A00
  classDef util fill:#F0F0F0,stroke:#A0A0A0,color:#707070
  classDef codegen fill:#FFF4C1,stroke:#CCAA00,color:#CCAA00
```
