# nguyenhoanghiep478/bookingtrainticket architecture

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

- Interactive diagram: https://gitdiagram.com/nguyenhoanghiep478/bookingtrainticket
- Repository: https://github.com/nguyenhoanghiep478/bookingtrainticket

## Overview

##### Main Components
- Config Service – A centralized configuration provider that all microservices check for runtime configuration (usually on port 8888).
- Discovery Service – A service registry (such as Eureka) that helps each microservice register its information and discover others (commonly on port 8761).
- Microservices:
- Auth Service: Handles user authentication and authorization.
- Store Service: Manages inventory, ticketing, and aspects of train scheduling.
- Order Service: Responsible for order creation, processing (buy/sell orders), and interacting with other services via service gateways.
- Payment Service: Handles payment processing with integration for multiple payment methods (e.g., COD or PayPal).
- Marketing Service: Manages promotional campaigns, email notifications (including templates like mailTemplate.html, preOrderTemplate.html, etc.), and communications.
- Gateway Service (if present): Acts as the API gateway to route external requests to the appropriate microservices.
- External Infrastructure:
- Database (PostgreSQL) for persistent data.
- Apache Kafka for asynchronous messaging among services.
- Redis for caching and fast data retrieval.
- Docker (Compose) for container orchestration of Kafka, Redis, and possibly other services.

##### Relationships & Interactions
- Config Service and Discovery Service as central to the architecture.
- Similarly, show registration of these services with the Discovery Service.
- Auth Service (for user identity/permission check).
- Store Service (to verify availability of tickets or inventory).
- Payment Service (to process payments).
- Marketing Service (for promotional notifications).
- If a Gateway is implemented, show it routing incoming requests to the appropriate microservices ensuring it is registered in the discovery mechanism.
- Integration with external systems like Swagger documentation endpoints (indicate that each service has its own API doc portal) and deployment pipelines using Docker.

##### Architectural Patterns & Design Principles
- Microservices Architecture – Separate, independently deployable services communicating over well-defined APIs.
- Service Discovery and Configuration Management – Centralized approaches using Config and Discovery Services.
- Fault Tolerance and Scalability – Although not explicitly depicted, consider annotating that each service container is isolated and can scale independently.
- Use of RESTful APIs (documented via Swagger) and potential API Gateway for security aggregation and routing.

