# duyanh-y4n/mdesign-leitsystem-server architecture

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

- Interactive diagram: https://gitdiagram.com/duyanh-y4n/mdesign-leitsystem-server
- Repository: https://github.com/duyanh-y4n/mdesign-leitsystem-server

## Overview

##### Main Components
a. Frontend/User Interface Module:
- Directory: src/main/java/UserInterface (and its PrototypGUI subpackage)
- Role: Provides a graphical interface with components like crossroad visualization, logs, and vehicle data display.

b. Communication Server:
- Directory: src/main/java/CommunicationServer
- Role: Contains components for managing requests, messages, and UDP communication. Components like CommunicationCenter, InfoServer, LeitsystemRequestHandler, MessageListener, and MessageUnicastSender process and route incoming messages.

c. Traffic System Logic:
- Directory: src/main/java/TrafficSystemLogic
- Role: Encapsulates the core simulation/modeling rules (e.g., areas, crossroads, and traffic system state management) that define the system’s behavior.

d. Data Server:
- Directory: src/main/java/DataServer
- Role: Provides database access functions via DAO objects (e.g., BaseDAO, LeitsystemSimpleVehicleDatabaseDAO, VehicleDatabaseDAO) for persisting or retrieving vehicle and system data.

e. Client Component:
- Directory: src/main/java/Client
- Role: Likely used for representing a remote client or simulation unit (including types defined by enums and helper classes) that interacts with the server system.

f. External Library – JAVA_UDP_Server:
- Directory: lib/Java_UDP_Server
- Role: Manages low-level UDP communications. This dependency is essential to the system’s network interactions.

##### Relationships and Interactions
- The communication server acts as an intermediary between incoming UDP messages (possibly received via the external library) and the internal processing modules.
- Incoming requests (from Clients or external traffic signals) are processed by the LeitsystemRequestHandler, with messages flowing through the CommunicationCenter.
- The processed messages then interact with the Traffic System Logic that updates the simulation state (e.g., changing the status of crossroads, managing vehicle flows, etc.).
- When data persistence or retrieval is required, the Traffic System Logic communicates with the Data Server (DAO layer) to store or extract information.
- The User Interface (GUI) uses output from the Traffic System Logic and Data Server to display real-time information such as vehicle statuses and intersection data.
- The Client component may be used to simulate or represent external entities that also communicate with the server, sending requests using the Java_UDP_Server mechanisms.

##### Important Architectural Patterns
- Separation of Concerns: Each package (e.g., CommunicationServer, TrafficSystemLogic, DataServer, UserInterface) is responsible for a distinct area of functionality.
- Layered Architecture: The system is naturally layered – with communication and presentation at the top, business logic in the middle, and data access at the bottom.
- Use of External Libraries: The system integrates a third-party UDP server library to handle network communications.

##### Relevant Technologies and Frameworks
- Java (core language and JVM)
- Maven (indicated by the pom.xml for build management and dependency resolution)
- Java_UDP_Server (for UDP-based communication)
- Swing or similar (suggested by the presence of GUI components in the UserInterface package)

##### Detail and Clarity
- Keep the design modular, ensuring that every component’s role is clearly visible, and interdependencies are not oversimplified.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "External Entities"
        Client("Client"):::client
        UDP("JAVA UDP Server"):::external
    end

    subgraph "Application Layers"
        subgraph "Communication Layer"
            CommS("Communication Server"):::processing
        end
        subgraph "Business Layer"
            Traffic("Traffic System Logic"):::processing
        end
        subgraph "Data Access Layer"
            Data("Data Server (DAO)"):::data
        end
        subgraph "Presentation Layer"
            UI("User Interface (GUI)"):::frontend
        end
    end

    Client -->|"sendUDPMessage"| CommS
    CommS -->|"UDPCommunication"| UDP
    CommS -->|"processMessage"| Traffic
    Traffic -->|"dataAccess"| Data
    Traffic -->|"updateGUI"| UI

    click Client "https://github.com/duyanh-y4n/mdesign-leitsystem-server/tree/master/src/main/java/Client"
    click UDP "https://github.com/duyanh-y4n/mdesign-leitsystem-server/tree/master/lib/Java_UDP_Server"
    click CommS "https://github.com/duyanh-y4n/mdesign-leitsystem-server/tree/master/src/main/java/CommunicationServer"
    click Traffic "https://github.com/duyanh-y4n/mdesign-leitsystem-server/tree/master/src/main/java/TrafficSystemLogic"
    click Data "https://github.com/duyanh-y4n/mdesign-leitsystem-server/tree/master/src/main/java/DataServer"
    click UI "https://github.com/duyanh-y4n/mdesign-leitsystem-server/tree/master/src/main/java/UserInterface"

    classDef processing fill:#85C1E9,stroke:#1F618D,stroke-width:2px;
    classDef data fill:#82E0AA,stroke:#27AE60,stroke-width:2px;
    classDef external fill:#F5B041,stroke:#D35400,stroke-width:2px;
    classDef client fill:#BDC3C7,stroke:#7F8C8D,stroke-width:2px;
    classDef frontend fill:#AED6F1,stroke:#5DADE2,stroke-width:2px;
```
