# amb1/sgh_masterthesis architecture

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

- Interactive diagram: https://gitdiagram.com/amb1/sgh_masterthesis
- Repository: https://github.com/amb1/sgh_masterthesis

## Overview

##### Main Components
- Backend (located under /local):
– Data Ingestion & Processing: The Python scripts (e.g., scripts/process_citygml.py) are responsible for loading CityGML, fetching additional data via WFS and OSM, and creating/updating the project directories (e.g., local/projects/CityGMLProject) for City Energy Analyst (CEA).
– Configuration & Workflow Management: The cfg folder holds various YAML configuration files (for CEA and data sources) that define data mapping, available layers, and analysis workflows.
– Utility Modules: Under local/utils (including submodules like CEA, data_processing, data_sources, helper, etc.) that encapsulate the logic for processing data, mapping CityGML to IFC, and performing additional helper functions.
– Execution & Orchestration: The main entry points like run_cea.py and the various scripts coordinate the pipeline from data ingestion to project creation.

- Frontend (located under /web):
– User Interface & Components: Written in React and TypeScript, with components (e.g., Auth, Projects, Config, CesiumViewer) managing user interactions, authentication, and layout.
– Visualization: CesiumJS is integrated (as seen in CesiumViewer and CesiumConfig components) to render 3D geospatial data.
– API Communication: The frontend contains API endpoints (in web/src/app/api/) and service modules (e.g., citygmlService.ts, viennaService.ts, wfsService.ts) for interacting with the backend and possibly Supabase for auth and backend data.
– Supabase Integration: Used for authentication and possibly database interactions, as referenced in the Supabase configuration folders and related scripts.

##### Relationships and Interactions
- Data Flow:
– The backend ingests and processes CityGML data, enriches it via external data sources (WFS, OSM), and produces outputs that are either stored in project folders or made available via API endpoints.
– The frontend communicates with the backend via RESTful API endpoints (found in web/src/app/api) to retrieve processed data and project boundaries.
– The frontend then utilizes CesiumJS and other UI components to display the 3D visualization and data analytics to the user.
- Dependencies:
– The backend is loosely coupled with the frontend through clearly defined service endpoints and data contracts.
– Both parts of the application are connected via configuration files (both YAML and JSON) that define data mappings, processing parameters, and service endpoints.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clearly delineated boundaries between the Python backend (data processing, workflow orchestration) and the React frontend (user interactions, 3D visual rendering).
- Modularization: Both directories (local and web) contain modular components (scripts, utilities, API endpoints, UI components) that are isolated and reusable.
- Configuration-Driven Behavior: The backend uses YAML files to define mappings and workflows, allowing flexibility in adapting to various data sources and processing requirements.
- Integration via APIs: The frontend’s API layer (and the SaaS components via Supabase) indicates a clear contract for communication between the UI and the processing backend.

##### Relevant Technologies, Frameworks & Libraries
- Backend: Python 3.9+, CEA (City Energy Analyst) workflow, CityGML processing utilities, YAML configuration.
- Frontend: React 18 with TypeScript, Vite (for module bundling and HMR), CesiumJS (3D visualization), Supabase, TailwindCSS.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Sources
    subgraph "External Data Sources"
        E1["CityGML Files"]:::external
        E2["OSM Data"]:::external
        E3["WFS Service"]:::external
    end

    %% Python Backend Region
    subgraph "Python Backend"
        %% Data Processing Subgraph
        subgraph "Data Processing"
            BN1["Data Ingestion & Processing"]:::backend
            BN2["Data Sources Utilities"]:::backend
            BN3["Configuration & Workflow Management"]:::backend
            BN4["Utility Modules"]:::backend
        end
        %% Execution & Orchestration Subgraph
        subgraph "Execution & Orchestration"
            OB1["Run CEA"]:::backend
            OB2["Test Pipeline"]:::backend
        end
    end

    %% React Frontend Region
    subgraph "React Frontend"
        %% UI Layer
        subgraph "UI Layer"
            FE1["UI Components"]:::frontend
            FE2["CesiumJS Viewer"]:::frontend
            FE3["CesiumJS Config"]:::frontend
        end
        %% API Layer
        subgraph "API Layer"
            FE4["API Endpoints"]:::frontend
            FE5["Service Modules"]:::frontend
        end
        %% Supabase & Authentication
        subgraph "Auth & Integration"
            FE6["Supabase Library"]:::frontend
            FE7["Supabase Directory"]:::frontend
            FE8["Auth Context"]:::frontend
        end
    end

    %% Connections from External Data Sources to Backend Data Ingestion
    E1 --> BN1
    E2 --> BN1
    E3 --> BN1

    %% Connections within Backend Data Processing to Execution
    BN2 --> BN1
    BN3 --> OB1
    BN4 --> OB1
    BN1 --> OB1
    OB1 --> FE4
    OB2 --> FE4

    %% Connections in Frontend: API Layer to UI
    FE4 --> FE5
    FE5 --> FE1
    FE1 --> FE2
    FE1 --> FE3

    %% Supabase & Auth integration with UI
    FE6 --> FE1
    FE7 --> FE1
    FE8 --> FE1

    %% Click Events for Backend Components
    click BN1 "https://github.com/amb1/sgh_masterthesis/blob/main/local/scripts/process_citygml.py"
    click BN2 "https://github.com/amb1/sgh_masterthesis/tree/main/local/utils/data_sources"
    click BN3 "https://github.com/amb1/sgh_masterthesis/tree/main/local/cfg"
    click BN4 "https://github.com/amb1/sgh_masterthesis/tree/main/local/utils"
    click OB1 "https://github.com/amb1/sgh_masterthesis/blob/main/local/run_cea.py"
    click OB2 "https://github.com/amb1/sgh_masterthesis/blob/main/local/scripts/test_pipeline.py"

    %% Click Events for Frontend Components
    click FE1 "https://github.com/amb1/sgh_masterthesis/tree/main/web/src/components"
    click FE2 "https://github.com/amb1/sgh_masterthesis/blob/main/web/src/components/Viewer/CesiumViewer.tsx"
    click FE3 "https://github.com/amb1/sgh_masterthesis/blob/main/web/src/components/Config/CesiumConfig.tsx"
    click FE4 "https://github.com/amb1/sgh_masterthesis/blob/main/web/src/app/api/project-boundaries/route.ts"
    click FE5 "https://github.com/amb1/sgh_masterthesis/blob/main/web/src/lib/citygmlService.ts"
    click FE6 "https://github.com/amb1/sgh_masterthesis/blob/main/web/src/lib/supabase.ts"
    click FE7 "https://github.com/amb1/sgh_masterthesis/tree/main/web/supabase"
    click FE8 "https://github.com/amb1/sgh_masterthesis/blob/main/web/src/contexts/AuthContext.tsx"

    %% Styling Classes
    classDef backend fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef frontend fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#DAA520,stroke-width:2px;
```
