# rammarthi9/tunefolio architecture

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

- Interactive diagram: https://gitdiagram.com/rammarthi9/tunefolio
- Repository: https://github.com/rammarthi9/tunefolio

## Overview

TuneFolio is a read-only portfolio intelligence platform: an investor connects a Zerodha account, then views holdings, portfolio context, and historical analysis in a dashboard. Its runtime spans consent-based authentication, broker data retrieval, account-scoped persistence, and analysis of sectors, trades, delivery volumes, and performance. The README also describes snapshot-based historical insight and comparative analysis. The supplied excerpts establish key service calls; some feature relationships are supported only by the SOURCE INDEX or README, so unsampled implementation details are not inferred.

Main entry points: [`backend/app/services/db.py`](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/db.py) (Account storage), [`backend/app/routes/portfolio.py`](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/routes/portfolio.py) (Portfolio endpoints), [`backend/app/services/zerodha_holdings.py`](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/zerodha_holdings.py) (Live holdings), [`backend/app/main.py`](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/main.py) (API application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and interface"]
  node_dashboard["Dashboard UI<br/>[index.html]"]
  node_app["API application<br/>[main.py]"]
  node_auth["Zerodha login<br/>[zerodha.py]"]
  node_sessions["Session lookup<br/>[sessions.py]"]
end

subgraph group_portfolio["Portfolio data"]
  node_portfolio_api["Portfolio endpoints<br/>[portfolio.py]"]
  node_holdings["Live holdings"]
  node_trade_sync["Trade sync<br/>[trade_sync.py]"]
  node_scheduler["Background scheduler<br/>[scheduler.py]"]
end

subgraph group_analysis["Analysis and context"]
  node_instruments["Instrument enrichment<br/>[instruments.py]"]
  node_sector_map["Sector mapping<br/>[sector_map.py]"]
  node_trades["Trade history<br/>[trades.py]"]
  node_delivery["Delivery analysis<br/>[delivery.py]"]
  node_comparative["Market comparison<br/>[comparative.py]"]
  node_performance["Performance evidence<br/>[performance.py]"]
  node_valuation["Holding normalization<br/>[valuation.py]"]
end

subgraph group_storage["Persistence"]
  node_db[("Account storage<br/>[db.py]")]
  node_remote_db[("Remote database adapter<br/>[remote_db.py]")]
end

node_investor(("Investor"))
node_broker{{"Zerodha Kite"}}
node_nse{{"NSE data"}}

node_investor -->|"uses"| node_dashboard
node_app -->|"serves"| node_dashboard
node_app -->|"registers"| node_auth
node_app -->|"registers"| node_portfolio_api
node_app -->|"starts"| node_scheduler
node_app -->|"checks sessions"| node_sessions
node_auth -->|"exchanges token"| node_broker
node_auth -->|"saves session"| node_db
node_auth -->|"starts sync"| node_trade_sync
node_portfolio_api -->|"fetches holdings"| node_holdings
node_portfolio_api -->|"enriches instruments"| node_instruments
node_portfolio_api -->|"computes history"| node_trades
node_portfolio_api -->|"fetches delivery"| node_delivery
node_portfolio_api -->|"gets comparison"| node_comparative
node_portfolio_api -->|"uses performance"| node_performance
node_portfolio_api -->|"reads portfolio data"| node_db
node_holdings -->|"fetches holdings"| node_broker
node_holdings -->|"saves snapshots"| node_db
node_holdings -->|"records observations"| node_performance
node_holdings -->|"normalizes holdings"| node_valuation
node_trade_sync -->|"fetches trades"| node_broker
node_trade_sync -->|"inserts trades"| node_db
node_scheduler -->|"runs sync"| node_trade_sync
node_scheduler -->|"reads sessions"| node_db
node_instruments -->|"stores instruments"| node_db
node_instruments -->|"looks up sectors"| node_sector_map
node_db -->|"enriches sectors"| node_sector_map
node_trades -->|"reads ledger"| node_db
node_trades -->|"uses valuation"| node_valuation
node_delivery -->|"reads cache"| node_db
node_delivery -->|"fetches history"| node_nse
node_comparative -->|"reads market data"| node_db
node_comparative -->|"uses holdings"| node_holdings
node_performance -->|"stores evidence"| node_db
node_performance -->|"normalizes holdings"| node_valuation
node_sessions -->|"looks up session"| node_db
node_db -->|"connects remotely"| node_remote_db

click node_dashboard "https://github.com/rammarthi9/tunefolio/blob/main/frontend/index.html"
click node_app "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/main.py"
click node_auth "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/auth/zerodha.py"
click node_portfolio_api "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/routes/portfolio.py"
click node_holdings "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/zerodha_holdings.py"
click node_trade_sync "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/trade_sync.py"
click node_scheduler "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/scheduler.py"
click node_instruments "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/instruments.py"
click node_sector_map "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/sector_map.py"
click node_trades "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/trades.py"
click node_delivery "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/delivery.py"
click node_comparative "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/comparative.py"
click node_performance "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/performance.py"
click node_valuation "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/valuation.py"
click node_sessions "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/sessions.py"
click node_db "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/db.py"
click node_remote_db "https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/remote_db.py"

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_dashboard,node_app,node_auth,node_sessions toneBlue
class node_portfolio_api,node_holdings,node_trade_sync,node_scheduler toneAmber
class node_instruments,node_sector_map,node_trades,node_delivery,node_comparative,node_performance,node_valuation toneMint
class node_db,node_remote_db toneRose
class node_investor,node_broker,node_nse toneIndigo
```

## Components

### Access and interface

- [Dashboard UI](https://github.com/rammarthi9/tunefolio/blob/main/frontend/index.html): `frontend/index.html`
- [API application](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/main.py): `backend/app/main.py`
- [Zerodha login](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/auth/zerodha.py): `backend/app/auth/zerodha.py`
- [Session lookup](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/sessions.py): `backend/app/services/sessions.py`

### Portfolio data

- [Portfolio endpoints](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/routes/portfolio.py): `backend/app/routes/portfolio.py`
- [Live holdings](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/zerodha_holdings.py): `backend/app/services/zerodha_holdings.py`
- [Trade sync](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/trade_sync.py): `backend/app/services/trade_sync.py`
- [Background scheduler](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/scheduler.py): `backend/app/services/scheduler.py`

### Analysis and context

- [Instrument enrichment](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/instruments.py): `backend/app/services/instruments.py`
- [Sector mapping](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/sector_map.py): `backend/app/services/sector_map.py`
- [Trade history](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/trades.py): `backend/app/services/trades.py`
- [Delivery analysis](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/delivery.py): `backend/app/services/delivery.py`
- [Market comparison](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/comparative.py): `backend/app/services/comparative.py`
- [Performance evidence](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/performance.py): `backend/app/services/performance.py`
- [Holding normalization](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/valuation.py): `backend/app/services/valuation.py`

### Persistence

- [Account storage](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/db.py): `backend/app/services/db.py`
- [Remote database adapter](https://github.com/rammarthi9/tunefolio/blob/main/backend/app/services/remote_db.py): `backend/app/services/remote_db.py`

### Other components

- **Investor**
- **Zerodha Kite**
- **NSE data**

## Connections

- Investor → Dashboard UI: uses (evidence: `README.md`)
- API application → Dashboard UI: serves (evidence: `backend/app/main.py`)
- API application → Zerodha login: registers (evidence: `backend/app/main.py`)
- API application → Portfolio endpoints: registers (evidence: `backend/app/main.py`)
- API application → Background scheduler: starts (evidence: `backend/app/main.py`)
- API application → Session lookup: checks sessions (evidence: `backend/app/main.py`)
- Zerodha login → Zerodha Kite: exchanges token (evidence: `backend/app/auth/zerodha.py`)
- Zerodha login → Account storage: saves session (evidence: `backend/app/auth/zerodha.py`)
- Zerodha login → Trade sync: starts sync (evidence: `backend/app/auth/zerodha.py`)
- Portfolio endpoints → Live holdings: fetches holdings (evidence: `backend/app/routes/portfolio.py`)
- Portfolio endpoints → Instrument enrichment: enriches instruments (evidence: `backend/app/routes/portfolio.py`)
- Portfolio endpoints → Trade history: computes history (evidence: `backend/app/routes/portfolio.py`)
- Portfolio endpoints → Delivery analysis: fetches delivery (evidence: `backend/app/routes/portfolio.py`)
- Portfolio endpoints → Market comparison: gets comparison (evidence: `backend/app/routes/portfolio.py`)
- Portfolio endpoints → Performance evidence: uses performance (evidence: `backend/app/routes/portfolio.py`)
- Portfolio endpoints → Account storage: reads portfolio data (evidence: `backend/app/routes/portfolio.py`)
- Live holdings → Zerodha Kite: fetches holdings (evidence: `backend/app/services/zerodha_holdings.py`)
- Live holdings → Account storage: saves snapshots (evidence: `backend/app/services/zerodha_holdings.py`)
- Live holdings → Performance evidence: records observations (evidence: `backend/app/services/zerodha_holdings.py`)
- Live holdings → Holding normalization: normalizes holdings (evidence: `backend/app/services/zerodha_holdings.py`)
- Trade sync → Zerodha Kite: fetches trades (evidence: `backend/app/services/trade_sync.py`)
- Trade sync → Account storage: inserts trades (evidence: `backend/app/services/trade_sync.py`)
- Background scheduler → Trade sync: runs sync (evidence: `backend/app/services/scheduler.py`)
- Background scheduler → Account storage: reads sessions (evidence: `backend/app/services/scheduler.py`)
- Instrument enrichment → Account storage: stores instruments (evidence: `backend/app/services/instruments.py`)
- Instrument enrichment → Sector mapping: looks up sectors (evidence: `backend/app/services/instruments.py`)
- Account storage → Sector mapping: enriches sectors (evidence: `backend/app/services/db.py`)
- Trade history → Account storage: reads ledger (evidence: `backend/app/services/trades.py`)
- Trade history → Holding normalization: uses valuation (evidence: `backend/app/services/trades.py`)
- Delivery analysis → Account storage: reads cache (evidence: `backend/app/services/delivery.py`)
- Delivery analysis → NSE data: fetches history (evidence: `backend/app/services/delivery.py`)
- Market comparison → Account storage: reads market data (evidence: `backend/app/services/comparative.py`)
- Market comparison → Live holdings: uses holdings (evidence: `backend/app/services/comparative.py`)
- Performance evidence → Account storage: stores evidence (evidence: `backend/app/services/performance.py`)
- Performance evidence → Holding normalization: normalizes holdings (evidence: `backend/app/services/performance.py`)
- Session lookup → Account storage: looks up session (evidence: `backend/app/services/sessions.py`)
- Account storage → Remote database adapter: connects remotely (evidence: `backend/app/services/db.py`)
