# flash0x45/portfolio-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/flash0x45/portfolio-tracker
- Repository: https://github.com/flash0x45/portfolio-tracker

## Overview

This repository is a small Python application for tracking a mutual fund portfolio in real time during Indian market hours. The architecture is a pipeline: load configuration, check whether NSE is open, fetch scheme holdings, map them to tradable NSE symbols, fetch live prices, and compute portfolio-level returns.

The main runtime entry point appears to be `app.py`. It likely wires the subsystems together and starts the tracking loop. The README mentions `main.py` and a Streamlit app, but those files are not present in the tree, so the codebase shown here looks centered around the `app.py`/`agents` modules instead.

`config.py` is the configuration boundary. It holds environment-specific settings such as the fund slug, poll interval, and NSE holiday list. This is the main place where runtime behavior is tuned without changing the core logic.

The `agents/market_clock.py` module is the market-gating subsystem. Its job is to decide whether the tracker should run now, based on Indian market hours and holidays. This is important because it prevents unnecessary polling when NSE is closed and likely controls whether the app exits, sleeps, or waits.

`agents/portfolio_builder.py` is the portfolio ingestion and normalization step. It fetches the holdings for a Groww mutual fund scheme and resolves underlying equity holdings into NSE symbols. Architecturally, this is where the fund-specific source data is transformed into a portfolio the rest of the system can price.

`agents/price_fetcher.py` is the market-data adapter. It is responsible for retrieving current live prices for the resolved NSE symbols. This module forms the external data boundary to whatever quote source is being used.

`agents/return_calculator.py` is the valuation engine. It takes holdings plus live prices and computes current value, gains/losses, and other return metrics. This is the core computation layer and should be treated as pure business logic if possible.

`agents/orchestrator.py` is the control plane for the system. It likely coordinates the full refresh cycle: check market status, build the portfolio snapshot, fetch prices, calculate returns, and repeat at the configured polling interval. If you are drawing the architecture, this is the central node connecting all other agents.

The `agents` package is the main functional boundary in the codebase. Each module has a narrow responsibility, which suggests a layered design: market gating, portfolio normalization, price retrieval, and valuation. There is no evidence in the tree of persistence, message queues, or a separate backend service.

Data flow is mostly one-directional and in-memory:
config and market-calendar data go into the market clock;
fund holdings come from Groww into the portfolio builder;
resolved symbols go to the price fetcher;
prices and holdings feed the return calculator;
the orchestrator aggregates and repeats the cycle.

The likely external dependencies that materially affect the architecture are:
Groww or a similar source for mutual fund holdings,
an NSE quote source for live prices,
and the NSE trading calendar/holiday schedule for run-time gating.
These are the only external system boundaries implied by the file names and README.

There is also a presentation concern hinted at by the README’s Streamlit reference, but that UI file is not in the tree. Based on the repository contents shown, the core application is the tracking engine itself rather than a full web service or database-backed system.

