# c-40/hackthon architecture

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

- Interactive diagram: https://gitdiagram.com/c-40/hackthon
- Repository: https://github.com/c-40/hackthon

## Overview

##### Project Type and Purpose
- Type: A single‐page, full-stack-ish Python web application for credit-risk classification, built with Streamlit.
- Purpose: Expose a pre-trained ML model (German Credit dataset) via a user interface for predicting whether a loan applicant is high or low risk.

##### File-Structure Analysis
Top-level entries:
- .devcontainer/ & devcontainer.json – Defines the VS Code development container (Docker) for consistent dev environment.
- Hackthon.ipynb – Jupyter notebook with data exploration, preprocessing, feature engineering, model training and evaluation.
- app.py – Streamlit application script: loads the model, defines UI forms, applies preprocessing, outputs predictions.
- credit_risk_model.pkl & optimized_credit_risk_model.pkl – Serialized ML model artifacts.
- requirements.txt – Python dependencies (e.g., streamlit, scikit-learn, pandas).

##### README Insights
- Describes end-to-end ML pipeline: data cleaning, EDA, feature engineering (custom `credit_risk_label`), model training, metrics.
- Explains deployment via Streamlit for interactive prediction.
- Links to Colab, GitHub, docs; mentions decision-tree, random forest, XGBoost experiments.

##### Main Components
a. Client (Web Browser) – End user interacts with the UI.
b. Streamlit Server (app.py) – Serves UI, collects input, orchestrates preprocessing & prediction.
c. Preprocessing Module (in app.py) – Applies the same cleaning, encoding, scaling, `credit_risk_label` logic used at training.
d. Model Loader – Reads `optimized_credit_risk_model.pkl` from filesystem.
e. ML Model (scikit-learn / XGBoost) – Performs prediction.
f. Dev Container (Docker) – Ensures consistent environment for development & debugging.
g. Notebook (Hackthon.ipynb) – Offline EDA/training component (not live in the deployed app).
h. External Services – (None in production; just Streamlit’s hosting platform if deployed).

##### Component Interactions & Data Flow
1. Client submits form data →
2. Streamlit Server receives inputs →
3. Preprocessing Module applies rules & encoders →
4. Model Loader retrieves the serialized model →
5. ML Model predicts risk →
6. Streamlit Server displays prediction to the Client.

##### Architectural Patterns & Principles
- Separation of Concerns: UI layer (Streamlit), logic layer (preprocessing + loading), and data layer (model files).
- Re-use of Training Pipeline: The custom feature-engineering logic (`credit_risk_label`) is mirrored in the app.
- Immutable Artifacts: Models are versioned as `.pkl` files, ensuring reproducibility.
- Containerization: Dev container ensures environment parity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main User Flow
    Client["Client Browser"]:::ui
    StreamlitApp["Streamlit App (app.py)"]:::ui
    Preprocessor["Preprocessing Module"]:::backend
    ModelLoader["Model Loader"]:::backend
    MLModelOpt["optimized_credit_risk_model.pkl"]:::artifact
    Predictor["ML Prediction Engine"]:::backend

    Client -->|"submit input"| StreamlitApp
    StreamlitApp -->|"raw data"| Preprocessor
    Preprocessor -->|"cleaned & encoded data"| ModelLoader
    ModelLoader -->|"load model"| MLModelOpt
    MLModelOpt -->|"predict()"| Predictor
    Predictor -->|"prediction result"| StreamlitApp
    StreamlitApp -->|"display result"| Client

    %% Offline Training Flow
    Notebook["Hackthon.ipynb"]:::offline
    MLModelInit["credit_risk_model.pkl"]:::artifact
    Notebook -.->|"train & serialize"| MLModelInit
    MLModelInit -.->|"version & optimize"| MLModelOpt

    %% Developer Environment
    subgraph "Developer Environment" 
        direction TB
        DevContainer[".devcontainer/devcontainer.json"]:::dev
        Dependencies["requirements.txt"]:::dev
        Documentation["README.md"]:::dev
    end

    %% Styling
    classDef ui fill:#D6EFFF,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#DFF7DF,stroke:#22863a,stroke-width:1px
    classDef artifact fill:#EEEEEE,stroke:#6a737d,stroke-width:1px
    classDef dev fill:#FFF4C1,stroke:#735C0F,stroke-width:1px
    classDef offline fill:#F2E8FF,stroke:#6f42c1,stroke-width:1px

    %% Click Events
    click StreamlitApp "https://github.com/c-40/hackthon/blob/main/app.py"
    click Preprocessor "https://github.com/c-40/hackthon/blob/main/app.py"
    click ModelLoader "https://github.com/c-40/hackthon/blob/main/app.py"
    click MLModelOpt "https://github.com/c-40/hackthon/blob/main/optimized_credit_risk_model.pkl"
    click MLModelInit "https://github.com/c-40/hackthon/blob/main/credit_risk_model.pkl"
    click Notebook "https://github.com/c-40/hackthon/blob/main/Hackthon.ipynb"
    click DevContainer "https://github.com/c-40/hackthon/blob/main/.devcontainer/devcontainer.json"
    click Dependencies "https://github.com/c-40/hackthon/blob/main/requirements.txt"
    click Documentation "https://github.com/c-40/hackthon/blob/main/README.md"
```
