# monlai-dev/go_hello_world architecture

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

- Interactive diagram: https://gitdiagram.com/monlai-dev/go_hello_world
- Repository: https://github.com/monlai-dev/go_hello_world

## Overview

##### Project Type and Purpose
- The project is a full-stack application for cinema ticket booking.
- It handles user authentication, movie and theater management, seat booking (with real-time updates via Socket.IO), payment processing (via PayOS/VNPay), and email notifications using RabbitMQ.
- Features such as Redis caching, Docker containerization, and role-based access control indicate both performance and security are important considerations.

##### Key Components
a. API / Backend Layer:
- Command-line entry point (cmd/app/main.go) indicating the starting point.
- API Layer: Controllers under internal/api/controllers handle endpoints (e.g., account_controller, movie_controller, booking_controller, etc.).
- Middleware and Routing: internal/api/middleware and internal/api/routes manage authentication, logging, error handling, etc.

b. Business Logic Layer (Services):
- Domain logic implemented in internal/services for handling user accounts, bookings, movies, theaters, seats, and payment processes.
- This layer encapsulates business rules (e.g., 10-minute booking hold, real-time updates, payment verification).

c. Data Access Layer (Repositories):
- The repositories in internal/repositories, with each domain (account, movie, booking, etc.) having repository and its implementation, facilitating separation of concerns.

d. Infrastructure/Integration Layer:
- Database: Components found under internal/infrastructure/database suggest integration with PostgreSQL.
- Caching: Redis components are available via internal/infrastructure/cache.
- Messaging / Queueing: RabbitMQ integration appears under internal/infrastructure/rabbitMq for email notification handling (and possibly additional asynchronous tasks).
- External Services: Payment Gateway communication via components in the payment_gateway directory.
- Elastic search and Firebase integrations are also listed under internal/infrastructure, implying some search functionality or notification services might be present.

e. Additional Utilities:
- Utility functions for tasks like hashing passwords and JWT creation (pkg/utils).
- Testing components in unit_test and swagger documentation files provided in cmd/app/docs, which can also be noted.

##### Defining the Relationships and Flow
- At the top, represent the entry point (cmd/app/main.go) which initializes the backend server, routing, and dependency injection (as indicated by wire_gen.go).
- The controllers then call the respective service implementations in the services layer.
- Services call repository methods to perform CRUD operations on the database.
- For payment and external integrations, show how the services interact directly with payment gateway code and the messaging queue (RabbitMQ) for email notifications.
- Additionally, include caching (Redis) to show that high-frequency data is stored and retrieved to enhance performance.

##### Highlighting Architectural Patterns and Technologies
- MVC-like approach with clear separation between controllers (presenting the API), services (business logic), and repositories (data access).
- The use of RabbitMQ and caching systems underscores asynchronous processing and optimization patterns.
- Containerization is supported through the Dockerfile and docker-compose.yml.
- Pay attention to dependency injection as indicated by files like wire_gen.go.
- Real-time updates facilitated by Socket.IO mechanisms should be visually linked with the booking components.
- Usage of JWT for authentication and Bcrypt for secure password hashing.
- That configuration related aspects (database connections, caching, third-party credentials) likely reside in the config directory.

## Diagram (Mermaid)

```mermaid
graph TD
    %% API Layer
    subgraph "API Layer"
        A["App Entry (main.go)"]:::api
        B["Middleware"]:::api
        C["Routes"]:::api
        D["Controllers"]:::api
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        E["Services"]:::services
        F["Real-time Service (Socket.IO)"]:::services
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        G["Repositories"]:::repo
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        H["Database (PostgreSQL)"]:::infra
        I["Cache (Redis)"]:::infra
        J["Messaging (RabbitMQ)"]:::infra
        K["Payment Gateway"]:::infra
        L["ElasticSearch"]:::infra
        M["Firebase"]:::infra
    end

    %% Utilities & Others
    subgraph "Utilities & Others"
        N["Utilities (JWT, hashing)"]:::utils
        O["Documentation (Swagger)"]:::utils
        P["Unit Tests"]:::utils
    end

    %% Connections - Vertical Flow
    A --> B
    B --> C
    C --> D
    D --> E
    E --> G
    G --> H
    E --> I
    E --> J
    E --> K
    E --> F
    E --> L
    E --> M
    %% Dashed dependencies on utilities
    D -.-> N
    E -.-> N

    %% Click Events
    click A "https://github.com/monlai-dev/go_hello_world/blob/master/cmd/app/main.go"
    click B "https://github.com/monlai-dev/go_hello_world/tree/master/internal/api/middleware"
    click C "https://github.com/monlai-dev/go_hello_world/blob/master/internal/api/routes/routes.go"
    click D "https://github.com/monlai-dev/go_hello_world/tree/master/internal/api/controllers"
    click E "https://github.com/monlai-dev/go_hello_world/tree/master/internal/services"
    click F "https://github.com/monlai-dev/go_hello_world/blob/master/internal/services/websocket_service.go"
    click G "https://github.com/monlai-dev/go_hello_world/tree/master/internal/repositories"
    click H "https://github.com/monlai-dev/go_hello_world/blob/master/internal/infrastructure/database/db_context.go"
    click I "https://github.com/monlai-dev/go_hello_world/blob/master/internal/infrastructure/cache/redis_context.go"
    click J "https://github.com/monlai-dev/go_hello_world/blob/master/internal/infrastructure/rabbitMq/rabbitmq.go"
    click K "https://github.com/monlai-dev/go_hello_world/tree/master/payment_gateway"
    click L "https://github.com/monlai-dev/go_hello_world/blob/master/internal/infrastructure/elastic_search/elastic_search.go"
    click M "https://github.com/monlai-dev/go_hello_world/blob/master/internal/infrastructure/firebase/firebase_context.go"
    click N "https://github.com/monlai-dev/go_hello_world/tree/master/pkg/utils"
    click O "https://github.com/monlai-dev/go_hello_world/tree/master/cmd/app/docs"
    click P "https://github.com/monlai-dev/go_hello_world/tree/master/unit_test"

    %% Styles
    classDef api fill:#f9e6ff,stroke:#800080,stroke-width:2px;
    classDef services fill:#e6f7ff,stroke:#005580,stroke-width:2px;
    classDef repo fill:#e6ffe6,stroke:#008000,stroke-width:2px;
    classDef infra fill:#fff0e6,stroke:#cc6600,stroke-width:2px;
    classDef utils fill:#e6fce6,stroke:#006600,stroke-width:2px;
```
