# balenoanurag/fyers-cas-paper-trader architecture

> Architecture diagram of the GitHub repository balenoanurag/fyers-cas-paper-trader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/balenoanurag/fyers-cas-paper-trader
- Repository: https://github.com/balenoanurag/fyers-cas-paper-trader

## Overview

This is a mobile PWA for discovering FYERS options and monitoring a paper strategy around 3:20. The documented workflow is: authenticate, discover and select contracts, receive live ticks, persist them, then let a persistent worker evaluate the reference-based strategy and expose status to the UI. The README explicitly says there is no order-placement endpoint. The excerpts are partial, so internal server components are separated by responsibility; uncertain implementation details are omitted.

Main entry points: [`index.html`](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/index.html) (PWA interface), [`server.py`](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py) (FastAPI app), [`manifest.webmanifest`](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/manifest.webmanifest) (PWA manifest), [`sw.js`](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/sw.js) (Service worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Mobile interface"]
  node_ui["PWA interface<br/>[index.html]"]
  node_manifest["PWA manifest"]
  node_sw["Service worker<br/>[sw.js]"]
end

subgraph group_market["Market data"]
  node_api["FastAPI app<br/>[server.py]"]
  node_auth["FYERS authentication<br/>[server.py]"]
  node_discovery["Option discovery<br/>[server.py]"]
  node_selection["Contract selection<br/>[server.py]"]
  node_stream["WebSocket feed<br/>[server.py]"]
  node_ticks["Tick handling<br/>[server.py]"]
end

subgraph group_strategy["Paper strategy"]
  node_worker["Strategy worker<br/>[server.py]"]
  node_reference["Reference strategy<br/>[server.py]"]
  node_paper["Paper execution<br/>[server.py]"]
end

subgraph group_storage["Persistent state"]
  node_db[("Tick database<br/>[server.py]")]
end

node_user(("Phone user"))
node_fyers{{"FYERS services"}}

node_user -->|"opens"| node_ui
node_ui -->|"API requests"| node_api
node_ui -->|"loads"| node_manifest
node_ui -->|"registers"| node_sw
node_api -->|"handles login"| node_auth
node_auth -->|"authenticates"| node_fyers
node_api -->|"discovers contracts"| node_discovery
node_discovery -->|"requests chain"| node_fyers
node_discovery -->|"provides chain"| node_selection
node_selection -->|"subscribes contracts"| node_stream
node_fyers -->|"streams ticks"| node_stream
node_stream -->|"delivers messages"| node_ticks
node_ticks -->|"persists ticks"| node_db
node_worker -->|"reads ticks"| node_db
node_worker -->|"evaluates strategy"| node_reference
node_reference -->|"records simulation"| node_paper
node_ui -->|"reads status"| node_api

click node_ui "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/index.html"
click node_manifest "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/manifest.webmanifest"
click node_sw "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/sw.js"
click node_api "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py"
click node_auth "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py"
click node_discovery "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py"
click node_selection "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py"
click node_stream "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py"
click node_ticks "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py"
click node_worker "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py"
click node_reference "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py"
click node_paper "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py"
click node_db "https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.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_ui,node_manifest,node_sw,node_user toneBlue
class node_api,node_auth,node_discovery,node_selection,node_stream,node_ticks toneAmber
class node_worker,node_reference,node_paper toneMint
class node_db toneRose
class node_fyers toneIndigo
```

## Components

### Mobile interface

- [PWA interface](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/index.html): `index.html`
- [PWA manifest](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/manifest.webmanifest): `manifest.webmanifest`
- [Service worker](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/sw.js): `sw.js`

### Market data

- [FastAPI app](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py): `server.py`
- [FYERS authentication](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py): `server.py`
- [Option discovery](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py): `server.py`
- [Contract selection](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py): `server.py`
- [WebSocket feed](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py): `server.py`
- [Tick handling](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py): `server.py`

### Paper strategy

- [Strategy worker](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py): `server.py`
- [Reference strategy](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py): `server.py`
- [Paper execution](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py): `server.py`

### Persistent state

- [Tick database](https://github.com/balenoanurag/fyers-cas-paper-trader/blob/main/server.py): `server.py`

### Other components

- **Phone user**
- **FYERS services**

## Connections

- Phone user → PWA interface: opens
- PWA interface → FastAPI app: API requests
- PWA interface → PWA manifest: loads
- PWA interface → Service worker: registers
- FastAPI app → FYERS authentication: handles login
- FYERS authentication → FYERS services: authenticates
- FastAPI app → Option discovery: discovers contracts
- Option discovery → FYERS services: requests chain
- Option discovery → Contract selection: provides chain
- Contract selection → WebSocket feed: subscribes contracts
- FYERS services → WebSocket feed: streams ticks
- WebSocket feed → Tick handling: delivers messages
- Tick handling → Tick database: persists ticks
- Strategy worker → Tick database: reads ticks
- Strategy worker → Reference strategy: evaluates strategy
- Reference strategy → Paper execution: records simulation
- PWA interface → FastAPI app: reads status
