# narayana0804/apso-portfolio-optimizer architecture

> Architecture diagram of the GitHub repository narayana0804/apso-portfolio-optimizer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/narayana0804/apso-portfolio-optimizer
- Repository: https://github.com/narayana0804/apso-portfolio-optimizer

## Overview

This is a Flask stock-portfolio optimizer: a user selects stocks, the app loads their historical prices, computes candidate portfolio weights and risk metrics, then renders the results with generated charts. Its main internal layer is the APSO optimization module, which calculates returns and scores portfolios. The source excerpts show the route, computation, and chart calls; the README is empty, so broader product capabilities cannot be confirmed.

Main entry points: [`app.py`](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/app.py) (Flask routes), [`apso.py`](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/apso.py) (Portfolio optimizer), [`visualizer.py`](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/visualizer.py) (Chart generation), [`templates/index.html`](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/templates/index.html) (Stock selection page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web workflow"]
  node_webapp["Flask routes<br/>[app.py]"]
  node_index_template["Stock selection page<br/>[index.html]"]
  node_result_template["Results page<br/>[result.html]"]
end

subgraph group_portfolio["Portfolio optimization"]
  node_optimizer["Portfolio optimizer<br/>[apso.py]"]
  node_returns["Return calculator<br/>[apso.py]"]
  node_metrics["Portfolio metrics<br/>[apso.py]"]
end

subgraph group_outputs["Data and presentation"]
  node_price_data[("Stock price CSVs")]
  node_visualizer["Chart generation<br/>[visualizer.py]"]
  node_chart_files["Generated charts"]
end

node_user(("Investor"))

node_user -->|"selects stocks"| node_webapp
node_webapp -->|"renders"| node_index_template
node_webapp -->|"reads prices"| node_price_data
node_webapp -->|"optimizes portfolio"| node_optimizer
node_optimizer -->|"calculates returns"| node_returns
node_optimizer -->|"scores portfolios"| node_metrics
node_webapp -->|"generates charts"| node_visualizer
node_visualizer -->|"writes charts"| node_chart_files
node_webapp -->|"renders results"| node_result_template

click node_webapp "https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/app.py"
click node_price_data "https://github.com/narayana0804/apso-portfolio-optimizer/tree/master/data"
click node_optimizer "https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/apso.py"
click node_returns "https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/apso.py"
click node_metrics "https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/apso.py"
click node_visualizer "https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/visualizer.py"
click node_chart_files "https://github.com/narayana0804/apso-portfolio-optimizer/tree/master/static"
click node_index_template "https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/templates/index.html"
click node_result_template "https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/templates/result.html"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_webapp,node_index_template,node_result_template toneBlue
class node_optimizer,node_returns,node_metrics toneAmber
class node_price_data,node_visualizer,node_chart_files toneMint
class node_user toneIndigo
```

## Components

### Web workflow

- [Flask routes](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/app.py): `app.py`
- [Stock selection page](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/templates/index.html): `templates/index.html`
- [Results page](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/templates/result.html): `templates/result.html`

### Portfolio optimization

- [Portfolio optimizer](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/apso.py): `apso.py`
- [Return calculator](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/apso.py): `apso.py`
- [Portfolio metrics](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/apso.py): `apso.py`

### Data and presentation

- [Stock price CSVs](https://github.com/narayana0804/apso-portfolio-optimizer/tree/master/data): `data`
- [Chart generation](https://github.com/narayana0804/apso-portfolio-optimizer/blob/master/visualizer.py): `visualizer.py`
- [Generated charts](https://github.com/narayana0804/apso-portfolio-optimizer/tree/master/static): `static`

### Other components

- **Investor**

## Connections

- Investor → Flask routes: selects stocks (evidence: `app.py`)
- Flask routes → Stock selection page: renders (evidence: `app.py`)
- Flask routes → Stock price CSVs: reads prices (evidence: `app.py`)
- Flask routes → Portfolio optimizer: optimizes portfolio (evidence: `app.py`)
- Portfolio optimizer → Return calculator: calculates returns (evidence: `apso.py`)
- Portfolio optimizer → Portfolio metrics: scores portfolios (evidence: `apso.py`)
- Flask routes → Chart generation: generates charts (evidence: `app.py`)
- Chart generation → Generated charts: writes charts (evidence: `visualizer.py`)
- Flask routes → Results page: renders results (evidence: `app.py`)
