# kaptnemo/alphabee architecture

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

- Interactive diagram: https://gitdiagram.com/kaptnemo/alphabee
- Repository: https://github.com/kaptnemo/alphabee
- Video tour (about a minute): https://gitdiagram.com/kaptnemo/alphabee/video

## Overview

AlphaBee is an A-share investment research system whose main user workflow runs a layered analysis from factual data gathering through evidence-backed investment conclusions and report output. CLI and web interfaces expose that workflow; company tracking and midterm decisions extend it across runs. The README documents the domain-stage sequence and major capabilities. Sampled excerpts additionally establish selected engine behavior and the tracking adapter’s call into the orchestrator; unsampled subsystem links are limited to documented relationships.

Main entry points: [`alphabee/orchestrator/agent.py`](https://github.com/kaptnemo/alphabee/blob/main/alphabee/orchestrator/agent.py) (Analysis orchestrator), [`alphabee/apps/cli/main.py`](https://github.com/kaptnemo/alphabee/blob/main/alphabee/apps/cli/main.py) (CLI entry), [`alphabee/financial_report/pipeline.py`](https://github.com/kaptnemo/alphabee/blob/main/alphabee/financial_report/pipeline.py) (Financial report pipeline), [`alphabee/tracking/scheduler.py`](https://github.com/kaptnemo/alphabee/blob/main/alphabee/tracking/scheduler.py) (Tracking scheduler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI entry<br/>[main.py]"]
  node_cli_stream["CLI streaming<br/>[streaming.py]"]
  node_cli_render["CLI renderer<br/>[renderer.py]"]
  node_web_api["Web API<br/>[chat.py]"]
  node_web_client["Web client<br/>[useChatStream.ts]"]
end

subgraph group_research["Research pipeline"]
  node_orchestrator["Analysis orchestrator<br/>[agent.py]"]
  node_facts["Fact analysis<br/>[models.py]"]
  node_context["Context injection<br/>[context_router.py]"]
  node_derived["Derived facts<br/>[engine.py]"]
  node_derived_rules["Derived rules<br/>[registry.py]"]
  node_signals["Signal detection<br/>[engine.py]"]
  node_anomaly["Anomaly detection<br/>[engine.py]"]
  node_anomaly_models["Anomaly models<br/>[models.py]"]
  node_conflicts["Conflict exploration<br/>[agent.py]"]
  node_verification["Hypothesis verification<br/>[agent.py]"]
  node_insights["Insight synthesis<br/>[agent.py]"]
  node_thesis["Thesis generation<br/>[engine.py]"]
  node_thesis_review["Thesis review<br/>[reviewer.py]"]
  node_report["Research report<br/>[agent.py]"]
end

subgraph group_evidence["Data and evidence"]
  node_collectors["Market collectors"]
  node_adapters["Field adapters<br/>[tushare.py]"]
  node_report_pipeline["Financial report pipeline<br/>[pipeline.py]"]
  node_pdf_loader["PDF OCR loader<br/>[pdf_ocr_loader.py]"]
  node_ocr_server["OCR MCP server<br/>[pdf_ocr_server.py]"]
end

subgraph group_continuity["Research continuity"]
  node_midterm["Midterm decision<br/>[score_engine.py]"]
  node_midterm_models["Decision models<br/>[models.py]"]
  node_company_track["Company tracking<br/>[track.py]"]
  node_tracking_scheduler["Tracking scheduler<br/>[scheduler.py]"]
  node_pipeline_engine["Pipeline engine adapter<br/>[pipeline_engine.py]"]
  node_task_records[("Task records<br/>[recorder.py]")]
end

subgraph group_platform["Runtime services"]
  node_pipeline_utils["LLM output utilities<br/>[pipeline.py]"]
  node_telemetry["Telemetry<br/>[telemetry.py]"]
  node_storage["Data storage paths<br/>[storage.py]"]
end

node_analyst(("Analyst"))

node_analyst -->|"submits query"| node_cli
node_cli -->|"starts analysis"| node_orchestrator
node_analyst -->|"asks question"| node_web_client
node_web_client -->|"streams request"| node_web_api
node_web_api -->|"starts analysis"| node_orchestrator
node_orchestrator -->|"collects facts"| node_facts
node_orchestrator -->|"injects context"| node_context
node_orchestrator -->|"computes indicators"| node_derived
node_derived -->|"loads rules"| node_derived_rules
node_orchestrator -->|"detects signals"| node_signals
node_orchestrator -->|"detects anomalies"| node_anomaly
node_anomaly -->|"produces report"| node_anomaly_models
node_orchestrator -->|"explores conflicts"| node_conflicts
node_orchestrator -->|"verifies evidence"| node_verification
node_orchestrator -->|"synthesizes insights"| node_insights
node_orchestrator -->|"forms thesis"| node_thesis
node_thesis -->|"reviews thesis"| node_thesis_review
node_orchestrator -->|"outputs report"| node_report
node_collectors -->|"normalizes fields"| node_adapters
node_report_pipeline -->|"uses OCR"| node_pdf_loader
node_report_pipeline -->|"uses OCR service"| node_ocr_server
node_orchestrator -->|"adds decision stage"| node_midterm
node_midterm -->|"scores factors"| node_midterm_models
node_tracking_scheduler -.->|"tracks companies"| node_company_track
node_tracking_scheduler -.->|"runs research engine"| node_pipeline_engine
node_pipeline_engine -->|"invokes analysis"| node_orchestrator
node_orchestrator -->|"records run"| node_task_records
node_cli -->|"streams output"| node_cli_stream
node_cli -->|"renders results"| node_cli_render
node_orchestrator -->|"tracks execution"| node_telemetry
node_orchestrator -.->|"parses model output"| node_pipeline_utils
node_report_pipeline -->|"resolves data paths"| node_storage

click node_cli "https://github.com/kaptnemo/alphabee/blob/main/alphabee/apps/cli/main.py"
click node_cli_stream "https://github.com/kaptnemo/alphabee/blob/main/alphabee/apps/cli/streaming.py"
click node_cli_render "https://github.com/kaptnemo/alphabee/blob/main/alphabee/apps/cli/renderer.py"
click node_web_api "https://github.com/kaptnemo/alphabee/blob/main/alphabee/apps/web/api/chat.py"
click node_web_client "https://github.com/kaptnemo/alphabee/blob/main/web/src/hooks/useChatStream.ts"
click node_orchestrator "https://github.com/kaptnemo/alphabee/blob/main/alphabee/orchestrator/agent.py"
click node_facts "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/facts/models.py"
click node_context "https://github.com/kaptnemo/alphabee/blob/main/alphabee/domain_context/context_router.py"
click node_derived "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/derived_facts/engine.py"
click node_derived_rules "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/derived_facts/registry.py"
click node_signals "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/signal/engine.py"
click node_anomaly "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/anomaly/engine.py"
click node_anomaly_models "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/anomaly/models.py"
click node_conflicts "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/explore_conflicts/agent.py"
click node_verification "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/verify_hypotheses/agent.py"
click node_insights "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/insights/agent.py"
click node_thesis "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/thesis/engine.py"
click node_thesis_review "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/thesis/reviewer.py"
click node_report "https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/research_reports/agent.py"
click node_collectors "https://github.com/kaptnemo/alphabee/tree/main/alphabee/collectors"
click node_adapters "https://github.com/kaptnemo/alphabee/blob/main/alphabee/adapters/tushare.py"
click node_report_pipeline "https://github.com/kaptnemo/alphabee/blob/main/alphabee/financial_report/pipeline.py"
click node_pdf_loader "https://github.com/kaptnemo/alphabee/blob/main/alphabee/loader/pdf_ocr_loader.py"
click node_ocr_server "https://github.com/kaptnemo/alphabee/blob/main/alphabee/mcp/pdf_ocr_server.py"
click node_midterm "https://github.com/kaptnemo/alphabee/blob/main/alphabee/midterm/score_engine.py"
click node_midterm_models "https://github.com/kaptnemo/alphabee/blob/main/alphabee/midterm/models.py"
click node_company_track "https://github.com/kaptnemo/alphabee/blob/main/alphabee/company_track/track.py"
click node_tracking_scheduler "https://github.com/kaptnemo/alphabee/blob/main/alphabee/tracking/scheduler.py"
click node_pipeline_engine "https://github.com/kaptnemo/alphabee/blob/main/alphabee/tracking/engines/pipeline_engine.py"
click node_task_records "https://github.com/kaptnemo/alphabee/blob/main/alphabee/task_records/recorder.py"
click node_pipeline_utils "https://github.com/kaptnemo/alphabee/blob/main/alphabee/utils/pipeline.py"
click node_telemetry "https://github.com/kaptnemo/alphabee/blob/main/alphabee/orchestrator/services/telemetry.py"
click node_storage "https://github.com/kaptnemo/alphabee/blob/main/alphabee/utils/storage.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_cli,node_cli_stream,node_cli_render,node_web_api,node_web_client toneBlue
class node_orchestrator,node_facts,node_context,node_derived,node_derived_rules,node_signals,node_anomaly,node_anomaly_models,node_conflicts,node_verification,node_insights,node_thesis,node_thesis_review,node_report toneAmber
class node_collectors,node_adapters,node_report_pipeline,node_pdf_loader,node_ocr_server toneMint
class node_midterm,node_midterm_models,node_company_track,node_tracking_scheduler,node_pipeline_engine,node_task_records toneRose
class node_pipeline_utils,node_telemetry,node_storage,node_analyst toneIndigo
```

## Components

### User interfaces

- [CLI entry](https://github.com/kaptnemo/alphabee/blob/main/alphabee/apps/cli/main.py): `alphabee/apps/cli/main.py`
- [CLI streaming](https://github.com/kaptnemo/alphabee/blob/main/alphabee/apps/cli/streaming.py): `alphabee/apps/cli/streaming.py`
- [CLI renderer](https://github.com/kaptnemo/alphabee/blob/main/alphabee/apps/cli/renderer.py): `alphabee/apps/cli/renderer.py`
- [Web API](https://github.com/kaptnemo/alphabee/blob/main/alphabee/apps/web/api/chat.py): `alphabee/apps/web/api/chat.py`
- [Web client](https://github.com/kaptnemo/alphabee/blob/main/web/src/hooks/useChatStream.ts): `web/src/hooks/useChatStream.ts`

### Research pipeline

- [Analysis orchestrator](https://github.com/kaptnemo/alphabee/blob/main/alphabee/orchestrator/agent.py): `alphabee/orchestrator/agent.py`
- [Fact analysis](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/facts/models.py): `alphabee/agents/facts/models.py`
- [Context injection](https://github.com/kaptnemo/alphabee/blob/main/alphabee/domain_context/context_router.py): `alphabee/domain_context/context_router.py`
- [Derived facts](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/derived_facts/engine.py): `alphabee/agents/derived_facts/engine.py`
- [Derived rules](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/derived_facts/registry.py): `alphabee/agents/derived_facts/registry.py`
- [Signal detection](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/signal/engine.py): `alphabee/agents/signal/engine.py`
- [Anomaly detection](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/anomaly/engine.py): `alphabee/agents/anomaly/engine.py`
- [Anomaly models](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/anomaly/models.py): `alphabee/agents/anomaly/models.py`
- [Conflict exploration](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/explore_conflicts/agent.py): `alphabee/agents/explore_conflicts/agent.py`
- [Hypothesis verification](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/verify_hypotheses/agent.py): `alphabee/agents/verify_hypotheses/agent.py`
- [Insight synthesis](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/insights/agent.py): `alphabee/agents/insights/agent.py`
- [Thesis generation](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/thesis/engine.py): `alphabee/agents/thesis/engine.py`
- [Thesis review](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/thesis/reviewer.py): `alphabee/agents/thesis/reviewer.py`
- [Research report](https://github.com/kaptnemo/alphabee/blob/main/alphabee/agents/research_reports/agent.py): `alphabee/agents/research_reports/agent.py`

### Data and evidence

- [Market collectors](https://github.com/kaptnemo/alphabee/tree/main/alphabee/collectors): `alphabee/collectors`
- [Field adapters](https://github.com/kaptnemo/alphabee/blob/main/alphabee/adapters/tushare.py): `alphabee/adapters/tushare.py`
- [Financial report pipeline](https://github.com/kaptnemo/alphabee/blob/main/alphabee/financial_report/pipeline.py): `alphabee/financial_report/pipeline.py`
- [PDF OCR loader](https://github.com/kaptnemo/alphabee/blob/main/alphabee/loader/pdf_ocr_loader.py): `alphabee/loader/pdf_ocr_loader.py`
- [OCR MCP server](https://github.com/kaptnemo/alphabee/blob/main/alphabee/mcp/pdf_ocr_server.py): `alphabee/mcp/pdf_ocr_server.py`

### Research continuity

- [Midterm decision](https://github.com/kaptnemo/alphabee/blob/main/alphabee/midterm/score_engine.py): `alphabee/midterm/score_engine.py`
- [Decision models](https://github.com/kaptnemo/alphabee/blob/main/alphabee/midterm/models.py): `alphabee/midterm/models.py`
- [Company tracking](https://github.com/kaptnemo/alphabee/blob/main/alphabee/company_track/track.py): `alphabee/company_track/track.py`
- [Tracking scheduler](https://github.com/kaptnemo/alphabee/blob/main/alphabee/tracking/scheduler.py): `alphabee/tracking/scheduler.py`
- [Pipeline engine adapter](https://github.com/kaptnemo/alphabee/blob/main/alphabee/tracking/engines/pipeline_engine.py): `alphabee/tracking/engines/pipeline_engine.py`
- [Task records](https://github.com/kaptnemo/alphabee/blob/main/alphabee/task_records/recorder.py): `alphabee/task_records/recorder.py`

### Runtime services

- [LLM output utilities](https://github.com/kaptnemo/alphabee/blob/main/alphabee/utils/pipeline.py): `alphabee/utils/pipeline.py`
- [Telemetry](https://github.com/kaptnemo/alphabee/blob/main/alphabee/orchestrator/services/telemetry.py): `alphabee/orchestrator/services/telemetry.py`
- [Data storage paths](https://github.com/kaptnemo/alphabee/blob/main/alphabee/utils/storage.py): `alphabee/utils/storage.py`

### Other components

- **Analyst**

## Connections

- Analyst → CLI entry: submits query (evidence: `README.md`)
- CLI entry → Analysis orchestrator: starts analysis (evidence: `README.md`)
- Analyst → Web client: asks question (evidence: `README.md`)
- Web client → Web API: streams request (evidence: `README.md`)
- Web API → Analysis orchestrator: starts analysis (evidence: `README.md`)
- Analysis orchestrator → Fact analysis: collects facts (evidence: `README.md`)
- Analysis orchestrator → Context injection: injects context (evidence: `README.md`)
- Analysis orchestrator → Derived facts: computes indicators (evidence: `README.md`)
- Derived facts → Derived rules: loads rules (evidence: `alphabee/agents/derived_facts/engine.py`)
- Analysis orchestrator → Signal detection: detects signals (evidence: `README.md`)
- Analysis orchestrator → Anomaly detection: detects anomalies (evidence: `README.md`)
- Anomaly detection → Anomaly models: produces report (evidence: `alphabee/agents/anomaly/engine.py`)
- Analysis orchestrator → Conflict exploration: explores conflicts (evidence: `README.md`)
- Analysis orchestrator → Hypothesis verification: verifies evidence (evidence: `README.md`)
- Analysis orchestrator → Insight synthesis: synthesizes insights (evidence: `README.md`)
- Analysis orchestrator → Thesis generation: forms thesis (evidence: `README.md`)
- Thesis generation → Thesis review: reviews thesis (evidence: `README.md`)
- Analysis orchestrator → Research report: outputs report (evidence: `README.md`)
- Market collectors → Field adapters: normalizes fields (evidence: `README.md`)
- Financial report pipeline → PDF OCR loader: uses OCR (evidence: `alphabee/financial_report/pipeline.py`)
- Financial report pipeline → OCR MCP server: uses OCR service (evidence: `alphabee/financial_report/pipeline.py`)
- Analysis orchestrator → Midterm decision: adds decision stage (evidence: `README.md`)
- Midterm decision → Decision models: scores factors (evidence: `alphabee/midterm/score_engine.py`)
- Tracking scheduler → Company tracking: tracks companies
- Tracking scheduler → Pipeline engine adapter: runs research engine
- Pipeline engine adapter → Analysis orchestrator: invokes analysis (evidence: `alphabee/tracking/engines/pipeline_engine.py`)
- Analysis orchestrator → Task records: records run (evidence: `README.md`)
- CLI entry → CLI streaming: streams output (evidence: `alphabee/apps/cli/main.py`)
- CLI entry → CLI renderer: renders results (evidence: `alphabee/apps/cli/main.py`)
- Analysis orchestrator → Telemetry: tracks execution
- Analysis orchestrator → LLM output utilities: parses model output
- Financial report pipeline → Data storage paths: resolves data paths (evidence: `alphabee/financial_report/pipeline.py`)