Main entry points: [`agents/orchestrator.py`](https://github.com/flash0x45/portfolio-tracker/blob/main/agents/orchestrator.py) (Orchestrator), [`config.py`](https://github.com/flash0x45/portfolio-tracker/blob/main/config.py) (Config), [`agents/portfolio_builder.py`](https://github.com/flash0x45/portfolio-tracker/blob/main/agents/portfolio_builder.py) (Portfolio builder), [`agents/market_clock.py`](https://github.com/flash0x45/portfolio-tracker/blob/main/agents/market_clock.py) (Market clock)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core app"]
  node_app["App<br/>entrypoint<br/>[app.py]"]
  node_config["Config<br/>settings<br/>[config.py]"]
end

subgraph group_agents["Agents"]
  node_orchestrator["Orchestrator<br/>control plane<br/>[orchestrator.py]"]
  node_market_clock(("Market clock<br/>market gate<br/>[market_clock.py]"))
  node_portfolio_builder["Portfolio builder<br/>holdings mapper"]
  node_price_fetcher[("Price fetcher<br/>market data<br/>[price_fetcher.py]")]
  node_return_calculator{{"Return calc<br/>valuation engine"}}
end

node_app -->|"loads"| node_config
node_app -->|"starts"| node_orchestrator
node_orchestrator -->|"checks"| node_market_clock
node_orchestrator -->|"builds"| node_portfolio_builder
node_portfolio_builder -->|"resolves symbols"| node_price_fetcher
node_price_fetcher -->|"prices"| node_return_calculator
node_portfolio_builder -->|"holdings"| node_return_calculator
node_return_calculator -->|"results"| node_orchestrator
node_config -->|"holidays"| node_market_clock
node_config -->|"intervals"| node_orchestrator
node_market_clock -->|"allow/deny"| node_orchestrator

click node_app "https://github.com/flash0x45/portfolio-tracker/blob/main/app.py"
click node_config "https://github.com/flash0x45/portfolio-tracker/blob/main/config.py"
click node_orchestrator "https://github.com/flash0x45/portfolio-tracker/blob/main/agents/orchestrator.py"
click node_market_clock "https://github.com/flash0x45/portfolio-tracker/blob/main/agents/market_clock.py"
click node_portfolio_builder "https://github.com/flash0x45/portfolio-tracker/blob/main/agents/portfolio_builder.py"
click node_price_fetcher "https://github.com/flash0x45/portfolio-tracker/blob/main/agents/price_fetcher.py"
click node_return_calculator "https://github.com/flash0x45/portfolio-tracker/blob/main/agents/return_calculator.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_app,node_config toneBlue
class node_orchestrator,node_market_clock,node_portfolio_builder,node_price_fetcher,node_return_calculator toneAmber
```

## Components

### Core app

Runtime entrypoint and configuration boundary.

- [App](https://github.com/flash0x45/portfolio-tracker/blob/main/app.py): entrypoint · Main runtime wiring and loop start. · `app.py`
- [Config](https://github.com/flash0x45/portfolio-tracker/blob/main/config.py): settings · Runtime settings like fund slug, polling, and holidays. · `config.py`

### Agents

Pipeline components that gate, build, price, and value the portfolio.

- [Orchestrator](https://github.com/flash0x45/portfolio-tracker/blob/main/agents/orchestrator.py): control plane · Coordinates the refresh cycle and repeats it. · `agents/orchestrator.py`
- [Market clock](https://github.com/flash0x45/portfolio-tracker/blob/main/agents/market_clock.py): market gate · Checks NSE hours and holiday status. · `agents/market_clock.py`
- [Portfolio builder](https://github.com/flash0x45/portfolio-tracker/blob/main/agents/portfolio_builder.py): holdings mapper · Fetches scheme holdings and resolves tradable NSE symbols. · `agents/portfolio_builder.py`
- [Price fetcher](https://github.com/flash0x45/portfolio-tracker/blob/main/agents/price_fetcher.py): market data · Retrieves live prices for resolved symbols. · `agents/price_fetcher.py`
- [Return calc](https://github.com/flash0x45/portfolio-tracker/blob/main/agents/return_calculator.py): valuation engine · Computes value, gains, losses, and returns. · `agents/return_calculator.py`

## Connections

- App → Config: loads · Reads runtime configuration at startup.
- App → Orchestrator: starts · Hands off execution to the coordinator.
- Orchestrator → Market clock: checks · Decides whether tracking should run now.
- Orchestrator → Portfolio builder: builds · Fetches and normalizes scheme holdings.
- Portfolio builder → Price fetcher: resolves symbols · Passes tradable NSE symbols for pricing.
- Price fetcher → Return calc: prices · Provides live market data for valuation.
- Portfolio builder → Return calc: holdings · Supplies quantities and cost basis.
- Return calc → Orchestrator: results · Returns portfolio metrics for the cycle.
- Config → Market clock: holidays · Provides market calendar and polling behavior.
- Config → Orchestrator: intervals · Controls refresh cadence and fund selection.
- Market clock → Orchestrator: allow/deny · Gates whether the refresh loop proceeds.
