# ubeyozcan/pnc-pricing-engine-backend architecture

> Architecture diagram of the GitHub repository ubeyozcan/pnc-pricing-engine-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ubeyozcan/pnc-pricing-engine-backend
- Repository: https://github.com/ubeyozcan/pnc-pricing-engine-backend

## Overview

##### Project type and purpose
- This is a Python‐based backend service built with FastAPI.
- It includes both an ML pipeline (data loading, EDA, model building) and a REST API layer that serves prebuilt models.
- Artifacts (trained models in pickle form) are stored under `models/prod` and used at runtime by the API.

##### File structure
- Top‐level scripts and dirs:
– EDA/eda.py: exploratory data analysis, one‐off analyses.
– build_models.py: orchestrates data loading via `src/DataFactory` and model training via `src/ModelFactory`, then writes pickles into `models/prod`.
– main.py: application entrypoint (likely loads models and dispatches to `app/runapp`).
– app/: contains the API code:
- runapp.py – starts the FastAPI server (uvicorn?).
- database.py – sets up database connections or ORM.
– models/: stores data inputs (`models/data/*.csv`) and production artifacts (`models/prod/*.pickle`).
– src/: library modules implementing factory patterns:
- DataFactory – data ingestion, cleaning.
- ModelFactory – model instantiation, training, evaluation.
– render.yaml, requirements.txt, pyproject.toml – deployment config and dependencies.

##### README
- Very brief: “Fast API for the backend.”
- Implies the primary purpose is exposing model inference or data services over HTTP.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Offline ML Pipeline
    subgraph "Offline ML Pipeline"
        direction TB
        EDA["EDA Module"]:::code
        InputData["Input Data Source\n(models/data/frenchmtpl_clean.csv)"]:::data
        DataFactory["DataFactory Module"]:::code
        ModelFactory["ModelFactory Module"]:::code
        MLOrchestrator["ML Pipeline Orchestrator\n(build_models.py)"]:::code
        Artifacts["Model Artifacts Storage\n(models/prod/)"]:::data

        EDA -->|“one-off analysis”| InputData
        InputData -->|“load raw data”| DataFactory
        DataFactory -->|“clean & prepare data”| ModelFactory
        MLOrchestrator -->|“invoke factories”| DataFactory
        MLOrchestrator -->|“invoke factories”| ModelFactory
        MLOrchestrator -->|“save pickles”| Artifacts
    end

    %% Online Inference Service
    subgraph "Online Inference Service"
        direction TB
        Main["API Entrypoint\n(main.py)"]:::code
        RunApp["FastAPI Server Starter\n(app/runapp.py)"]:::code
        ModelLoader["Model Loader"]:::code
        RequestHandler["Request Handlers"]:::code
        DatabaseModule["Database Connection Module\n(app/database.py)"]:::code

        Main -->|“start server”| RunApp
        RunApp -->|“load models”| ModelLoader
        ModelLoader -->|“read pickles”| Artifacts
        RunApp -->|“register endpoints”| RequestHandler
        RequestHandler -->|“DB operations”| DatabaseModule
    end

    %% External Clients and Infrastructure
    subgraph "External & Deployment" 
        direction TB
        ExternalClient["External Clients"]:::external
        DeployConfig["Deployment Configuration\n(render.yaml)"]:::infra
        Requirements["Python Dependencies\n(requirements.txt)"]:::infra
        Pyproject["Project Metadata\n(pyproject.toml)"]:::infra

        ExternalClient -->|“HTTP requests”| RequestHandler
        DeployConfig -->|“defines container”| RunApp
        Requirements -->|“install deps”| RunApp
        Pyproject -->|“project config”| RunApp
    end

    %% Styles
    classDef code fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef data fill:#90EE90,stroke:#000,stroke-width:1px
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#000,stroke-width:1px

    %% Click Events
    click EDA "https://github.com/ubeyozcan/pnc-pricing-engine-backend/blob/main/EDA/eda.py"
    click DataFactory "https://github.com/ubeyozcan/pnc-pricing-engine-backend/tree/main/src/DataFactory/"
    click ModelFactory "https://github.com/ubeyozcan/pnc-pricing-engine-backend/tree/main/src/ModelFactory/"
    click MLOrchestrator "https://github.com/ubeyozcan/pnc-pricing-engine-backend/blob/main/build_models.py"
    click Artifacts "https://github.com/ubeyozcan/pnc-pricing-engine-backend/tree/main/models/prod/"
    click InputData "https://github.com/ubeyozcan/pnc-pricing-engine-backend/blob/main/models/data/frenchmtpl_clean.csv"
    click RunApp "https://github.com/ubeyozcan/pnc-pricing-engine-backend/blob/main/app/runapp.py"
    click Main "https://github.com/ubeyozcan/pnc-pricing-engine-backend/blob/main/main.py"
    click DatabaseModule "https://github.com/ubeyozcan/pnc-pricing-engine-backend/blob/main/app/database.py"
    click DeployConfig "https://github.com/ubeyozcan/pnc-pricing-engine-backend/blob/main/render.yaml"
    click Requirements "https://github.com/ubeyozcan/pnc-pricing-engine-backend/blob/main/requirements.txt"
    click Pyproject "https://github.com/ubeyozcan/pnc-pricing-engine-backend/blob/main/pyproject.toml"
```
