# peterbrodersen/osmetymology architecture

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

- Interactive diagram: https://gitdiagram.com/peterbrodersen/osmetymology
- Repository: https://github.com/peterbrodersen/osmetymology

## Overview

##### Component Relationships

- External Data → Import Pipeline
- Import Pipeline → Storage Layer
- Storage Layer → Web Application
- Web Application → User Interface

##### Data Acquisition
- Denmark OSM data download
- Municipality boundaries download
##### Data Processing
- osm2pgsql processing
- Municipality boundary import
##### Data Aggregation
- Street name grouping
- Municipality-based splitting
##### Wikidata Enhancement
- Fetch Wikidata items
- Process "Instance of" relationships
##### Export Generation
- FlatGeobuf creation
- CSV export

Web Application Layer:
- Frontend Components
- Leaflet Map Integration
- Search Interface
- Helper Functions (helper.js)
- Backend Components
- Database Connection (connect.inc.php)
- API Endpoints (lookup.php)
- Data Serving Logic

##### Technical Details

Annotations showing:
- File formats (SQL, FlatGeobuf, CSV)
- Key technologies (Leaflet, PostgreSQL, PHP)
- Critical configuration points (db.php)
- Data flow directions
- API endpoints

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Data Sources"]
        OSM["OpenStreetMap<br/>(GeoFabrik Denmark)"]:::external
        WD["Wikidata"]:::external
        DAWA["DAWA<br/>(Municipality Boundaries)"]:::external
    end

    subgraph Import["Import Pipeline"]
        DL["Data Download"]:::process
        click DL "https://github.com/PeterBrodersen/osmetymology/blob/main/import/import.sh"
        
        subgraph Processing["Data Processing"]
            OSM2PGSQL["osm2pgsql"]:::process
            OGR["ogr2ogr"]:::process
            JSONB["JSONB Processing"]:::process
            click JSONB "https://github.com/PeterBrodersen/osmetymology/blob/main/import/jsonb.lua"
        end
        
        subgraph Aggregation["Data Aggregation"]
            AGG["Street Name Grouping"]:::process
            click AGG "https://github.com/PeterBrodersen/osmetymology/blob/main/import/aggregate.sql"
            MUNI["Municipality Processing"]:::process
            click MUNI "https://github.com/PeterBrodersen/osmetymology/blob/main/import/municipalitybuffers.sql"
            WIKI["Wikidata Integration"]:::process
            click WIKI "https://github.com/PeterBrodersen/osmetymology/blob/main/import/wikidataimport.php"
        end
        
        subgraph Export["Export Generation"]
            FGB["FlatGeobuf Export"]:::process
            click FGB "https://github.com/PeterBrodersen/osmetymology/blob/main/import/tofgb.sql"
            CSV["CSV Export"]:::process
            click CSV "https://github.com/PeterBrodersen/osmetymology/blob/main/import/tocsv.sql"
            STATS["Statistics Update"]:::process
            click STATS "https://github.com/PeterBrodersen/osmetymology/blob/main/import/updatestatsfile.php"
        end
    end

    subgraph Storage["Storage Layer"]
        DB[(PostgreSQL<br/>osmetymology)]:::storage
        FILES["File Storage"]:::storage
        click FILES "https://github.com/PeterBrodersen/osmetymology/tree/main/www/data"
        MUNISTORE["Municipality Storage"]:::storage
        click MUNISTORE "https://github.com/PeterBrodersen/osmetymology/tree/main/www/data/municipalities"
    end

    subgraph WebApp["Web Application"]
        direction TB
        subgraph Backend["PHP Backend"]
            DBCONN["Database Connection"]:::backend
            click DBCONN "https://github.com/PeterBrodersen/osmetymology/blob/main/www/connect.inc.php"
            API["API Endpoints"]:::backend
            click API "https://github.com/PeterBrodersen/osmetymology/blob/main/www/lookup.php"
            DBCONFIG["Database Config"]:::backend
            click DBCONFIG "https://github.com/PeterBrodersen/osmetymology/blob/main/config/db.example.php"
        end

        subgraph Frontend["Frontend Layer"]
            MAP["Leaflet Map Interface"]:::frontend
            click MAP "https://github.com/PeterBrodersen/osmetymology/blob/main/www/map.js"
            SEARCH["Search Component"]:::frontend
            HELPER["Helper Functions"]:::frontend
            click HELPER "https://github.com/PeterBrodersen/osmetymology/blob/main/www/helper.js"
            MUNIHELP["Municipality Helpers"]:::frontend
            click MUNIHELP "https://github.com/PeterBrodersen/osmetymology/blob/main/www/kommuner/helper.js"
            UI["User Interface"]:::frontend
            click UI "https://github.com/PeterBrodersen/osmetymology/blob/main/www/index.php"
            MUNIUI["Municipality Interface"]:::frontend
            click MUNIUI "https://github.com/PeterBrodersen/osmetymology/blob/main/www/kommuner/index.php"
            STYLE["Styling"]:::frontend
            click STYLE "https://github.com/PeterBrodersen/osmetymology/blob/main/www/style.css"
        end
    end

    OSM --> DL
    WD --> DL
    DAWA --> DL
    DL --> Processing
    Processing --> Aggregation
    Aggregation --> Export
    Export --> Storage
    Storage --> Backend
    Backend --> Frontend

    classDef external fill:#gray,stroke:#333,stroke-width:2px
    classDef process fill:#3498db,stroke:#2980b9,color:white
    classDef storage fill:#2ecc71,stroke:#27ae60,color:white
    classDef backend fill:#e67e22,stroke:#d35400,color:white
    classDef frontend fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        L1["External Systems"]:::external
        L2["Processing Components"]:::process
        L3["Storage Systems"]:::storage
        L4["Backend Components"]:::backend
        L5["Frontend Components"]:::frontend
    end
```
