# shivanshsinghal107/investment-portfolio architecture

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

- Interactive diagram: https://gitdiagram.com/shivanshsinghal107/investment-portfolio
- Repository: https://github.com/shivanshsinghal107/investment-portfolio

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with Flask, focused on student investment portfolio optimization.
- Purpose: let users (students/low-income) register/login, input holdings, run three portfolio-optimization algorithms (Markowitz, Minimum Variance, Sharpe Ratio via Monte Carlo), view results and track investments with live stats.

##### File Structure
- Top-level files:
- app.py – Flask application entrypoint and route definitions (controllers).
- data.py – core business logic module (data access, optimization algorithms).
- Procfile – deployment instructions for Heroku.
- requirements.txt – Python dependencies.
- stock data.csv – local sample dataset.
- Directories:
- templates/ – Jinja2 HTML templates (views).
- static/ – Bootstrap CSS, JS, video demos, images.
- No separate “services” or microservices – it’s a monolithic Flask app.

##### README
- Confirms tech stack: Flask (Python), Bootstrap, PostgreSQL.
- Describes features: registration/login, tracking, optimization, live stats.
- Mentions three in-house optimization techniques.

##### Main Components
a. Client Layer
– Web browser (renders HTML/CSS/JS)
b. Web Server Layer (Flask monolith)
– Routing & Controllers (app.py)
– Business Logic / Optimization Engine (data.py)
– Template Renderer (Jinja2)
– Static File Server (videos, CSS, JS)
c. Persistence Layer
– PostgreSQL database (user profiles, investment history, optimization results)
– Local CSV store for offline data
d. External Services
– Live Stock Data API (for up-to-date quotes)
e. Deployment Platform
– Heroku (Procfile)

##### Component Interactions & Data Flow
- User → HTTP(s) → Flask routes
- Flask controllers call:
- data.py to fetch/process data & run optimization
- SQLAlchemy/psycopg2 to query/update PostgreSQL
- External API client to fetch live stock prices
- Flask → Jinja2 → rendered HTML → User
- Flask → Static files (CSS/JS/Video) → User
- Async or synchronous calls between layers are all handled in the same process.

##### Key Architectural Patterns & Design Principles
- MVC-style separation:
- Models/business logic in data.py
- Views in templates/ (HTML + Bootstrap)
- Controllers in app.py
- Single-page-style flows per route (no separate SPA framework).
- Monolithic deployment – easy to evolve but not microservices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser"]:::ui
    end

    %% Server Layer
    subgraph "Server Layer"
        subgraph "Flask App"
            Controllers["Routes / Controllers\n(app.py)"]:::server
            Engine["Business Logic / Optimization Engine\n(data.py)"]:::server
            Renderer["Template Renderer\n(Jinja2)"]:::server
            StaticServer["Static Asset Server\n(CSS/JS/Video)"]:::server
        end
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        Postgres["PostgreSQL Database"]:::db
        CSV["Local Sample Dataset\n(stock data.csv)"]:::db
    end

    %% External Services
    subgraph "External Services"
        StockAPI["Live Stock Data API"]:::external
    end

    %% Deployment & Config
    subgraph "Deployment & Configuration"
        Heroku["Heroku Deployment\n(Procfile)"]:::deployment
        Requirements["Dependency Definitions\n(requirements.txt)"]:::config
        Readme["Project Documentation\n(README.md)"]:::config
    end

    %% Connections
    Browser -->|"HTTP Requests/Responses"| Controllers
    Controllers -->|"calls"| Engine
    Controllers -->|"renders"| Renderer
    Controllers -->|"serves"| StaticServer
    Engine -->|"queries/updates\n(SQLAlchemy)"| Postgres
    Engine -->|"reads"| CSV
    Engine -->|"fetches\n(REST/JSON)"| StockAPI
    Renderer -->|"outputs HTML"| Browser
    StaticServer -->|"serves assets"| Browser
    Heroku -.-> Controllers

    %% Click Events
    click Controllers "https://github.com/shivanshsinghal107/investment-portfolio/blob/master/app.py"
    click Engine "https://github.com/shivanshsinghal107/investment-portfolio/blob/master/data.py"
    click Renderer "https://github.com/shivanshsinghal107/investment-portfolio/tree/master/templates/"
    click StaticServer "https://github.com/shivanshsinghal107/investment-portfolio/tree/master/static/"
    click CSV "https://github.com/shivanshsinghal107/investment-portfolio/blob/master/stock data.csv"
    click Heroku "https://github.com/shivanshsinghal107/investment-portfolio/tree/master/Procfile"
    click Requirements "https://github.com/shivanshsinghal107/investment-portfolio/blob/master/requirements.txt"
    click Readme "https://github.com/shivanshsinghal107/investment-portfolio/blob/master/README.md"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#1B4F72,rx:5,ry:5;
    classDef server fill:#A9DFBF,stroke:#145A32,rx:5,ry:5;
    classDef db fill:#F9E79F,stroke:#B9770E,rx:5,ry:5;
    classDef external fill:#D5DBDB,stroke:#424949,rx:5,ry:5;
    classDef deployment fill:#E8DAEF,stroke:#512E5F,rx:5,ry:5;
    classDef config fill:#F5B7B1,stroke:#C0392B,rx:5,ry:5;
```
