# grist-data-desk/ira-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/grist-data-desk/ira-tracker
- Repository: https://github.com/grist-data-desk/ira-tracker

## Overview

##### Project Overview & Main Components
- The project is a full-stack web mapping application focused on visualizing IRA and BIL projects. It has two major parts:
b. The Data Processing Pipeline (in the /scripts folder) that ingests raw CSV and other datasets, converts them into geospatial formats (GeoJSON), produces vector tiles (PMTiles), and uploads assets (map styles, data tiles) to external storage/CDNs (Digital Ocean Spaces).

##### Analyzing the File Structure
- At the root, configuration and dependency files such as package.json, pnpm-lock.yaml, and TypeScript/Vite configs indicate that the project is managed with pnpm, TypeScript, and SvelteKit.
- The /src directory includes:
- /routes: Houses SvelteKit routes that define pages, layout, and application routing.
- The /scripts directory is dedicated to:
- Data processing scripts (in /scripts/src) using both Python and TypeScript to convert CSV files to GeoJSON, convert those to PMTiles, and deploy/upload these artifacts.
- A structured organization for data with /raw for input and /processed for output. This separation clearly shows the ETL pipeline depicting the flow from raw data ingestion to final, optimized map assets.

- Frontend Application:
- SvelteKit App – including UI & Routing (/src/routes, /src/lib).
- Mapping Library – MapLibre GL that integrates with the SvelteKit app for map rendering.
- Data Processing Pipeline:
- Data Ingestion Module – where CSVs and raw datasets (located in /scripts/data/raw) are loaded.
- Data Transformation Modules – scripts converting CSV to GeoJSON (csv-to-geojson.ts) and GeoJSON to PMTiles (geojson-to-pmtiles.ts); additional scripts for spatial analysis (project-similarity.py) can also be included.
- Data Upload & Deployment Modules – scripts responsible for uploading processed data (upload-geojson.ts, upload-pmtiles.ts, upload-styles.ts) and deploying the application.
- External Services:
- Digital Ocean Spaces as the storage/CDN, where the processed map assets (PMTiles and styles) are hosted.
- Additional libraries such as Turf.js and KDBush for geospatial analysis and spatial indexing.

b. Relationships and Interactions:
- How the output from the Data Processing Pipeline (map assets) feeds into the Frontend Application (via Digital Ocean Spaces or directly by the deployment scripts).
- How the SvelteKit app consumes these rendered map layers from MapLibre GL.

c. Architectural Patterns:
- Modular Separation: Distinguishing between the client-side visual application and the backend data processing pipeline.
- ETL Pipeline: Emphasizing the Extract, Transform, Load stages through the clear directory distinctions (/raw vs. /processed).
- API/Deployment Integration: Marking how deployment scripts combine build and publish processes for production use.

d. Important Technologies/Frameworks:
- SvelteKit for server-side rendering and routing.
- MapLibre GL JS for interactive map rendering.
- TailwindCSS for styling.
- TypeScript for development consistency.
- PMTiles as the optimized vector tile storage solution.
- External APIs/services such as Digital Ocean Spaces for asset delivery.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Application Cluster
    subgraph "Frontend Application"
        FSRoutes["SvelteKit Routes"]:::frontend
        FSUI["UI Components"]:::frontend
        FSMap["Map Rendering (MapLibre GL)"]:::frontend
    end

    %% Data Processing Pipeline Cluster
    subgraph "Data Processing Pipeline"
        RawData["Raw Data (CSV)"]:::dataproc
        CSV2Geo["CSV-to-GeoJSON"]:::dataproc
        Geo2PM["GeoJSON-to-PMTiles"]:::dataproc
        ProjSim["Project Similarity Analysis"]:::dataproc
        UploadGeo["Upload GeoJSON"]:::dataproc
        UploadPM["Upload PMTiles"]:::dataproc
        UploadStyles["Upload Map Styles"]:::dataproc
        Deploy["Deployment Script"]:::dataproc
    end

    %% External Services Cluster
    subgraph "External Services"
        DOSpaces["Digital Ocean Spaces/CDN"]:::external
        GeoLib["Geospatial Libraries (Turf.js, KDBush)"]:::external
    end

    %% Data Processing Flow
    RawData -->|"ingest"| CSV2Geo
    CSV2Geo -->|"convert"| Geo2PM
    CSV2Geo -->|"analyze"| ProjSim
    Geo2PM -->|"generate"| UploadPM
    CSV2Geo -->|"produce"| UploadGeo
    UploadPM --> DOSpaces
    UploadGeo --> DOSpaces
    UploadStyles --> DOSpaces
    Deploy --> DOSpaces

    %% Frontend consumes processed assets
    DOSpaces -->|"serve assets"| FSMap

    %% Frontend Internal Interactions
    FSRoutes -->|"provides layout to"| FSUI
    FSUI -->|"triggers"| FSMap

    %% Click Events for Frontend Components
    click FSRoutes "https://github.com/grist-data-desk/ira-tracker/tree/main/src/routes"
    click FSUI "https://github.com/grist-data-desk/ira-tracker/tree/main/src/lib/components"

    %% Click Events for Data Processing Pipeline
    click RawData "https://github.com/grist-data-desk/ira-tracker/tree/main/scripts/data/raw"
    click CSV2Geo "https://github.com/grist-data-desk/ira-tracker/blob/main/scripts/src/csv-to-geojson.ts"
    click Geo2PM "https://github.com/grist-data-desk/ira-tracker/blob/main/scripts/src/geojson-to-pmtiles.ts"
    click ProjSim "https://github.com/grist-data-desk/ira-tracker/blob/main/scripts/src/project-similarity.py"
    click UploadGeo "https://github.com/grist-data-desk/ira-tracker/blob/main/scripts/src/upload-geojson.ts"
    click UploadPM "https://github.com/grist-data-desk/ira-tracker/blob/main/scripts/src/upload-pmtiles.ts"
    click UploadStyles "https://github.com/grist-data-desk/ira-tracker/blob/main/scripts/src/upload-styles.ts"
    click Deploy "https://github.com/grist-data-desk/ira-tracker/blob/main/scripts/src/deploy.ts"

    %% Styles
    classDef frontend fill:#a2d2ff,stroke:#084298,stroke-width:2px;
    classDef dataproc fill:#ffe5e5,stroke:#d9534f,stroke-width:2px;
    classDef external fill:#e2f0d9,stroke:#5cb85c,stroke-width:2px;
```
