# itsharshvb/health_impact_project architecture

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

- Interactive diagram: https://gitdiagram.com/itsharshvb/health_impact_project
- Repository: https://github.com/itsharshvb/health_impact_project

## Overview

##### Project type and purpose
- This is a backend‐only, data‐driven microservice that scrapes air‐quality data, stores it in a local database, and exposes an API for predicting health impacts using a trained ML model.
- The README confirms it’s an “air pollutant health impact” project using machine learning.

##### File structure
- Top-level directories:
- backend/: all application code
- backend/data & data_files/: raw and derived data files (city lists, SQLite DB)
- backend/models/: serialized ML model & scaler
- backend/scrape_mod/: standalone scraper scripts & config
- backend/src/: core application
- Inside backend/src:
- api/routes.py – HTTP endpoints (likely FastAPI)
- core/ – configuration loader, logging setup, city‐loader utility
- db/ – ORM models and session management (SQLite)
- schemas/ – Pydantic schemas for request/response validation
- services/ – business logic (air‐quality fetcher, scraper orchestrator, health‐impact predictor)
- utils/ – supportive modules (city mapping)
- Supporting files:
- requirements.txt – Python dependencies
- backend_setup_guide.md – deployment instructions

##### Extract insights from the README
- Single responsibility: ingest data, store it, serve predictions.
- Stacks: Python, FastAPI (implied by route structure), SQLite, Keras (model), Pandas/CSV for scrapers.

##### Detailed capture of essential elements
- Environment variables or config file (core/config.py) flowing into components

## Diagram (Mermaid)

```mermaid
graph TB

    ExternalData["External Data Sources"]:::external

    subgraph "Scraping Module"
        SM1["scrape_city.py"] 
        SM2["json_to_csv_converter.py"] 
        SVScr["scraper.py"]:::service
    end

    CSV["CSV Files"]:::data

    subgraph "Database Layer"
        MODELS["models.py"] 
        SESSION["session.py"] 
        DB["SQLite Database"]:::storage
    end

    subgraph "API Server (FastAPI)"
        MAIN["main.py"]:::api
        ROUTES["routes.py"]:::api

        subgraph "Service Layer"
            AQ["air_quality.py"]:::service
            HP["health_predictor.py"]:::ml
            SCRSvc["scraper.py"]:::service
        end

        SCHEMA["air_quality.py Schema"]:::schema
    end

    subgraph "ML Model"
        MODEL["health_impact_predictor_model.keras"] 
        SCALER["health_impact_predictor_scaler.pkl"]
    end

    subgraph "Core & Utilities"
        CONFIG["config.py"]:::config
        LOGGING["logging_config.py"]:::config
        CITYLD["city_loader.py"]:::config
        CITYMAP["city_map.py"]:::util
    end

    Clients["HTTP Client"]:::client

    ExternalData --> SM1
    SM1 --> SM2
    SM2 --> CSV
    CSV -->|file I/O| SESSION
    SESSION -->|SQL| DB
    MODELS -->|ORM| SESSION

    Clients -->|HTTP| MAIN
    MAIN --> ROUTES
    ROUTES --> AQ
    ROUTES --> HP
    ROUTES --> SCRSvc
    ROUTES --> SCHEMA

    AQ -->|reads/writes| DB
    HP -->|loads model| MODEL
    HP -->|loads scaler| SCALER
    SCRSvc -->|orchestrates| SM1

    CONFIG --> MAIN
    CONFIG --> SM1
    CONFIG --> SESSION
    CONFIG --> HP

    LOGGING --> MAIN
    LOGGING --> SM1
    LOGGING --> AQ
    LOGGING --> HP

    CITYLD --> SM1
    CITYLD --> AQ
    CITYMAP --> SM1

    click SM1 "https://github.com/itsharshvb/health_impact_project/blob/main/backend/scrape_mod/scrape_city.py"
    click SM2 "https://github.com/itsharshvb/health_impact_project/blob/main/backend/scrape_mod/json _to_csv_convorter.py"
    click SVScr "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/services/scraper.py"
    click SESSION "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/db/session.py"
    click MODELS "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/db/models.py"
    click MODEL "https://github.com/itsharshvb/health_impact_project/blob/main/backend/models/health_impact_predictor_model.keras"
    click SCALER "https://github.com/itsharshvb/health_impact_project/blob/main/backend/models/health_impact_predictor_scaler.pkl"
    click HP "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/services/health_predictor.py"
    click MAIN "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/main.py"
    click ROUTES "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/api/routes.py"
    click AQ "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/services/air_quality.py"
    click SCHEMA "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/schemas/air_quality.py"
    click CONFIG "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/core/config.py"
    click LOGGING "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/core/logging_config.py"
    click CITYLD "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/core/city_loader.py"
    click CITYMAP "https://github.com/itsharshvb/health_impact_project/blob/main/backend/src/utils/city_map.py"

    classDef external fill:#bdd7ee,stroke:#3572A5,color:#000
    classDef data fill:#d5f5e3,stroke:#27AE60,color:#000
    classDef storage fill:#aed6f1,stroke:#21618c,color:#000
    classDef api fill:#e8daef,stroke:#8e44ad,color:#000
    classDef service fill:#fcf3cf,stroke:#f1c40f,color:#000
    classDef ml fill:#f9e79f,stroke:#d4ac0d,color:#000
    classDef config fill:#d5dbdb,stroke:#566573,color:#000
    classDef util fill:#f2f3f4,stroke:#85929e,color:#000
    classDef schema fill:#fadbd8,stroke:#c0392b,color:#000
    classDef client fill:#fdebd0,stroke:#ba4a00,color:#000
```
