# ed-donner/finally architecture

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

- Interactive diagram: https://gitdiagram.com/ed-donner/finally
- Repository: https://github.com/ed-donner/finally

## Overview

FinAlly is an AI trading workstation. Its market-data workflow selects a provider, updates a shared price cache, and exposes changed prices through SSE; the documented product also includes portfolio views, watchlists, simulated trading, and AI-assisted trade execution. The supplied tree and excerpts cover the market-data subsystem, not the application routes or the other feature implementations, so those capabilities are represented only at the documented subsystem level.

Main entry points: [`backend/app/market/cache.py`](https://github.com/ed-donner/finally/blob/main/backend/app/market/cache.py) (Price Cache), [`backend/app/market/simulator.py`](https://github.com/ed-donner/finally/blob/main/backend/app/market/simulator.py) (GBM Simulator), [`backend/app/market/massive_client.py`](https://github.com/ed-donner/finally/blob/main/backend/app/market/massive_client.py) (Massive Client), [`backend/app`](https://github.com/ed-donner/finally/tree/main/backend/app) (AI Chat Assistant)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_market["Market Data"]
  node_source_factory["Source Selector<br/>[factory.py]"]
  node_source_contract["Provider Contract<br/>[interface.py]"]
  node_simulator["GBM Simulator<br/>[simulator.py]"]
  node_seed_prices["Seed Parameters<br/>[seed_prices.py]"]
  node_massive["Massive Client<br/>[massive_client.py]"]
  node_price_cache[("Price Cache<br/>[cache.py]")]
  node_price_update["Price Snapshot<br/>[models.py]"]
  node_sse["SSE Stream<br/>[stream.py]"]
end

subgraph group_trading["Portfolio &amp; Trading"]
  node_watchlist["Watchlist"]
  node_portfolio["Portfolio Views"]
  node_trade_execution["Trade Execution"]
  node_portfolio_store[("SQLite Database")]
end

subgraph group_assistant["AI Assistant"]
  node_chat["AI Chat Assistant"]
  node_llm{{"LiteLLM / OpenRouter"}}
end

node_user(("Trader"))
node_provider(("Market Provider"))

node_source_factory -->|"selects fallback"| node_simulator
node_source_factory -->|"selects by key"| node_massive
node_simulator -->|"implements"| node_source_contract
node_massive -->|"implements"| node_source_contract
node_simulator -->|"loads parameters"| node_seed_prices
node_simulator -->|"writes prices"| node_price_cache
node_massive -->|"writes prices"| node_price_cache
node_massive -->|"polls snapshots"| node_provider
node_price_cache -->|"creates snapshots"| node_price_update
node_sse -->|"reads updates"| node_price_cache
node_user -.->|"views live prices"| node_sse
node_price_cache -.->|"provides prices"| node_portfolio
node_price_cache -.->|"provides prices"| node_trade_execution
node_user -.->|"manages tickers"| node_watchlist
node_user -.->|"asks assistant"| node_chat
node_chat -.->|"requests analysis"| node_llm
node_chat -.->|"executes suggestions"| node_trade_execution
node_portfolio -.->|"persists portfolio"| node_portfolio_store
node_trade_execution -.->|"updates portfolio"| node_portfolio_store

click node_source_factory "https://github.com/ed-donner/finally/blob/main/backend/app/market/factory.py"
click node_source_contract "https://github.com/ed-donner/finally/blob/main/backend/app/market/interface.py"
click node_simulator "https://github.com/ed-donner/finally/blob/main/backend/app/market/simulator.py"
click node_seed_prices "https://github.com/ed-donner/finally/blob/main/backend/app/market/seed_prices.py"
click node_massive "https://github.com/ed-donner/finally/blob/main/backend/app/market/massive_client.py"
click node_price_cache "https://github.com/ed-donner/finally/blob/main/backend/app/market/cache.py"
click node_price_update "https://github.com/ed-donner/finally/blob/main/backend/app/market/models.py"
click node_sse "https://github.com/ed-donner/finally/blob/main/backend/app/market/stream.py"
click node_watchlist "https://github.com/ed-donner/finally/tree/main/backend/app"
click node_portfolio "https://github.com/ed-donner/finally/tree/main/backend/app"
click node_trade_execution "https://github.com/ed-donner/finally/tree/main/backend/app"
click node_chat "https://github.com/ed-donner/finally/tree/main/backend/app"

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_source_factory,node_source_contract,node_simulator,node_seed_prices,node_massive,node_price_cache,node_price_update,node_sse toneBlue
class node_watchlist,node_portfolio,node_trade_execution,node_portfolio_store toneAmber
class node_chat,node_llm toneMint
class node_user,node_provider toneIndigo
```

## Components

### Market Data

- [Source Selector](https://github.com/ed-donner/finally/blob/main/backend/app/market/factory.py): `backend/app/market/factory.py`
- [Provider Contract](https://github.com/ed-donner/finally/blob/main/backend/app/market/interface.py): `backend/app/market/interface.py`
- [GBM Simulator](https://github.com/ed-donner/finally/blob/main/backend/app/market/simulator.py): `backend/app/market/simulator.py`
- [Seed Parameters](https://github.com/ed-donner/finally/blob/main/backend/app/market/seed_prices.py): `backend/app/market/seed_prices.py`
- [Massive Client](https://github.com/ed-donner/finally/blob/main/backend/app/market/massive_client.py): `backend/app/market/massive_client.py`
- [Price Cache](https://github.com/ed-donner/finally/blob/main/backend/app/market/cache.py): `backend/app/market/cache.py`
- [Price Snapshot](https://github.com/ed-donner/finally/blob/main/backend/app/market/models.py): `backend/app/market/models.py`
- [SSE Stream](https://github.com/ed-donner/finally/blob/main/backend/app/market/stream.py): `backend/app/market/stream.py`

### Portfolio & Trading

- [Watchlist](https://github.com/ed-donner/finally/tree/main/backend/app): `backend/app`
- [Portfolio Views](https://github.com/ed-donner/finally/tree/main/backend/app): `backend/app`
- [Trade Execution](https://github.com/ed-donner/finally/tree/main/backend/app): `backend/app`
- **SQLite Database**

### AI Assistant

- [AI Chat Assistant](https://github.com/ed-donner/finally/tree/main/backend/app): `backend/app`
- **LiteLLM / OpenRouter**

### Other components

- **Trader**
- **Market Provider**

## Connections

- Source Selector → GBM Simulator: selects fallback (evidence: `backend/app/market/factory.py`)
- Source Selector → Massive Client: selects by key (evidence: `backend/app/market/factory.py`)
- GBM Simulator → Provider Contract: implements (evidence: `backend/app/market/simulator.py`)
- Massive Client → Provider Contract: implements (evidence: `backend/app/market/massive_client.py`)
- GBM Simulator → Seed Parameters: loads parameters (evidence: `backend/app/market/simulator.py`)
- GBM Simulator → Price Cache: writes prices (evidence: `backend/app/market/simulator.py`)
- Massive Client → Price Cache: writes prices (evidence: `backend/app/market/massive_client.py`)
- Massive Client → Market Provider: polls snapshots (evidence: `backend/app/market/massive_client.py`)
- Price Cache → Price Snapshot: creates snapshots (evidence: `backend/app/market/cache.py`)
- SSE Stream → Price Cache: reads updates (evidence: `backend/app/market/stream.py`)
- Trader → SSE Stream: views live prices (evidence: `README.md`)
- Price Cache → Portfolio Views: provides prices (evidence: `backend/app/market/cache.py`)
- Price Cache → Trade Execution: provides prices (evidence: `backend/app/market/cache.py`)
- Trader → Watchlist: manages tickers (evidence: `README.md`)
- Trader → AI Chat Assistant: asks assistant (evidence: `README.md`)
- AI Chat Assistant → LiteLLM / OpenRouter: requests analysis (evidence: `README.md`)
- AI Chat Assistant → Trade Execution: executes suggestions (evidence: `README.md`)
- Portfolio Views → SQLite Database: persists portfolio (evidence: `README.md`)
- Trade Execution → SQLite Database: updates portfolio (evidence: `README.md`)
