# layheng-hok/shenzhen-metro architecture

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

- Interactive diagram: https://gitdiagram.com/layheng-hok/shenzhen-metro
- Repository: https://github.com/layheng-hok/shenzhen-metro

## Overview

##### Project Type and Purpose
- This project is a metro management system developed as part of a university database course. It has two clear components:
- Part 2 implements an API using Spring Boot with clearly defined controllers, DTOs, services, and repositories, along with a basic web interface to interact with the system.

##### Main Components
a. Data Import and Database Design Subsystem:
- Java-based Import Scripts (located in the ShenzhenMetroDatabaseDesign and the updated DataImport directories).
- Python-based Import Script for data import automation.
- Resources containing JSON data files and SQL DDLs (MySQL and PostgreSQL).
- Underlying Database(s): Illustrate both options (PostgreSQL and MySQL) even though the API deployment instructs MySQL.

b. API and Backend Service:
- The Spring Boot Application (Project2/ShenzhenMetro) that serves as the primary backend.
- Layers such as:
- Controller layer: REST endpoints (e.g., BusController, StationController, RideController).
- DTO layer: Data Transfer Objects that smooth data exchange between client and server.
- Service layer: Business logic implementations (e.g., RideService, LineDetailService).
- Repository layer: Data access interfaces (e.g., CardRepository, StationRepository).
- Integration with the previously designed and populated database.

c. Frontend / Static Views:
- Static assets (HTML, CSS, JavaScript) and templates that provide the user interface for administrative or user operations.
- Separation between static resources (web assets) and the backend API.

d. External Systems / Environment:
- The database system (MySQL is used for deployment, while experiments are also conducted on PostgreSQL).
- Deployment environments: note testing on different OSs (macOS, Windows, Linux VM) as reported in the experiments.
- Build and configuration tools such as Maven, IDEs like IDEA and PyCharm.

##### Relationships and Interactions
- How the Spring Boot Application’s controllers receive requests that flow through service logic, which in turn interacts with the database via repositories.
- Data flow from the database back to the frontend via the API calls.
- Modular separation: data import is a distinct process from the ongoing API services, although both ultimately target the same database.

##### Architectural Patterns and Technologies
- For the backend (Spring Boot application), include the common layered architecture (Controller, Service, Repository, DTO).
- Stress the use of ORM-like mapping in the “object” package that maps database tables into Java objects.
- Mention the usage of standard integration patterns such as PreparedStatement batching (for performance in data import) and RESTful API design in the Spring Boot project.
- Rectangles for components (e.g., Import Scripts, Application Server).

##### Final Checklist
- All major components must be clearly identified and labeled.
- That both parts of the project are represented while showing how they interact with the shared database.
- Keep details comprehensive but focused on architectural elements rather than low-level code details.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Data Import & Database Design Subsystem
    subgraph "Data Import & Database Design"
        A1["Java Import Scripts"]:::dataimport
        A2["Python Import Script"]:::dataimport
        A3["JSON Resources"]:::dataimport
        A4["SQL DDLs"]:::dataimport
        A5["Updated Import Scripts"]:::dataimport
        A6["ER Diagram"]:::dataimport
        DIP["Data Import Pipeline"]:::dataimport
        A1 -->|"reads"| DIP
        A2 -->|"reads"| DIP
        A3 -->|"supplies"| DIP
        A4 -->|"supplies"| DIP
        A5 -->|"executes"| DIP
        A6 -->|"guides"| DIP
    end

    %% Database Subsystem
    subgraph "Database"
        DB1("MySQL Database"):::database
        DB2("PostgreSQL Database"):::database
    end
    
    %% Connect Data Import Pipeline to Databases
    DIP -->|"imports to"| DB1
    DIP -->|"imports to"| DB2

    %% API & Web Application Subsystem
    subgraph "API & Web Application"
        B1["Spring Boot Application"]:::api
            %% Backend Layers
            subgraph "Backend Layers"
                C1["Controller Layer"]:::api
                C2["DTO Layer"]:::api
                C3["Service Layer"]:::api
                C4["Repository Layer"]:::api
                C5["Domain/ORM Mapping"]:::api
            end
            %% Frontend / Static Views
            subgraph "Frontend / Static Views"
                F1["Static Assets"]:::frontend
                F2["HTML Templates"]:::frontend
            end
    end

    %% API Internal Flow
    B1 -->|"routes to"| C1
    C1 -->|"calls"| C3
    C3 -->|"invokes"| C4
    C4 -->|"queries"| DB1
    DB1 -->|"returns"| C4
    C4 -->|"processes"| C3
    C3 -->|"responds"| C1
    C1 -->|"sends response"| B1

    %% Frontend and API Interaction
    F1 -->|"API request"| B1
    F2 -->|"API request"| B1
    B1 -->|"API response"| F1
    B1 -->|"API response"| F2

    %% Styles
    classDef dataimport fill:#ffdddd,stroke:#cc0000,stroke-width:2px;
    classDef api fill:#ddffdd,stroke:#008800,stroke-width:2px;
    classDef frontend fill:#ddddff,stroke:#0000cc,stroke-width:2px;
    classDef database fill:#fff0b3,stroke:#cc9900,stroke-width:2px;

    %% Click Events
    click A1 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project1/ShenzhenMetroDatabaseDesign/src/main/java"
    click A2 "https://github.com/layheng-hok/shenzhen-metro/blob/main/Project1/ShenzhenMetroDatabaseDesignPython/import_script.py"
    click A3 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project1/ShenzhenMetroDatabaseDesign/src/main/resources"
    click A4 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project1/ShenzhenMetroDatabaseDesign/src/main/sql"
    click A5 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project2/DataImport/src/main/java"
    click B1 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project2/ShenzhenMetro"
    click C1 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project2/ShenzhenMetro/src/main/java/com/sustech/cs307/project2/shenzhenmetro/controller"
    click C2 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project2/ShenzhenMetro/src/main/java/com/sustech/cs307/project2/shenzhenmetro/dto"
    click C3 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project2/ShenzhenMetro/src/main/java/com/sustech/cs307/project2/shenzhenmetro/service"
    click C4 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project2/ShenzhenMetro/src/main/java/com/sustech/cs307/project2/shenzhenmetro/repository"
    click C5 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project2/ShenzhenMetro/src/main/java/com/sustech/cs307/project2/shenzhenmetro/object"
    click F1 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project2/ShenzhenMetro/src/main/resources/static"
    click F2 "https://github.com/layheng-hok/shenzhen-metro/tree/main/Project2/ShenzhenMetro/src/main/resources/templates"
```
