# projectultra/finance_metrics architecture

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

- Interactive diagram: https://gitdiagram.com/projectultra/finance_metrics
- Repository: https://github.com/projectultra/finance_metrics

## Overview

##### Project type and purpose
- This is a full-stack Django web application (“FM” project) for fetching live stock, currency, commodity, and news data, preprocessing it, running it through a TensorFlow/Keras model, and displaying predicted prices in a browser.
- Key functionality:
- Live data ingestion from an external API
- Data preprocessing and transformation
- ML inference via a saved TensorFlow Keras model
- Presentation of results via HTML templates

##### File structure
- Top-level directories and files
- FM/ – Django project settings, URLs, WSGI/ASGI entry points
- FinanceMetrics/ – Django app containing models, views, templates, migrations
- Stock Data/ – sample CSVs, a Jupyter notebook, and the saved TensorFlow model artifacts
- db.sqlite3 – local database
- Dockerfile, .github/workflows – containerization and CI pipelines
- requirements.txt – Python dependencies
- manage.py – Django command-line utility
- Architectural cues
- MVC pattern (Models in FinanceMetrics/models.py, Views in views.py, Templates in Templates/)
- ORM migrations for evolving data schema
- Integration of a machine‐learning model as part of the application

##### README for additional insights
- Confirms tech stack: Python, Django, TensorFlow, Keras, HTML/CSS
- Describes how live data is fetched, preprocessed, and fed to a trained model
- Shows screenshots of UI sections (stocks, currencies, commodities, news)

a. Main components
- Client Browser (UI)
- Django Web Server
– URL Router (FM/urls.py)
– Views/Controllers (FinanceMetrics/views.py)
– Template Renderer (FinanceMetrics/Templates/*.html)
– ORM & Database Layer (FinanceMetrics/models.py + SQLite)
– ML Inference Module (loads TensorFlow model from Stock Data/models)
- External Stock Data API
- Static Asset Server (images/, CSS)
- CI/CD Pipeline (GitHub Actions, Dockerfile)
b. Relationships and interactions
1. User requests a page in the browser
2. Django URL router dispatches to the view
3. View calls a service to fetch live data from External API
4. Data flows into preprocessing routines
5. Preprocessed data is passed into the ML Inference Module
6. Model returns predictions
7. View writes results to the ORM for optional logging (SQLite)
8. Template Renderer builds the HTML response
9. Browser displays results; static assets are loaded in parallel
c. Architectural patterns and design principles
- MVC (Models, Views, Templates)
- Single monolithic service with clearly separated layers
- Reuse of Django’s built-in ORM and templating
- ML model as an internal library – could be factored out to a micro-service if scalability demands
d. Key technologies and libraries
- Django (web framework, routing, ORM, templating)
- SQLite (development database)
- TensorFlow & Keras (model inference)
- Python scripts/notebooks (data exploration in Stock Data/)
- Docker & GitHub Actions (container build and CI/CD)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)"
        direction TB
        Browser["Web Browser"]:::frontend
    end

    %% External Services
    ExternalAPI["External Stock Data API"]:::external

    %% Server Layer
    subgraph "Django Server"
        direction TB

        subgraph "Entry & Configuration"
            direction TB
            Settings["Settings (FM/settings.py)"]:::backend
            ASGI["ASGI Entry (FM/asgi.py)"]:::backend
            WSGI["WSGI Entry (FM/wsgi.py)"]:::backend
            Manage["Manage Utility (manage.py)"]:::backend
        end

        URLRouter["URL Router (FM/urls.py)"]:::backend
        Views["Views/Controllers (FinanceMetrics/views.py)"]:::backend
        subgraph "Data Processing"
            direction TB
            PreprocCSV["CSV Samples (Stock Data/*.csv)"]:::ml
            PreprocNotebook["Exploration Notebook (Stock Data/model.ipynb)"]:::ml
            Preprocessor["Preprocessing Module"]:::ml
        end
        MLModule["ML Inference Module (Stock Data/models/)"]:::ml
        subgraph "Persistence"
            direction TB
            ORM["ORM Models (FinanceMetrics/models.py)"]:::backend
            Migrations["Migrations (FinanceMetrics/migrations/)"]:::backend
            SQLite["SQLite DB (db.sqlite3)"]:::datastore
        end
        TemplateRenderer["Template Renderer (FinanceMetrics/Templates/index.html)"]:::frontend
    end

    StaticAssets["Static Assets Server (images/)"]:::frontend

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        DockerfileNode["Dockerfile"]:::backend
        Workflow["GitHub Actions Workflow (.github/workflows/docker image.yml)"]:::backend
    end

    %% Connections
    Browser -->|Requests page| URLRouter
    URLRouter -->|Dispatches to| Views
    Views -->|Fetch live data| ExternalAPI
    Views -->|Invoke| Preprocessor
    PreprocCSV --> Preprocessor
    PreprocNotebook --> Preprocessor
    Preprocessor -->|Feed data| MLModule
    MLModule -->|Predictions| Views
    Views -->|Log results| ORM
    ORM --> Migrations
    ORM --> SQLite
    Views -->|Render| TemplateRenderer
    TemplateRenderer -->|Responds| Browser
    Browser -->|Load assets| StaticAssets

    %% CI/CD links
    DockerfileNode --> Workflow

    %% Click Events
    click Settings "https://github.com/projectultra/finance_metrics/blob/main/FM/settings.py"
    click ASGI "https://github.com/projectultra/finance_metrics/blob/main/FM/asgi.py"
    click WSGI "https://github.com/projectultra/finance_metrics/blob/main/FM/wsgi.py"
    click Manage "https://github.com/projectultra/finance_metrics/blob/main/manage.py"
    click URLRouter "https://github.com/projectultra/finance_metrics/blob/main/FM/urls.py"
    click Views "https://github.com/projectultra/finance_metrics/blob/main/FinanceMetrics/views.py"
    click PreprocCSV "https://github.com/projectultra/finance_metrics/blob/main/Stock Data/*.csv"
    click PreprocNotebook "https://github.com/projectultra/finance_metrics/blob/main/Stock Data/model.ipynb"
    click MLModule "https://github.com/projectultra/finance_metrics/tree/main/Stock Data/models/"
    click ORM "https://github.com/projectultra/finance_metrics/blob/main/FinanceMetrics/models.py"
    click Migrations "https://github.com/projectultra/finance_metrics/tree/main/FinanceMetrics/migrations/"
    click SQLite "https://github.com/projectultra/finance_metrics/blob/main/db.sqlite3"
    click TemplateRenderer "https://github.com/projectultra/finance_metrics/blob/main/FinanceMetrics/Templates/index.html"
    click StaticAssets "https://github.com/projectultra/finance_metrics/tree/main/images/"
    click DockerfileNode "https://github.com/projectultra/finance_metrics/tree/main/Dockerfile"
    click Workflow "https://github.com/projectultra/finance_metrics/blob/main/.github/workflows/docker image.yml"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#2196F3,stroke-width:2px
    classDef backend fill:#FFF3E0,stroke:#FB8C00,stroke-width:2px
    classDef external fill:#E8F5E9,stroke:#43A047,stroke-width:2px
    classDef datastore fill:#EFEBE9,stroke:#5D4037,stroke-width:2px
    classDef ml fill:#F3E5F5,stroke:#8E24AA,stroke-width:2px
```