##### Final Steps
- Keep the design detailed enough to capture all essential architectural guidelines but also clear enough to be easily understood by technical stakeholders.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure
    subgraph "Infrastructure"
        KAFKA["Apache Kafka"]:::infra
        REDIS["Redis Cache"]:::infra
        POSTGRES["PostgreSQL DB"]:::infra
        DOCKER["Docker Compose"]:::infra
    end

    %% Core Services
    subgraph "Core Services"
        CONFIG["Config Service (Port:8888)"]:::core
        DISCOVERY["Discovery Service (Port:8761)"]:::core
    end

    %% Microservices
    subgraph "Microservices"
        AUTH["Auth Service"]:::micro
        GATEWAY["Gateway Service"]:::micro
        ORDER["Order Service"]:::micro
        PAYMENT["Payment Service"]:::micro
        STORE["Store Service"]:::micro
        MARKETING["Marketing Service"]:::micro
    end

    %% Microservices dependent on Core Services
    AUTH -->|"cfg_disc"| CONFIG
    AUTH -->|"cfg_disc"| DISCOVERY

    STORE -->|"cfg_disc"| CONFIG
    STORE -->|"cfg_disc"| DISCOVERY

    ORDER -->|"cfg_disc"| CONFIG
    ORDER -->|"cfg_disc"| DISCOVERY

    PAYMENT -->|"cfg_disc"| CONFIG
    PAYMENT -->|"cfg_disc"| DISCOVERY

    MARKETING -->|"cfg_disc"| CONFIG
    MARKETING -->|"cfg_disc"| DISCOVERY

    GATEWAY -->|"cfg_disc"| CONFIG
    GATEWAY -->|"cfg_disc"| DISCOVERY

    %% API Gateway routing
    GATEWAY -->|"routes"| AUTH
    GATEWAY -->|"routes"| ORDER
    GATEWAY -->|"routes"| PAYMENT
    GATEWAY -->|"routes"| STORE
    GATEWAY -->|"routes"| MARKETING

    %% Order Service inter-service calls
    ORDER -->|"callsAuth"| AUTH
    ORDER -->|"callsStore"| STORE
    ORDER -->|"callsPayment"| PAYMENT
    ORDER -->|"callsMarketing"| MARKETING

    %% Asynchronous communication via Kafka (bidirectional)
    AUTH <-->|"pubsub"| KAFKA
    PAYMENT <-->|"pubsub"| KAFKA
    MARKETING <-->|"pubsub"| KAFKA
    ORDER <-->|"pubsub"| KAFKA

    %% Cache integration with Redis
    AUTH -->|"cache"| REDIS
    PAYMENT -->|"cache"| REDIS
    MARKETING -->|"cache"| REDIS

    %% Docker Compose orchestration
    DOCKER -->|"orchestrates"| KAFKA
    DOCKER -->|"orchestrates"| REDIS
    DOCKER -->|"orchestrates"| CONFIG
    DOCKER -->|"orchestrates"| DISCOVERY
    DOCKER -->|"orchestrates"| AUTH
    DOCKER -->|"orchestrates"| GATEWAY
    DOCKER -->|"orchestrates"| ORDER
    DOCKER -->|"orchestrates"| PAYMENT
    DOCKER -->|"orchestrates"| STORE
    DOCKER -->|"orchestrates"| MARKETING

    %% Styling Classes
    classDef infra fill:#CDEBFF,stroke:#036,stroke-width:2px;
    classDef core fill:#FFF1B8,stroke:#C58,stroke-width:2px;
    classDef micro fill:#C1FFC1,stroke:#383,stroke-width:2px;

    %% Click Events
    click CONFIG "https://github.com/nguyenhoanghiep478/bookingtrainticket/blob/main/Back-end/TrainTicketBooking/src/main/java/com/backend/trainticketbooking/services/config-server/ConfigServerApplication.java"
    click DISCOVERY "https://github.com/nguyenhoanghiep478/bookingtrainticket/blob/main/Back-end/TrainTicketBooking/src/main/java/com/backend/trainticketbooking/services/discovery/DiscoveryApplication.java"
    click AUTH "https://github.com/nguyenhoanghiep478/bookingtrainticket/tree/main/Back-end/TrainTicketBooking/src/main/java/com/backend/trainticketbooking/services/authentication/"
    click GATEWAY "https://github.com/nguyenhoanghiep478/bookingtrainticket/tree/main/Back-end/TrainTicketBooking/src/main/java/com/backend/trainticketbooking/services/gateway/"
    click MARKETING "https://github.com/nguyenhoanghiep478/bookingtrainticket/tree/main/Back-end/TrainTicketBooking/src/main/java/com/backend/trainticketbooking/services/marketing/"
    click ORDER "https://github.com/nguyenhoanghiep478/bookingtrainticket/tree/main/Back-end/TrainTicketBooking/src/main/java/com/backend/trainticketbooking/services/order/"
    click PAYMENT "https://github.com/nguyenhoanghiep478/bookingtrainticket/tree/main/Back-end/TrainTicketBooking/src/main/java/com/backend/trainticketbooking/services/payment/"
    click STORE "https://github.com/nguyenhoanghiep478/bookingtrainticket/tree/main/Back-end/TrainTicketBooking/src/main/java/com/backend/trainticketbooking/services/store/"
    click DOCKER "https://github.com/nguyenhoanghiep478/bookingtrainticket/blob/main/Back-end/TrainTicketBooking/docker-compose.yml"
```
