# krishna5166/project-2216 architecture

> Architecture diagram of the GitHub repository krishna5166/project-2216, 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/krishna5166/project-2216
- Repository: https://github.com/krishna5166/project-2216
- Video tour (about a minute): https://gitdiagram.com/krishna5166/project-2216/video

## Overview

Project-2216 is a command-line algorithmic trading bot with paper-trading and credential-free simulation modes. The live path streams prices into a bot loop that records ticks, updates risk and decision engines, combines their votes, applies a final risk gate, then opens or closes positions through the selected execution layer. Separate workflows fetch historical prices, replay recorded or CSV prices through the same bot logic, compute performance metrics, and train an optional analytical model. The graph follows documented capabilities; unsampled module internals and unwired external-signal refreshers are not inferred.

Main entry points: [`algotrader/bot.py`](https://github.com/krishna5166/project-2216/blob/main/algotrader/bot.py) (Trading bot), [`algotrader/train.py`](https://github.com/krishna5166/project-2216/blob/main/algotrader/train.py) (Model training), [`algotrader/backtest.py`](https://github.com/krishna5166/project-2216/blob/main/algotrader/backtest.py) (Backtester), [`algotrader/recorder.py`](https://github.com/krishna5166/project-2216/blob/main/algotrader/recorder.py) (Tick recorder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and configuration"]
  node_main["CLI entry<br/>[main.py]"]
  node_config["Configuration<br/>[config.py]"]
end

subgraph group_live["Live trading loop"]
  node_bot["Trading bot<br/>[bot.py]"]
  node_recorder["Tick recorder<br/>[recorder.py]"]
end

subgraph group_signals["Decision and risk"]
  node_strategy["SMA strategy<br/>[strategy.py]"]
  node_analytics["Analytical engine<br/>[analytics.py]"]
  node_models["Prediction models<br/>[models.py]"]
  node_features["Feature extraction<br/>[features.py]"]
  node_meta["Vote controller<br/>[meta_controller.py]"]
  node_external["Signal cache"]
  node_risk["Volatility sizing<br/>[risk.py]"]
  node_gate["Risk gate<br/>[risk_gate.py]"]
end

subgraph group_io["Market and execution I/O"]
  node_live_feed["Live data feed<br/>[data_feed.py]"]
  node_live_exec["Live execution<br/>[execution.py]"]
  node_sim["Simulation layers<br/>[simulation.py]"]
end

subgraph group_research["Replay and model research"]
  node_history["Historical fetcher<br/>[historical.py]"]
  node_backtest["Backtester<br/>[backtest.py]"]
  node_metrics["Performance metrics<br/>[metrics.py]"]
  node_train["Model training<br/>[train.py]"]
end

node_operator(("Operator"))
node_alpaca_feed(("Alpaca market stream"))
node_alpaca_trade(("Alpaca trading API"))
node_csv["Price CSV"]
node_jsonl["Recorded ticks"]
node_model_file["Trained model file"]

node_operator -->|"runs"| node_main
node_main -->|"starts"| node_bot
node_bot -->|"loads settings"| node_config
node_bot -->|"updates"| node_strategy
node_bot -->|"updates"| node_analytics
node_bot -->|"reads signal"| node_external
node_bot -->|"combines votes"| node_meta
node_bot -->|"sizes position"| node_risk
node_bot -->|"checks order"| node_gate
node_bot -->|"records ticks"| node_recorder
node_bot -->|"consumes prices"| node_live_feed
node_live_feed -->|"streams prices"| node_alpaca_feed
node_bot -->|"submits orders"| node_live_exec
node_live_exec -->|"calls API"| node_alpaca_trade
node_bot -.->|"selects in dry run"| node_sim
node_sim -.->|"provides prices and orders"| node_bot
node_history -->|"fetches bars"| node_alpaca_feed
node_history -->|"writes prices"| node_csv
node_backtest -->|"reads prices"| node_csv
node_backtest -->|"loads recorded ticks"| node_jsonl
node_backtest -->|"loads ticks"| node_recorder
node_backtest -->|"replays prices"| node_bot
node_backtest -->|"computes results"| node_metrics
node_recorder -->|"appends ticks"| node_jsonl
node_train -->|"reads prices"| node_csv
node_train -->|"loads recorded ticks"| node_jsonl
node_train -->|"loads ticks"| node_recorder
node_train -->|"extracts features"| node_features
node_train -->|"trains model"| node_models
node_train -->|"saves model"| node_model_file
node_bot -.->|"loads configured model"| node_model_file
node_train -.->|"evaluates holdout"| node_backtest
node_external -.->|"awaits future provider"| node_operator

click node_main "https://github.com/krishna5166/project-2216/blob/main/main.py"
click node_config "https://github.com/krishna5166/project-2216/blob/main/algotrader/config.py"
click node_bot "https://github.com/krishna5166/project-2216/blob/main/algotrader/bot.py"
click node_recorder "https://github.com/krishna5166/project-2216/blob/main/algotrader/recorder.py"
click node_strategy "https://github.com/krishna5166/project-2216/blob/main/algotrader/strategy.py"
click node_analytics "https://github.com/krishna5166/project-2216/blob/main/algotrader/analytics.py"
click node_models "https://github.com/krishna5166/project-2216/blob/main/algotrader/models.py"
click node_features "https://github.com/krishna5166/project-2216/blob/main/algotrader/features.py"
click node_meta "https://github.com/krishna5166/project-2216/blob/main/algotrader/meta_controller.py"
click node_external "https://github.com/krishna5166/project-2216/blob/main/algotrader/external_signals.py"
click node_risk "https://github.com/krishna5166/project-2216/blob/main/algotrader/risk.py"
click node_gate "https://github.com/krishna5166/project-2216/blob/main/algotrader/risk_gate.py"
click node_live_feed "https://github.com/krishna5166/project-2216/blob/main/algotrader/data_feed.py"
click node_live_exec "https://github.com/krishna5166/project-2216/blob/main/algotrader/execution.py"
click node_sim "https://github.com/krishna5166/project-2216/blob/main/algotrader/simulation.py"
click node_history "https://github.com/krishna5166/project-2216/blob/main/algotrader/historical.py"
click node_backtest "https://github.com/krishna5166/project-2216/blob/main/algotrader/backtest.py"
click node_metrics "https://github.com/krishna5166/project-2216/blob/main/algotrader/metrics.py"
click node_train "https://github.com/krishna5166/project-2216/blob/main/algotrader/train.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_main,node_config toneBlue
class node_bot,node_recorder toneAmber
class node_strategy,node_analytics,node_models,node_features,node_meta,node_external,node_risk,node_gate,node_alpaca_trade toneMint
class node_live_feed,node_live_exec,node_sim toneRose
class node_history,node_backtest,node_metrics,node_train,node_operator,node_alpaca_feed,node_csv,node_jsonl,node_model_file toneIndigo
```

## Components

### CLI and configuration

- [CLI entry](https://github.com/krishna5166/project-2216/blob/main/main.py): `main.py`
- [Configuration](https://github.com/krishna5166/project-2216/blob/main/algotrader/config.py): `algotrader/config.py`

### Live trading loop

- [Trading bot](https://github.com/krishna5166/project-2216/blob/main/algotrader/bot.py): `algotrader/bot.py`
- [Tick recorder](https://github.com/krishna5166/project-2216/blob/main/algotrader/recorder.py): `algotrader/recorder.py`

### Decision and risk

- [SMA strategy](https://github.com/krishna5166/project-2216/blob/main/algotrader/strategy.py): `algotrader/strategy.py`
- [Analytical engine](https://github.com/krishna5166/project-2216/blob/main/algotrader/analytics.py): `algotrader/analytics.py`
- [Prediction models](https://github.com/krishna5166/project-2216/blob/main/algotrader/models.py): `algotrader/models.py`
- [Feature extraction](https://github.com/krishna5166/project-2216/blob/main/algotrader/features.py): `algotrader/features.py`
- [Vote controller](https://github.com/krishna5166/project-2216/blob/main/algotrader/meta_controller.py): `algotrader/meta_controller.py`
- [Signal cache](https://github.com/krishna5166/project-2216/blob/main/algotrader/external_signals.py): `algotrader/external_signals.py`
- [Volatility sizing](https://github.com/krishna5166/project-2216/blob/main/algotrader/risk.py): `algotrader/risk.py`
- [Risk gate](https://github.com/krishna5166/project-2216/blob/main/algotrader/risk_gate.py): `algotrader/risk_gate.py`

### Market and execution I/O

- [Live data feed](https://github.com/krishna5166/project-2216/blob/main/algotrader/data_feed.py): `algotrader/data_feed.py`
- [Live execution](https://github.com/krishna5166/project-2216/blob/main/algotrader/execution.py): `algotrader/execution.py`
- [Simulation layers](https://github.com/krishna5166/project-2216/blob/main/algotrader/simulation.py): `algotrader/simulation.py`

### Replay and model research

- [Historical fetcher](https://github.com/krishna5166/project-2216/blob/main/algotrader/historical.py): `algotrader/historical.py`
- [Backtester](https://github.com/krishna5166/project-2216/blob/main/algotrader/backtest.py): `algotrader/backtest.py`
- [Performance metrics](https://github.com/krishna5166/project-2216/blob/main/algotrader/metrics.py): `algotrader/metrics.py`
- [Model training](https://github.com/krishna5166/project-2216/blob/main/algotrader/train.py): `algotrader/train.py`

### Other components

- **Operator**
- **Alpaca market stream**
- **Alpaca trading API**
- **Price CSV**
- **Recorded ticks**
- **Trained model file**

## Connections

- Operator → CLI entry: runs
- CLI entry → Trading bot: starts
- Trading bot → Configuration: loads settings
- Trading bot → SMA strategy: updates
- Trading bot → Analytical engine: updates
- Trading bot → Signal cache: reads signal
- Trading bot → Vote controller: combines votes
- Trading bot → Volatility sizing: sizes position
- Trading bot → Risk gate: checks order
- Trading bot → Tick recorder: records ticks
- Trading bot → Live data feed: consumes prices
- Live data feed → Alpaca market stream: streams prices
- Trading bot → Live execution: submits orders
- Live execution → Alpaca trading API: calls API
- Trading bot → Simulation layers: selects in dry run
- Simulation layers → Trading bot: provides prices and orders
- Historical fetcher → Alpaca market stream: fetches bars
- Historical fetcher → Price CSV: writes prices
- Backtester → Price CSV: reads prices
- Backtester → Recorded ticks: loads recorded ticks
- Backtester → Tick recorder: loads ticks
- Backtester → Trading bot: replays prices
- Backtester → Performance metrics: computes results
- Tick recorder → Recorded ticks: appends ticks
- Model training → Price CSV: reads prices
- Model training → Recorded ticks: loads recorded ticks
- Model training → Tick recorder: loads ticks
- Model training → Feature extraction: extracts features
- Model training → Prediction models: trains model
- Model training → Trained model file: saves model
- Trading bot → Trained model file: loads configured model
- Model training → Backtester: evaluates holdout
- Signal cache → Operator: awaits future provider
