# mrchartist/fii-dii-data architecture

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

- Interactive diagram: https://gitdiagram.com/mrchartist/fii-dii-data
- Repository: https://github.com/mrchartist/fii-dii-data

## Overview

This is a live FII/DII institutional-flow dashboard and alerting service. Market data is fetched and persisted, served through Express APIs to a browser dashboard, and analyzed by scheduled agents whose findings can be sent through Telegram. The README documents the dashboard’s analytics, sector and derivatives views, exports, and PWA support. Some UI and server implementation is only partially sampled; edges below are limited to README statements or visible references and calls. Supabase is documented as prepared but not connected.

Main entry points: [`server.js`](https://github.com/mrchartist/fii-dii-data/blob/main/server.js) (Express API and scheduler), [`public/js/os27-ui.js`](https://github.com/mrchartist/fii-dii-data/blob/main/public/js/os27-ui.js) (Dashboard interface), [`agents/agent-utils.js`](https://github.com/mrchartist/fii-dii-data/blob/main/agents/agent-utils.js) (Agent data and state), [`telegram.js`](https://github.com/mrchartist/fii-dii-data/blob/main/telegram.js) (Telegram delivery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Data ingestion"]
  node_fetch["NSE flow fetcher<br/>[fetch_data.js]"]
  node_sectorfetch["NSDL sector fetcher<br/>[fetch_nsdl.js]"]
end

subgraph group_service["API and persistence"]
  node_server["Express API and scheduler<br/>[server.js]"]
  node_json[("Local JSON data<br/>[fetch_data.js]")]
  node_supabase[("Optional Supabase store<br/>[client.js]")]
  node_guard["API security guard<br/>[api-guard.js]"]
end

subgraph group_dashboard["Dashboard"]
  node_charts["Flow charts<br/>[os27-charts.js]"]
  node_ui["Dashboard interface<br/>[os27-ui.js]"]
  node_ranges["Date ranges<br/>[os27-ranges.js]"]
  node_deals["Deals view<br/>[os27-deals.js]"]
  node_serviceworker["Offline support<br/>[sw.js]"]
end

subgraph group_intelligence["Flow intelligence"]
  node_runner["Agent runner<br/>[agent-runner.js]"]
  node_utils["Agent data and state<br/>[agent-utils.js]"]
  node_streak["FII streak analysis"]
  node_divergence["Flow divergence<br/>[flow-divergence.js]"]
  node_regime["Market regime"]
  node_weekly["Weekly digest<br/>[weekly-digest.js]"]
end

subgraph group_alerts["Alerts"]
  node_telegram["Telegram delivery<br/>[telegram.js]"]
  node_messages["Alert messages"]
  node_health["Delivery watchdog<br/>[telegram-health.js]"]
end

node_nse(("NSE market data"))
node_nsdl(("NSDL FPI data"))
node_telegramservice(("Telegram service"))
node_browser(("Dashboard visitor"))

node_nse -->|"provides data"| node_fetch
node_fetch -->|"writes flows"| node_json
node_nsdl -->|"provides data"| node_sectorfetch
node_sectorfetch -->|"writes sectors"| node_json
node_server -->|"runs fetcher"| node_fetch
node_server -->|"reads data"| node_json
node_server -->|"uses guard"| node_guard
node_browser -->|"requests API"| node_server
node_server -->|"serves dashboard"| node_ui
node_ui -.->|"renders charts"| node_charts
node_ui -.->|"filters dates"| node_ranges
node_ui -.->|"shows deals"| node_deals
node_ui -->|"supports offline"| node_serviceworker
node_server -->|"runs agents"| node_runner
node_runner -->|"uses utilities"| node_utils
node_streak -->|"reads history and state"| node_utils
node_divergence -->|"reads history and state"| node_utils
node_regime -->|"reads history and state"| node_utils
node_weekly -->|"reads history and state"| node_utils
node_regime -.->|"sends alerts"| node_telegram
node_telegram -->|"formats alerts"| node_messages
node_telegram -->|"tracks delivery"| node_health
node_health -->|"checks delivery"| node_telegramservice
node_telegram -->|"sends messages"| node_telegramservice
node_supabase -.->|"migration source"| node_json

click node_fetch "https://github.com/mrchartist/fii-dii-data/blob/main/scripts/fetch_data.js"
click node_sectorfetch "https://github.com/mrchartist/fii-dii-data/blob/main/scripts/fetch_nsdl.js"
click node_server "https://github.com/mrchartist/fii-dii-data/blob/main/server.js"
click node_json "https://github.com/mrchartist/fii-dii-data/blob/main/scripts/fetch_data.js"
click node_supabase "https://github.com/mrchartist/fii-dii-data/blob/main/supabase/client.js"
click node_guard "https://github.com/mrchartist/fii-dii-data/blob/main/api-guard.js"
click node_charts "https://github.com/mrchartist/fii-dii-data/blob/main/public/js/os27-charts.js"
click node_ui "https://github.com/mrchartist/fii-dii-data/blob/main/public/js/os27-ui.js"
click node_ranges "https://github.com/mrchartist/fii-dii-data/blob/main/public/js/os27-ranges.js"
click node_deals "https://github.com/mrchartist/fii-dii-data/blob/main/public/js/os27-deals.js"
click node_serviceworker "https://github.com/mrchartist/fii-dii-data/blob/main/public/sw.js"
click node_runner "https://github.com/mrchartist/fii-dii-data/blob/main/agent-runner.js"
click node_utils "https://github.com/mrchartist/fii-dii-data/blob/main/agents/agent-utils.js"
click node_streak "https://github.com/mrchartist/fii-dii-data/blob/main/agents/fii-streak-agent.js"
click node_divergence "https://github.com/mrchartist/fii-dii-data/blob/main/agents/flow-divergence.js"
click node_regime "https://github.com/mrchartist/fii-dii-data/blob/main/agents/regime-classifier.js"
click node_weekly "https://github.com/mrchartist/fii-dii-data/blob/main/agents/weekly-digest.js"
click node_telegram "https://github.com/mrchartist/fii-dii-data/blob/main/telegram.js"
click node_messages "https://github.com/mrchartist/fii-dii-data/blob/main/telegram-messages.js"
click node_health "https://github.com/mrchartist/fii-dii-data/blob/main/telegram-health.js"

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_fetch,node_sectorfetch toneBlue
class node_server,node_json,node_supabase,node_guard toneAmber
class node_charts,node_ui,node_ranges,node_deals,node_serviceworker toneMint
class node_runner,node_utils,node_streak,node_divergence,node_regime,node_weekly toneRose
class node_telegram,node_messages,node_health,node_nse,node_nsdl,node_telegramservice,node_browser toneIndigo
```

## Components

### Data ingestion

- [NSE flow fetcher](https://github.com/mrchartist/fii-dii-data/blob/main/scripts/fetch_data.js): `scripts/fetch_data.js`
- [NSDL sector fetcher](https://github.com/mrchartist/fii-dii-data/blob/main/scripts/fetch_nsdl.js): `scripts/fetch_nsdl.js`

### API and persistence

- [Express API and scheduler](https://github.com/mrchartist/fii-dii-data/blob/main/server.js): `server.js`
- [Local JSON data](https://github.com/mrchartist/fii-dii-data/blob/main/scripts/fetch_data.js): `scripts/fetch_data.js`
- [Optional Supabase store](https://github.com/mrchartist/fii-dii-data/blob/main/supabase/client.js): `supabase/client.js`
- [API security guard](https://github.com/mrchartist/fii-dii-data/blob/main/api-guard.js): `api-guard.js`

### Dashboard

- [Flow charts](https://github.com/mrchartist/fii-dii-data/blob/main/public/js/os27-charts.js): `public/js/os27-charts.js`
- [Dashboard interface](https://github.com/mrchartist/fii-dii-data/blob/main/public/js/os27-ui.js): `public/js/os27-ui.js`
- [Date ranges](https://github.com/mrchartist/fii-dii-data/blob/main/public/js/os27-ranges.js): `public/js/os27-ranges.js`
- [Deals view](https://github.com/mrchartist/fii-dii-data/blob/main/public/js/os27-deals.js): `public/js/os27-deals.js`
- [Offline support](https://github.com/mrchartist/fii-dii-data/blob/main/public/sw.js): `public/sw.js`

### Flow intelligence

- [Agent runner](https://github.com/mrchartist/fii-dii-data/blob/main/agent-runner.js): `agent-runner.js`
- [Agent data and state](https://github.com/mrchartist/fii-dii-data/blob/main/agents/agent-utils.js): `agents/agent-utils.js`
- [FII streak analysis](https://github.com/mrchartist/fii-dii-data/blob/main/agents/fii-streak-agent.js): `agents/fii-streak-agent.js`
- [Flow divergence](https://github.com/mrchartist/fii-dii-data/blob/main/agents/flow-divergence.js): `agents/flow-divergence.js`
- [Market regime](https://github.com/mrchartist/fii-dii-data/blob/main/agents/regime-classifier.js): `agents/regime-classifier.js`
- [Weekly digest](https://github.com/mrchartist/fii-dii-data/blob/main/agents/weekly-digest.js): `agents/weekly-digest.js`

### Alerts

- [Telegram delivery](https://github.com/mrchartist/fii-dii-data/blob/main/telegram.js): `telegram.js`
- [Alert messages](https://github.com/mrchartist/fii-dii-data/blob/main/telegram-messages.js): `telegram-messages.js`
- [Delivery watchdog](https://github.com/mrchartist/fii-dii-data/blob/main/telegram-health.js): `telegram-health.js`

### Other components

- **NSE market data**
- **NSDL FPI data**
- **Telegram service**
- **Dashboard visitor**

## Connections

- NSE market data → NSE flow fetcher: provides data (evidence: `README.md`)
- NSE flow fetcher → Local JSON data: writes flows (evidence: `README.md`)
- NSDL FPI data → NSDL sector fetcher: provides data (evidence: `scripts/fetch_nsdl.js`)
- NSDL sector fetcher → Local JSON data: writes sectors (evidence: `scripts/fetch_nsdl.js`)
- Express API and scheduler → NSE flow fetcher: runs fetcher (evidence: `server.js`)
- Express API and scheduler → Local JSON data: reads data (evidence: `README.md`)
- Express API and scheduler → API security guard: uses guard (evidence: `server.js`)
- Dashboard visitor → Express API and scheduler: requests API (evidence: `README.md`)
- Express API and scheduler → Dashboard interface: serves dashboard (evidence: `README.md`)
- Dashboard interface → Flow charts: renders charts
- Dashboard interface → Date ranges: filters dates
- Dashboard interface → Deals view: shows deals
- Dashboard interface → Offline support: supports offline (evidence: `README.md`)
- Express API and scheduler → Agent runner: runs agents (evidence: `server.js`)
- Agent runner → Agent data and state: uses utilities (evidence: `agent-runner.js`)
- FII streak analysis → Agent data and state: reads history and state (evidence: `agents/fii-streak-agent.js`)
- Flow divergence → Agent data and state: reads history and state (evidence: `agents/flow-divergence.js`)
- Market regime → Agent data and state: reads history and state (evidence: `agents/regime-classifier.js`)
- Weekly digest → Agent data and state: reads history and state (evidence: `agents/weekly-digest.js`)
- Market regime → Telegram delivery: sends alerts
- Telegram delivery → Alert messages: formats alerts (evidence: `telegram.js`)
- Telegram delivery → Delivery watchdog: tracks delivery (evidence: `telegram.js`)
- Delivery watchdog → Telegram service: checks delivery (evidence: `telegram-health.js`)
- Telegram delivery → Telegram service: sends messages (evidence: `telegram.js`)
- Optional Supabase store → Local JSON data: migration source
