# anhquannguyen1/ttnt architecture

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

- Interactive diagram: https://gitdiagram.com/anhquannguyen1/ttnt
- Repository: https://github.com/anhquannguyen1/ttnt

## Overview

##### Project type and purpose
- Pathfinder is a domain-specific navigational tool (not a full-stack web app or microservice mesh)
- Purpose: compute and display the shortest path on a local map of the Tran Hung Dao area in Hanoi
- Key features: A*-based pathfinding, multiple traffic/flood constraint modes, interactive map interface

##### File structure
- Top level
– README.md (overview, usage)
– data/ (all static map data and generated HTML)
– src/ (all Python modules)
- data/ contains:
– map.osm, graphml/xml files, border.txt, blocked_edges.txt (map inputs)
– map2.html, map2_flood.html, map2_traffic.html (frontend views)
– out4.txt (intermediate or logging output)
- src/ contains:
– backend.py (entry point, likely runs a simple server or CLI orchestrator)
– getInput.py, extract.py, preprocessingMap.py, getBorder.py (data-prep pipeline)
– astar.py, astar_flood.py, astar_traffic.py (pathfinding algorithms)
– test.py (unit/integration tests)

##### README for additional insights
- Then open data/map2.html in a browser
- Implies: the Python backend processes map data and writes/serves an interactive HTML frontend

##### Main components & interactions
a. Components
1. User (Browser / Map UI)
2. Frontend View (data/map2.html + embedded JavaScript)
3. Backend Service (src/backend.py)
- Data-prep pipeline
- Pathfinding engine
- Visualization module
4. Data Layer (data/*.osm, *.txt, *.graphml.xml)
b. Relationships & data flow
- User clicks start/end in map2.html → HTTP request / file-based IPC to backend.py
- backend.py invokes preprocessingMap → extract → getBorder → getInput
- Pathfinding engine module (selects astar.py, astar_flood.py or astar_traffic.py)
- Frontend loads/refreshes with the computed path overlay
c. Architectural patterns & design principles
- Modular pipeline: clear separation of data extraction, preprocessing, algorithm, rendering
- Strategy pattern for selecting different A* variants (flood, traffic, vanilla)
- File-based I/O versus in-memory data flow
d. Technologies & libraries
- Python 3 scripts
- OSM/GraphML for map data
- A* algorithm implementations
- Simple HTML/JS for map interface

##### Detail is key
- Major Python scripts as discrete components or subcomponents
- How map2.html is both an input (template) and an output (rendered view)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        User["User (Browser)"]:::frontend
        FrontendTemplate["map2.html (View Template)"]:::frontend
        FloodView["map2_flood.html (Flood View)"]:::frontend
        TrafficView["map2_traffic.html (Traffic View)"]:::frontend
    end

    %% Backend Service
    subgraph "Backend Service" 
        direction TB
        Backend["backend.py (Entry Point)"]:::backend

        subgraph "Data-Prep Pipeline"
            direction TB
            Extract["extract.py"]:::backend
            GetInput["getInput.py"]:::backend
            GetBorder["getBorder.py"]:::backend
            Preprocess["preprocessingMap.py"]:::backend
        end

        subgraph "Pathfinding Engine"
            direction TB
            AStar["astar.py (Standard A*)"]:::backend
            AStarFlood["astar_flood.py (Flood-Aware A*)"]:::backend
            AStarTraffic["astar_traffic.py (Traffic-Aware A*)"]:::backend
        end

        subgraph "Visualization Module"
            direction TB
            Visualize["visualize.py"]:::backend
        end
    end

    %% Utility Modules
    subgraph "Utility Modules"
        direction TB
        Helper["helper.py"]:::utility
        LocationSearch["location_search.py"]:::utility
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        OSM["map.osm"]:::data
        GraphML["map3.graphml.xml"]:::data
        Blocked["blocked_edges.txt"]:::data
        BorderDef["border.txt"]:::data
        Out["out4.txt"]:::data
    end

    %% Other
    README["README.md"]:::other
    Test["test.py"]:::other

    %% Connections
    User -->|"loads template"| FrontendTemplate
    User -->|"loads flood view"| FloodView
    User -->|"loads traffic view"| TrafficView
    FrontendTemplate -->|"start/end coords"| Backend
    Backend -->|"invoke extract"| Extract
    Backend -->|"invoke getInput"| GetInput
    Backend -->|"invoke getBorder"| GetBorder
    Backend -->|"invoke preprocessingMap"| Preprocess

    Extract -->|"reads"| OSM
    GetInput -->|"reads"| GraphML
    GetInput -->|"reads"| Blocked
    GetBorder -->|"reads"| BorderDef
    Preprocess -->|"writes"| Out

    Backend -->|"select strategy"| AStar
    Backend -->|"select strategy"| AStarFlood
    Backend -->|"select strategy"| AStarTraffic

    AStar -->|"path data"| Visualize
    AStarFlood -->|"path data"| Visualize
    AStarTraffic -->|"path data"| Visualize

    Helper -->|"utilized by"| Backend
    LocationSearch -->|"utilized by"| Backend

    Visualize -->|"generates"| FrontendTemplate
    Visualize -->|"generates"| FloodView
    Visualize -->|"generates"| TrafficView

    README --- Backend
    Test --- Backend

    %% Click Events
    click User "https://github.com/anhquannguyen1/ttnt/blob/main/data/map2.html"
    click FrontendTemplate "https://github.com/anhquannguyen1/ttnt/blob/main/data/map2.html"
    click FloodView "https://github.com/anhquannguyen1/ttnt/blob/main/data/map2_flood.html"
    click TrafficView "https://github.com/anhquannguyen1/ttnt/blob/main/data/map2_traffic.html"
    click Backend "https://github.com/anhquannguyen1/ttnt/blob/main/src/backend.py"
    click Extract "https://github.com/anhquannguyen1/ttnt/blob/main/src/extract.py"
    click GetInput "https://github.com/anhquannguyen1/ttnt/blob/main/src/getInput.py"
    click GetBorder "https://github.com/anhquannguyen1/ttnt/blob/main/src/getBorder.py"
    click Preprocess "https://github.com/anhquannguyen1/ttnt/blob/main/src/preprocessingMap.py"
    click AStar "https://github.com/anhquannguyen1/ttnt/blob/main/src/astar.py"
    click AStarFlood "https://github.com/anhquannguyen1/ttnt/blob/main/src/astar_flood.py"
    click AStarTraffic "https://github.com/anhquannguyen1/ttnt/blob/main/src/astar_traffic.py"
    click Visualize "https://github.com/anhquannguyen1/ttnt/blob/main/src/visualize.py"
    click Helper "https://github.com/anhquannguyen1/ttnt/blob/main/src/helper.py"
    click LocationSearch "https://github.com/anhquannguyen1/ttnt/blob/main/src/location_search.py"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef data fill:#D2B48C,stroke:#333,stroke-width:1px
    classDef utility fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef other fill:#f0e68c,stroke:#333,stroke-width:1px
```
