# artonge/go-gtfs architecture

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

- Interactive diagram: https://gitdiagram.com/artonge/go-gtfs
- Repository: https://github.com/artonge/go-gtfs

## Overview

##### Project Type Analysis
This is an open-source Go library that parses GTFS files, which are standardized public transit data files. The project is primarily focused on data parsing and transformation.

##### Main Components

a. Input Layer:
- Two possible input paths:
- Single GTFS Directory
- Split GTFS Directories

b. Parser Core:
- Main GTFS Parser Component
- File Handlers for different GTFS file types
- Data Model Transformers

c. Data Model Layer:
- GTFS Struct (Main container)
- Individual Entity Models (Agency, Routes, Stops, etc.)

**[Input Sources] → [Parser Core] → [Data Models] → [Client Code]**

##### Detailed Component Breakdown

Input Sources (Blue):
**┌─────────────────┐**
- Single GTFS Dir │
- ┬────────┘

**┌─────────────────┐**
- Split GTFS Dirs │
- ┬────────┘

Parser Core (Green):
**┌─────────────────────┐**
- GTFS Parser      │
- ┌───────────────┐   │
- File Handlers │   │
- ┘   │
- ┌───────────────┐   │
- Data Validators│   │
- ┘   │
- ┬───────────┘

Data Models (Yellow):
**┌─────────────────┐**
- GTFS Struct   │
- ┌─────────────┐ │
- Agency     │ │
- Routes     │ │
- Stops      │ │
- Trips      │ │
- ...        │ │
- ┘ │
- ┘

##### Important Elements to Highlight

- File Processing Flow:
- How input files are processed sequentially
- Validation steps
- Error handling paths

- Data Model Relationships:
- Relationships between different GTFS entities
- Required vs. optional fields

##### Technical Details

- Input Formats:
- .txt files
- CSV parsing capabilities
- Directory structure requirements

- Error Handling:
- Error return paths
- Validation failure handling

## Diagram (Mermaid)

```mermaid
graph TB
    %% Input Layer
    subgraph Input
        SingleDir["Single GTFS Directory"]:::input
        SplitDir["Split GTFS Directories"]:::input
        BadInput["Invalid Input"]:::input
    end

    %% Parser Core Layer
    subgraph ParserCore
        Parser["GTFS Parser Core"]:::core
        Constants["Parser Constants"]:::core
        FileHandlers["File Handlers"]:::process
        Validators["Data Validators"]:::process
    end

    %% Data Models Layer
    subgraph DataModels
        GTFSStruct["GTFS Struct"]:::model
        subgraph Entities
            Agency["Agency Data"]:::entity
            Routes["Routes Data"]:::entity
            Stops["Stops Data"]:::entity
            Trips["Trips Data"]:::entity
            Calendar["Calendar Data"]:::entity
            CalendarDates["Calendar Dates"]:::entity
            StopTimes["Stop Times"]:::entity
            Transfers["Transfers"]:::entity
        end
    end

    %% Test Layer
    subgraph Testing
        ParserTest["Parser Tests"]:::test
    end

    %% Relationships
    SingleDir --> Parser
    SplitDir --> Parser
    BadInput -.-> Parser
    
    Parser --> FileHandlers
    Constants --> Parser
    FileHandlers --> Validators
    Validators --> GTFSStruct
    
    GTFSStruct --> Agency
    GTFSStruct --> Routes
    GTFSStruct --> Stops
    GTFSStruct --> Trips
    GTFSStruct --> Calendar
    GTFSStruct --> CalendarDates
    GTFSStruct --> StopTimes
    GTFSStruct --> Transfers

    Parser --> ParserTest

    %% Click Events
    click Parser "https://github.com/artonge/go-gtfs/blob/master/gtfs.go"
    click GTFSStruct "https://github.com/artonge/go-gtfs/blob/master/models.go"
    click Constants "https://github.com/artonge/go-gtfs/blob/master/const.go"
    click SingleDir "https://github.com/artonge/go-gtfs/tree/master/gtfs_test/ratp/"
    click SplitDir "https://github.com/artonge/go-gtfs/tree/master/gtfs_test/ratp_splitted/"
    click BadInput "https://github.com/artonge/go-gtfs/tree/master/gtfs_test/ratp_bad/"
    click ParserTest "https://github.com/artonge/go-gtfs/blob/master/gtfs_test.go"
    click Agency "https://github.com/artonge/go-gtfs/blob/master/gtfs_test/ratp/agency.txt"
    click Routes "https://github.com/artonge/go-gtfs/blob/master/gtfs_test/ratp/routes.txt"
    click Stops "https://github.com/artonge/go-gtfs/blob/master/gtfs_test/ratp/stops.txt"
    click Trips "https://github.com/artonge/go-gtfs/blob/master/gtfs_test/ratp/trips.txt"
    click Calendar "https://github.com/artonge/go-gtfs/blob/master/gtfs_test/ratp/calendar.txt"
    click CalendarDates "https://github.com/artonge/go-gtfs/blob/master/gtfs_test/ratp/calendar_dates.txt"
    click StopTimes "https://github.com/artonge/go-gtfs/blob/master/gtfs_test/ratp/stop_times.txt"
    click Transfers "https://github.com/artonge/go-gtfs/blob/master/gtfs_test/ratp/transfers.txt"

    %% Styles
    classDef input fill:#2374ab,stroke:#000,stroke-width:2px,color:#fff
    classDef core fill:#2a9d8f,stroke:#000,stroke-width:2px,color:#fff
    classDef process fill:#4caf50,stroke:#000,stroke-width:2px,color:#fff
    classDef model fill:#f4a261,stroke:#000,stroke-width:2px,color:#000
    classDef entity fill:#e9c46a,stroke:#000,stroke-width:2px,color:#000
    classDef test fill:#e76f51,stroke:#000,stroke-width:2px,color:#fff
```
