# andgem/osmtoroadgraph architecture

> Architecture diagram of the GitHub repository andgem/osmtoroadgraph, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andgem/osmtoroadgraph
- Repository: https://github.com/andgem/osmtoroadgraph

## Overview

##### Main Components and Structure
The system should be represented with these key components:

a) Input Processing Layer:
- OSM XML Parser (osm/ directory)
- Configuration Handler (configuration.py)
- Input Sanitization (osm/sanitize_input.py)

b) Core Processing Layer:
- Graph Construction (graph/ directory)
- Graph Algorithms (graph/algorithms.py)
- Graph Conversion (graph/convert_graph.py)
- Graph Contraction (graph/contract_graph.py)

c) Output Generation Layer:
- Graph Writer (output/write_graph.py)
- Multiple Output Formats (.pycgr, .json for NetworkX)

##### Data Flow and Relationships

**Input → Processing → Output**
**[OSM XML/BZ2] → [Parser] → [Graph Construction] → [Output Formats]**

##### Component Details

For each major component, include:

a) Input Processing:
- XML Handler (osm/xml_handler.py)
- Way Parser (osm/way_parser_helper.py)
- OSM Types Definition (osm/osm_types.py)

b) Graph Processing:
- Graph Factory (graph/graphfactory.py)
- Graph Types (graph/graph_types.py)
- Core Graph Logic (graph/graph.py)

c) Utility Components:
- Geo Tools (utils/geo_tools.py)
- Performance Timer (utils/timer.py)

##### Special Features to Highlight

- Network type handling (pedestrian, bicycle, car)
- Graph contraction capability
- Multiple output format support
- Indoor path processing (optional feature)

##### Implementation Details

Relationships:
- Configuration influence on graph construction
- Graph type selection flow
- Contraction process flow (optional)
- Output format selection

**Top: Input Layer (OSM Data)**
**↓**
**Middle: Processing Layer (Graph Construction & Manipulation)**
**↓**
**Bottom: Output Layer (Multiple Formats)**

##### Additional Elements

Include:
- Version information (v.0.6.0)
- Supported Python versions (3.7+)
- Optional dependencies (NetworkX)

This design should help developers understand both the high-level architecture and the specific components that make up the system, while maintaining clarity about the data transformation process from OSM input to the final graph output formats.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        OSM[("OSM Data\n(XML/BZ2)")]
        Config["Configuration Handler"]:::config
        XML["XML Handler"]:::input
        WayParser["Way Parser"]:::input
        OSMTypes["OSM Types Definition"]:::input
        Sanitize["Input Sanitization"]:::input
    end

    subgraph Processing
        GraphConst["Graph Construction"]:::core
        GraphAlgo["Graph Algorithms"]:::core
        GraphConv["Graph Conversion"]:::core
        GraphCont["Graph Contraction"]:::core
        GraphFact["Graph Factory"]:::core
        GraphTypes["Graph Types"]:::core
    end

    subgraph Output
        Writer["Graph Writer"]:::output
        PYCGR[(".pycgr Format")]:::output
        JSON[(".json Format")]:::output
        NetworkX["NetworkX Format"]:::output
    end

    subgraph Utils
        GeoTools["Geo Tools"]:::util
        Timer["Performance Timer"]:::util
    end

    %% Relationships
    OSM --> XML
    XML --> WayParser
    WayParser --> OSMTypes
    OSMTypes --> Sanitize
    Config --> GraphConst
    Sanitize --> GraphConst
    
    GraphConst --> GraphAlgo
    GraphConst --> GraphConv
    GraphConst --> GraphCont
    GraphFact --> GraphConst
    GraphTypes --> GraphFact
    
    GraphConv --> Writer
    GraphCont --> Writer
    Writer --> PYCGR
    Writer --> JSON
    Writer --> NetworkX
    
    GeoTools -.-> GraphConst
    Timer -.-> Processing

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef input fill:#4CAF50,stroke:#2E7D32,color:white
    classDef output fill:#FFC107,stroke:#FFA000,color:black
    classDef config fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef util fill:#9E9E9E,stroke:#616161,color:white

    %% Click events
    click Config "https://github.com/andgem/osmtoroadgraph/blob/main/configuration.py"
    click XML "https://github.com/andgem/osmtoroadgraph/blob/main/osm/xml_handler.py"
    click WayParser "https://github.com/andgem/osmtoroadgraph/blob/main/osm/way_parser_helper.py"
    click OSMTypes "https://github.com/andgem/osmtoroadgraph/blob/main/osm/osm_types.py"
    click Sanitize "https://github.com/andgem/osmtoroadgraph/blob/main/osm/sanitize_input.py"
    click GraphConst "https://github.com/andgem/osmtoroadgraph/blob/main/graph/graph.py"
    click GraphAlgo "https://github.com/andgem/osmtoroadgraph/blob/main/graph/algorithms.py"
    click GraphConv "https://github.com/andgem/osmtoroadgraph/blob/main/graph/convert_graph.py"
    click GraphCont "https://github.com/andgem/osmtoroadgraph/blob/main/graph/contract_graph.py"
    click GraphFact "https://github.com/andgem/osmtoroadgraph/blob/main/graph/graphfactory.py"
    click GraphTypes "https://github.com/andgem/osmtoroadgraph/blob/main/graph/graph_types.py"
    click Writer "https://github.com/andgem/osmtoroadgraph/blob/main/output/write_graph.py"
    click GeoTools "https://github.com/andgem/osmtoroadgraph/blob/main/utils/geo_tools.py"
    click Timer "https://github.com/andgem/osmtoroadgraph/blob/main/utils/timer.py"
```
