# fudanselab/train-ticket architecture

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

- Interactive diagram: https://gitdiagram.com/fudanselab/train-ticket
- Repository: https://github.com/fudanselab/train-ticket

## Overview

##### System’s Main Components
- External Client/User Interface – illustrate the Train Ticket web front end (as seen in “ts-ui-dashboard”) and any web/browser clients.
- API Gateway – represent “ts-gateway-service” as the entry point that receives incoming requests and forwards them to the appropriate microservices.
- Supporting Services – include core infrastructure services such as the configuration service (“ts-config-service”), a common service (“ts-common”), and possibly a security service (“ts-security-service”).
- Observability Components – if monitoring and tracing are enabled at deployment (“--with-monitoring” and “--with-tracing”), include external service components like Prometheus, Grafana, and distributed tracing systems (Jaeger/Zipkin) which help monitor and diagnose the system.
- Deployment and Infrastructure – show the overall orchestration platform using Kubernetes (with the provided manifests) and Docker-based images. Optionally indicate elements like secrets management or load balancing.

##### Relationships and Data Flows
- How services interact with their databases (for example, each service’s connection to MySQL/MongoDB).

##### Important Architectural Patterns/Design Principles
- Microservices Architecture – each service is independently deployable, developed in multiple programming languages (Java, Node.js, Python, Go) leveraging frameworks such as Spring Boot, Spring Cloud, Express, Django, and Webgo.
- Containerization and Orchestration – emphasize that each microservice is containerized (using Dockerfiles) and deployed in Kubernetes clusters.
- Independent Databases – the system supports independent databases for each service (as seen with the “--independent-db” flag) to minimize coupling through shared data.
- Asynchronous Communication and API Composition – where applicable, show both synchronous REST endpoints and asynchronous messaging (via RabbitMQ or similar) as inter-service communication methods.
- Scalability and Observability – include services or layers dedicated to monitoring, tracing, and logging.

