# konilo/purchasing-power architecture

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

- Interactive diagram: https://gitdiagram.com/konilo/purchasing-power
- Repository: https://github.com/konilo/purchasing-power

## Overview

##### Main Components

a. Data Sources Layer:
- Eurostat API
- US Bureau of Labor Statistics API
- REST Countries API

b. ETL Service:
- Separate modules for each data source (eurostat, usbls, restcountries)
- ETL processing flow

c. Data Storage:
- AWS RDS PostgreSQL Database
- Different schema layers (raw data vs. enriched data)

d. Enrichment Service:
- Data transformation flow
- Connection to database for both input and output

e. Backend Service:
- FastAPI server
- API endpoints (CPI, CPI correction, personal finances)
- Connection to enriched database schema

f. Frontend Service:
- React/Vite application
- Main components (Basics, PersonalFinance, About)
- Static hosting on AWS S3

##### Component Relationships

- Data ingestion flow: External APIs → ETL → Raw Database
- Data processing flow: Raw Database → Enrichment → Enriched Database
- Application flow: Frontend → Backend → Enriched Database

##### Specific Design Elements

- Rectangles for services
- Hexagons for external APIs
- Rounded rectangles for AWS services

- Blue: AWS services
- Green: Data processing services (ETL, Enrichment)
- Yellow: External APIs
- Purple: Application services (Frontend, Backend)

##### Additional Details

Technical annotations:
- Docker containers for each service
- Programming languages used (Python, JavaScript/React)
- Key libraries (FastAPI, Vite)
- Database schemas and tables

##### Deployment Context

Deployment locations:
- AWS EC2 for Backend
- AWS S3 for Frontend
- AWS RDS for Database
- Local machine for ETL and Enrichment services

##### User Interface

This layered approach will help maintain clarity while showing the complete system architecture. Remember to maintain consistent spacing and alignment for better readability.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Data Sources Layer
    subgraph DataSources
        EurostatAPI[("Eurostat API")]:::externalAPI
        USBLS[("US BLS API")]:::externalAPI
        RestCountries[("REST Countries API")]:::externalAPI
    end

    %% ETL Layer
    subgraph ETLService
        EurostatETL["Eurostat ETL"]:::etl
        USBLS_ETL["US BLS ETL"]:::etl
        RestCountriesETL["REST Countries ETL"]:::etl
        click EurostatETL "https://github.com/Konilo/purchasing-power/tree/main/etl/eurostat/"
        click USBLS_ETL "https://github.com/Konilo/purchasing-power/tree/main/etl/usbls/"
        click RestCountriesETL "https://github.com/Konilo/purchasing-power/tree/main/etl/restcountries/"
    end

    %% Data Storage Layer
    subgraph DataStorage["AWS RDS PostgreSQL"]
        RawSchema[("Raw Data Schema")]:::database
        EnrichedSchema[("Enriched Schema")]:::database
        DimTables[("Dimension Tables")]:::database
        FactTables[("Fact Tables")]:::database
        click RawSchema "https://github.com/Konilo/purchasing-power/blob/main/enrichment/pure_sql/queries/enriched_schema.sql"
        click DimTables "https://github.com/Konilo/purchasing-power/blob/main/enrichment/pure_sql/queries/dim_countries.sql"
        click FactTables "https://github.com/Konilo/purchasing-power/blob/main/enrichment/pure_sql/queries/fact_cpi_values.sql"
    end

    %% Enrichment Service
    subgraph EnrichmentService
        MainEnrichment["Main Enrichment Process"]:::enrichment
        SQLTransform["SQL Transformations"]:::enrichment
        click MainEnrichment "https://github.com/Konilo/purchasing-power/blob/main/enrichment/main.py"
        click SQLTransform "https://github.com/Konilo/purchasing-power/tree/main/enrichment/pure_sql/queries/"
    end

    %% Backend Service
    subgraph BackendService["FastAPI Backend"]
        MainServer["Main Server"]:::backend
        CPIEndpoints["CPI Endpoints"]:::backend
        CPICorrection["CPI Correction"]:::backend
        PersonalFinances["Personal Finances"]:::backend
        click MainServer "https://github.com/Konilo/purchasing-power/blob/main/backend/main.py"
        click CPIEndpoints "https://github.com/Konilo/purchasing-power/blob/main/backend/routers/get_cpis.py"
        click CPICorrection "https://github.com/Konilo/purchasing-power/blob/main/backend/routers/get_cpi_correction.py"
        click PersonalFinances "https://github.com/Konilo/purchasing-power/blob/main/backend/routers/project_personal_finances.py"
    end

    %% Frontend Service
    subgraph FrontendService["React Frontend"]
        MainApp["Main App"]:::frontend
        BasicsComponent["Basics"]:::frontend
        PersonalFinanceComponent["Personal Finance"]:::frontend
        AboutComponent["About"]:::frontend
        click MainApp "https://github.com/Konilo/purchasing-power/blob/main/frontend/app/src/App.jsx"
        click BasicsComponent "https://github.com/Konilo/purchasing-power/blob/main/frontend/app/src/Basics.jsx"
        click PersonalFinanceComponent "https://github.com/Konilo/purchasing-power/blob/main/frontend/app/src/PersonalFinance.jsx"
        click AboutComponent "https://github.com/Konilo/purchasing-power/blob/main/frontend/app/src/About.jsx"
    end

    %% Shared Infrastructure
    subgraph SharedInfra["Shared Infrastructure"]
        DBConnector["Database Connector"]:::shared
        EnvUtils["Environment Utils"]:::shared
        click DBConnector "https://github.com/Konilo/purchasing-power/blob/main/shared/psql_connector.py"
        click EnvUtils "https://github.com/Konilo/purchasing-power/blob/main/shared/environments_utils.py"
    end

    %% Relationships
    EurostatAPI --> EurostatETL
    USBLS --> USBLS_ETL
    RestCountries --> RestCountriesETL
    
    EurostatETL --> RawSchema
    USBLS_ETL --> RawSchema
    RestCountriesETL --> RawSchema
    
    RawSchema --> MainEnrichment
    MainEnrichment --> SQLTransform
    SQLTransform --> EnrichedSchema
    SQLTransform --> DimTables
    SQLTransform --> FactTables
    
    EnrichedSchema --> BackendService
    DimTables --> BackendService
    FactTables --> BackendService
    
    MainServer --> CPIEndpoints
    MainServer --> CPICorrection
    MainServer --> PersonalFinances
    
    FrontendService --> BackendService
    
    SharedInfra --> BackendService
    SharedInfra --> EnrichmentService
    SharedInfra --> ETLService

    %% Styles
    classDef externalAPI fill:#FFE873,stroke:#333,stroke-width:2px
    classDef etl fill:#90EE90,stroke:#333,stroke-width:2px
    classDef database fill:#69C,stroke:#333,stroke-width:2px
    classDef enrichment fill:#98FB98,stroke:#333,stroke-width:2px
    classDef backend fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef frontend fill:#B19CD9,stroke:#333,stroke-width:2px
    classDef shared fill:#FFB6C1,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[("External API")]:::externalAPI
        L2["ETL Process"]:::etl
        L3[("Database")]:::database
        L4["Enrichment"]:::enrichment
        L5["Backend Service"]:::backend
        L6["Frontend Component"]:::frontend
        L7["Shared Infrastructure"]:::shared
    end
```
