# piyushs3v3n/trafficsimulator-python architecture

> Architecture diagram of the GitHub repository piyushs3v3n/trafficsimulator-python, 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/piyushs3v3n/trafficsimulator-python
- Repository: https://github.com/piyushs3v3n/trafficsimulator-python

## Overview

##### Main Components
- Entry Point – main.py: This is the application’s starting point.
- Main Window – main_window.py: The primary window that initializes the UI.
- Path Window – path_window.py: Likely handles path-related features using osmnx.
- Simulation GL Widget – simulation_gl_widget.py: A specialized widget that handles OpenGL rendering for simulations.
- Simulation Thread – simulation_thread.py: A separate thread for running simulation processes, ensuring the UI remains responsive.

##### Relationships and Interactions
- The App Flow: The entry point (main.py) initializes the Main Window, which orchestrates all UI components.
- UI Components: The Main Window likely hosts or launches the Path Window and incorporates the Simulation GL Widget as part of its layout.
- Asynchronous Processing: The Simulation Thread is created by the UI (or simulation controller) to handle intensive simulation tasks in parallel, with clear signal/slot communication between the UI thread (main window) and the simulation thread.
- External Dependencies: PyQt5 acts as the core framework supporting the various window and widget components; PyOpenGL is used within the Simulation GL Widget for graphics rendering; osmnx might be leveraged in the Path Window to process map data or compute paths.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project cleanly separates the UI logic (main_window and path_window) from the simulation rendering and processing (simulation_gl_widget and simulation_thread).
- Event-Driven Programming: Using PyQt5’s signal-slot mechanism to coordinate between the UI and background processing, ensuring responsiveness.
- Multi-threading: The offloading of simulation tasks to a dedicated thread (simulation_thread) is a key design choice to prevent UI blocking.
- Modular Design: Each file/module in the src directory is focused on a specific component or functionality.

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Components
    main["main.py"]:::ui
    win["main_window.py"]:::ui
    simWidget["simulation_gl_widget.py"]:::ui
    path["path_window.py"]:::ui

    %% Background Processing
    simThread["simulation_thread.py"]:::simulation

    %% External Dependencies
    pyqt["PyQt5"]:::external
    pyOpenGL["PyOpenGL"]:::external
    osmnx["osmnx"]:::external

    %% Application Flow
    main -->|"initializes"| win
    win -->|"hosts"| simWidget
    win -->|"launches"| path
    simWidget -->|"signals_slots"| simThread

    %% External Dependencies Interactions
    pyqt -->|"framework"| win
    pyqt -->|"manages_threads"| simThread
    pyOpenGL -->|"renders_graphics"| simWidget
    osmnx -->|"processes_maps"| path

    %% Click Events
    click main "https://github.com/piyushs3v3n/trafficsimulator-python/blob/main/src/main.py"
    click win "https://github.com/piyushs3v3n/trafficsimulator-python/blob/main/src/main_window.py"
    click simWidget "https://github.com/piyushs3v3n/trafficsimulator-python/blob/main/src/simulation_gl_widget.py"
    click path "https://github.com/piyushs3v3n/trafficsimulator-python/blob/main/src/path_window.py"
    click simThread "https://github.com/piyushs3v3n/trafficsimulator-python/blob/main/src/simulation_thread.py"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef simulation fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