##### Incorporate Relevant Technologies, Frameworks, and Libraries
- Java (Spring Boot, Spring Cloud) for many of the services.
- Node.js (Express) and Python (Django) – represented in some services.
- Go (Webgo) – for a select few services.
- Docker and Kubernetes – for containerization and deployment.
- Databases: MySQL and MongoDB.
- Monitoring/Tracing frameworks – Prometheus, Grafana, Jaeger/Zipkin (as referenced in deployment manifests).
- Message queues/RabbitMQ (as indicated in “ts-delivery-service”, “ts-food-service”, “ts-notification-service”, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Client Layer
    subgraph "Client Layer"
        CLIENT["Train Ticket UI Dashboard (ts-ui-dashboard)"]:::client
    end

    %% API Gateway Layer
    subgraph "API Gateway"
        GATEWAY["API Gateway Service (ts-gateway-service)"]:::gateway
    end

    CLIENT -->|"HTTP"| GATEWAY

    %% Business Microservices Layer
    subgraph "Business Microservices"
        %% Admin Services Cluster
        subgraph "Admin Services"
            ADMIN_BASIC["Basic Info (ts-admin-basic-info-service)"]:::admin
            ADMIN_ORDER["Order (ts-admin-order-service)"]:::admin
            ADMIN_ROUTE["Route (ts-admin-route-service)"]:::admin
            ADMIN_TRAVEL["Travel (ts-admin-travel-service)"]:::admin
            ADMIN_USER["User (ts-admin-user-service)"]:::admin
        end

        %% Passenger/User Management Cluster
        subgraph "Passenger/User Management"
            AUTH["Authentication (ts-auth-service)"]:::passenger
            USER_PROFILE["User Profile (ts-user-service)"]:::passenger
        end

        %% Order and Payment Services Cluster
        subgraph "Order and Payment Services"
            ORDER_PROC["Order Processing (ts-order-service)"]:::order
            PAYMENT_PROC["Payment Processing (ts-payment-service)"]:::order
            INSIDE_PAYMENT["Inside Payment (ts-inside-payment-service)"]:::order
            WAIT_ORDER["Wait Order (ts-wait-order-service)"]:::order
            OTHER_ORDER["Other Order Service (ts-order-other-service)"]:::order
        end

        %% Travel/Station/Train Services Cluster
        subgraph "Travel/Station/Train Services"
            TRAVEL_INFO["Travel Information (ts-travel-service)"]:::travel
            TRAIN_OP["Train Operations (ts-train-service)"]:::travel
            STATION_MGMT["Station Management (ts-station-service)"]:::travel
            ROUTE_MGMT["Route Management (ts-route-service)"]:::travel
            SEAT_MGMT["Seat Management (ts-seat-service)"]:::travel
            TRAVEL_PLAN["Travel Plan (ts-travel-plan-service)"]:::travel
            TRAVEL2["Secondary Travel Service (ts-travel2-service)"]:::travel
        end

        %% Food, Delivery, and Voucher Services Cluster
        subgraph "Food, Delivery, and Voucher Services"
            FOOD_DELIVERY["Food Delivery (ts-food-delivery-service)"]:::food
            FOOD_SEARCH["Food Service (ts-food-service)"]:::food
            TRAIN_FOOD["Train Food (ts-train-food-service)"]:::food
            VOUCHER_MGMT["Voucher Management (ts-voucher-service)"]:::food
        end

        %% Notification Service
        NOTIFICATION["Notification Service (ts-notification-service)"]:::notification
    end

    %% Connections from API Gateway to Microservices
    GATEWAY -->|"routes"| ADMIN_BASIC
    GATEWAY -->|"routes"| ADMIN_ORDER
    GATEWAY -->|"routes"| ADMIN_ROUTE
    GATEWAY -->|"routes"| ADMIN_TRAVEL
    GATEWAY -->|"routes"| ADMIN_USER

    GATEWAY -->|"routes"| AUTH
    GATEWAY -->|"routes"| USER_PROFILE

    GATEWAY -->|"routes"| ORDER_PROC
    GATEWAY -->|"routes"| PAYMENT_PROC
    GATEWAY -->|"routes"| INSIDE_PAYMENT
    GATEWAY -->|"routes"| WAIT_ORDER
    GATEWAY -->|"routes"| OTHER_ORDER

    GATEWAY -->|"routes"| TRAVEL_INFO
    GATEWAY -->|"routes"| TRAIN_OP
    GATEWAY -->|"routes"| STATION_MGMT
    GATEWAY -->|"routes"| ROUTE_MGMT
    GATEWAY -->|"routes"| SEAT_MGMT
    GATEWAY -->|"routes"| TRAVEL_PLAN
    GATEWAY -->|"routes"| TRAVEL2

    GATEWAY -->|"routes"| FOOD_DELIVERY
    GATEWAY -->|"routes"| FOOD_SEARCH
    GATEWAY -->|"routes"| TRAIN_FOOD
    GATEWAY -->|"routes"| VOUCHER_MGMT

    GATEWAY -->|"routes"| NOTIFICATION

    %% Supporting Services Layer
    subgraph "Supporting Services"
        CONFIG["Configuration Service (ts-config-service)"]:::support
        COMMON["Common Utilities (ts-common)"]:::support
        SECURITY["Security Service (ts-security-service)"]:::support
    end

    %% Infrastructure Services Layer
    subgraph "Infrastructure Services"
        MYSQL[(MySQL Database)]:::infra
        MONGODB[(MongoDB Database)]:::infra
        MESSAGING["RabbitMQ Messaging"]:::infra
        OBSERVABILITY["Observability (Jaeger, Prometheus/Grafana)"]:::infra
        DEPLOYMENT["Docker & Kubernetes"]:::infra
    end

    %% Database Connections from Microservices (representative independent DB links)
    ADMIN_BASIC ---|"DB"| MYSQL
    ADMIN_ORDER ---|"DB"| MYSQL
    ADMIN_ROUTE ---|"DB"| MYSQL
    ADMIN_TRAVEL ---|"DB"| MYSQL
    ADMIN_USER ---|"DB"| MYSQL

    AUTH ---|"DB"| MONGODB
    USER_PROFILE ---|"DB"| MONGODB

    ORDER_PROC ---|"DB"| MYSQL
    PAYMENT_PROC ---|"DB"| MYSQL
    INSIDE_PAYMENT ---|"DB"| MYSQL
    WAIT_ORDER ---|"DB"| MYSQL
    OTHER_ORDER ---|"DB"| MYSQL

    TRAVEL_INFO ---|"DB"| MONGODB
    TRAIN_OP ---|"DB"| MYSQL
    STATION_MGMT ---|"DB"| MYSQL
    ROUTE_MGMT ---|"DB"| MYSQL
    SEAT_MGMT ---|"DB"| MYSQL
    TRAVEL_PLAN ---|"DB"| MYSQL
    TRAVEL2 ---|"DB"| MONGODB

    FOOD_DELIVERY ---|"DB"| MYSQL
    FOOD_SEARCH ---|"DB"| MYSQL
    TRAIN_FOOD ---|"DB"| MYSQL
    VOUCHER_MGMT ---|"DB"| MYSQL

    NOTIFICATION ---|"DB"| MYSQL

    %% Asynchronous Messaging (dashed arrows)
    FOOD_SEARCH -.->|"async"| MESSAGING
    NOTIFICATION -.->|"async"| MESSAGING

    %% Observability and Monitoring Connections
    ADMIN_BASIC -.-> OBSERVABILITY
    AUTH -.-> OBSERVABILITY
    ORDER_PROC -.-> OBSERVABILITY
    TRAVEL_INFO -.-> OBSERVABILITY
    FOOD_DELIVERY -.-> OBSERVABILITY

    %% Supporting Services providing configuration and security
    CONFIG ---|"config"| GATEWAY
    CONFIG ---|"config"| ADMIN_BASIC
    CONFIG ---|"config"| AUTH
    SECURITY ---|"security"| GATEWAY

    %% Deployment and Containerization links
    DEPLOYMENT ---|"orchestration"| GATEWAY
    DEPLOYMENT ---|"orchestration"| ADMIN_BASIC
    DEPLOYMENT ---|"orchestration"| AUTH

    OBSERVABILITY ---|"monitor"| DEPLOYMENT

    %% Click Events
    click CLIENT "https://github.com/fudanselab/train-ticket/tree/master/ts-ui-dashboard"
    click GATEWAY "https://github.com/fudanselab/train-ticket/tree/master/ts-gateway-service"
    click ADMIN_BASIC "https://github.com/fudanselab/train-ticket/tree/master/ts-admin-basic-info-service"
    click ADMIN_ORDER "https://github.com/fudanselab/train-ticket/tree/master/ts-admin-order-service"
    click ADMIN_ROUTE "https://github.com/fudanselab/train-ticket/tree/master/ts-admin-route-service"
    click ADMIN_TRAVEL "https://github.com/fudanselab/train-ticket/tree/master/ts-admin-travel-service"
    click ADMIN_USER "https://github.com/fudanselab/train-ticket/tree/master/ts-admin-user-service"
    click AUTH "https://github.com/fudanselab/train-ticket/tree/master/ts-auth-service"
    click USER_PROFILE "https://github.com/fudanselab/train-ticket/tree/master/ts-user-service"
    click ORDER_PROC "https://github.com/fudanselab/train-ticket/tree/master/ts-order-service"
    click PAYMENT_PROC "https://github.com/fudanselab/train-ticket/tree/master/ts-payment-service"
    click INSIDE_PAYMENT "https://github.com/fudanselab/train-ticket/tree/master/ts-inside-payment-service"
    click WAIT_ORDER "https://github.com/fudanselab/train-ticket/tree/master/ts-wait-order-service"
    click OTHER_ORDER "https://github.com/fudanselab/train-ticket/tree/master/ts-order-other-service"
    click TRAVEL_INFO "https://github.com/fudanselab/train-ticket/tree/master/ts-travel-service"
    click TRAIN_OP "https://github.com/fudanselab/train-ticket/tree/master/ts-train-service"
    click STATION_MGMT "https://github.com/fudanselab/train-ticket/tree/master/ts-station-service"
    click ROUTE_MGMT "https://github.com/fudanselab/train-ticket/tree/master/ts-route-service"
    click SEAT_MGMT "https://github.com/fudanselab/train-ticket/tree/master/ts-seat-service"
    click TRAVEL_PLAN "https://github.com/fudanselab/train-ticket/tree/master/ts-travel-plan-service"
    click TRAVEL2 "https://github.com/fudanselab/train-ticket/tree/master/ts-travel2-service"
    click FOOD_DELIVERY "https://github.com/fudanselab/train-ticket/tree/master/ts-food-delivery-service"
    click FOOD_SEARCH "https://github.com/fudanselab/train-ticket/tree/master/ts-food-service"
    click TRAIN_FOOD "https://github.com/fudanselab/train-ticket/tree/master/ts-train-food-service"
    click VOUCHER_MGMT "https://github.com/fudanselab/train-ticket/tree/master/ts-voucher-service"
    click NOTIFICATION "https://github.com/fudanselab/train-ticket/tree/master/ts-notification-service"
    click CONFIG "https://github.com/fudanselab/train-ticket/tree/master/ts-config-service"
    click COMMON "https://github.com/fudanselab/train-ticket/tree/master/ts-common"
    click SECURITY "https://github.com/fudanselab/train-ticket/tree/master/ts-security-service"
    click MESSAGING "https://github.com/fudanselab/train-ticket/tree/master/deployment/kubernetes-manifests/quickstart-k8s/charts/rabbitmq"
    click OBSERVABILITY "https://github.com/fudanselab/train-ticket/blob/master/deployment/docker-compose-manifests/docker-compose-with-jaeger.yml"
    click DEPLOYMENT "https://github.com/fudanselab/train-ticket/tree/master/deployment/kubernetes-manifests"

    %% Styles
    classDef client fill:#B3E5FC,stroke:#039BE5,stroke-width:2px;
    classDef gateway fill:#FFF176,stroke:#FBC02D,stroke-width:2px;
    classDef admin fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef passenger fill:#F8BBD0,stroke:#C2185B,stroke-width:2px;
    classDef order fill:#FFCCBC,stroke:#E64A19,stroke-width:2px;
    classDef travel fill:#D1C4E9,stroke:#7B1FA2,stroke-width:2px;
    classDef food fill:#DCEDC8,stroke:#558B2F,stroke-width:2px;
    classDef notification fill:#F0F4C3,stroke:#9E9D24,stroke-width:2px;
    classDef support fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
    classDef infra fill:#FFECB3,stroke:#FFA000,stroke-width:2px;
```
