# lecoeurdelest/wqbr architecture

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

- Interactive diagram: https://gitdiagram.com/lecoeurdelest/wqbr
- Repository: https://github.com/lecoeurdelest/wqbr

## Overview

#### Purpose and Entry Points
This is a Python research platform centered on quantitative-alpha research. It provides a WorldQuant BRAIN compatibility toolkit plus a platform-neutral Research Center for future providers. Main runtime entry points are the WorldQuant MCP stdio server (`wq_brain_mcp/__main__.py`, `wq_brain_mcp/server.py`), central multi-platform MCP gateway (`research_center_mcp/server.py`), and WorldQuant ingest orchestration (`research_platforms/worldquant/pipeline/run_all.py`). Package commands are defined in `pyproject.toml`.

#### API Boundary and WorldQuant Binding
`wqbrain` is the provider-facing transport/client layer: it authenticates, retries, rate-limits, polls asynchronous BRAIN operations, validates responses, and decodes endpoint payloads. Its models separate API contracts from downstream logic. WorldQuant-specific behavior is contained in the binding rather than spread through core research components.
Paths: `wqbrain/transport.py`, `wqbrain/client.py`, `research_platforms/worldquant/scorecard.py`.

#### Local Lake and Ingest Pipeline
The lake is the durable system of record for remotely fetched data, avoiding repeated network reads and simulation quota consumption. The WorldQuant pipeline ingests catalog, alpha, check, and PnL domains; then transforms, quality-checks, materializes marts, and persists pipeline state. Storage uses Parquet and DuckDB-oriented views/layouts, with atomic/idempotent writes implied by the pipeline boundary.
Paths: `wqbrain_lake/layout.py`, `wqbrain_lake/writer.py`, `research_platforms/worldquant/pipeline/run_all.py`.

#### Canonical Multi-Platform Data Path
The newer center architecture defines platform-scoped domain data and an injected projection pipeline, currently delivered for daily performance. `research_data` owns canonical performance records/repository semantics; `research_pipeline` projects provider data into this representation; `research_analytics` consumes canonical data through its analytics port. Other WorldQuant data domains remain provider-specific/staged.
Paths: `research_data/performance.py`, `research_pipeline/performance.py`, `research_analytics/performance.py`.

#### Analytics, Portfolio, and Visualization
Offline analytics operates on local/canonical PnL to calculate metrics, correlations, attribution, scorecards, parameter sweeps, and region-aware shadow-book risk/performance. This boundary must not require BRAIN calls. Visualization turns analytics datasets into static images or self-contained offline HTML using matplotlib and Plotly.
Paths: `research_analytics/metrics.py`, `research_analytics/portfolio.py`, `wqbrain_viz/report.py`.

#### Research Center, Policy, and Memory
The Research Center is the platform-neutral control plane: registry/capability routing, actor policy, research submissions, event capture, outcome memory, and cited knowledge. Research gates evaluate expression and lineage requirements before simulation budget reservation. Policy separates human and AI modes; AI routes cannot invoke irreversible submission capability or self-approve AI-originated knowledge.
Paths: `research_center/processor.py`, `research_center/memory.py`, `wqbrain_research/gates.py`.

#### MCP Interfaces and Safety Boundaries
Two stdio MCP servers expose the system to LLM clients: a WorldQuant-compatible façade and a central gateway. Read tools favor lake-first access; simulation returns local job UUIDs rather than remote progress handles. Submission is opt-in, requires a human mode, explicit confirmation, and passing checks. Config is non-secret TOML with environment credential/override support.
Paths: `wq_brain_mcp/server.py`, `wq_brain_mcp/tools/simulate.py`, `research_center_mcp/server.py`.

Main entry points: [`research_center/processor.py`](https://github.com/lecoeurdelest/wqbr/blob/main/research_center/processor.py) (Research processor), [`wqbrain/client.py`](https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain/client.py) (BRAIN client), [`wq_brain_mcp/server.py`](https://github.com/lecoeurdelest/wqbr/blob/main/wq_brain_mcp/server.py) (WorldQuant MCP server), [`research_platforms/worldquant/pipeline/run_all.py`](https://github.com/lecoeurdelest/wqbr/blob/main/research_platforms/worldquant/pipeline/run_all.py) (WorldQuant ingest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["MCP Interfaces"]
  node_wq_mcp["WorldQuant MCP server<br/>stdio MCP façade<br/>[server.py]"]
  node_simulate_tool["Simulation tool<br/>MCP tool<br/>[simulate.py]"]
  node_center_mcp["Research Center MCP<br/>stdio MCP gateway<br/>[server.py]"]
end

subgraph group_worldquant["WorldQuant Integration"]
  node_wq_client["BRAIN client<br/>provider transport<br/>[client.py]"]
  node_wq_transport["HTTP transport<br/>transport layer<br/>[transport.py]"]
  node_wq_pipeline{{"WorldQuant ingest<br/>orchestration pipeline<br/>[run_all.py]"}}
  node_scorecard["WorldQuant scorecards<br/>provider binding<br/>[scorecard.py]"]
end

subgraph group_data["Data &amp; Analytics"]
  node_lake_layout[("Lake layout<br/>storage layout<br/>[layout.py]")]
  node_lake_writer["Lake writer<br/>atomic persistence<br/>[writer.py]"]
  node_canonical_performance[("Canonical performance<br/>domain repository<br/>[performance.py]")]
  node_performance_projection["Performance projection<br/>projection pipeline<br/>[performance.py]"]
  node_analytics["Offline analytics<br/>analytics port<br/>[metrics.py]"]
  node_portfolio["Shadow-book portfolio<br/>portfolio analytics<br/>[portfolio.py]"]
  node_visualization["Offline reports<br/>visualization<br/>[report.py]"]
end

subgraph group_center["Research Center"]
  node_research_processor{{"Research processor<br/>control plane<br/>[processor.py]"}}
  node_research_memory[("Outcome memory<br/>cited knowledge store<br/>[memory.py]")]
  node_research_gates["Research gates<br/>policy enforcement<br/>[gates.py]"]
end

node_wq_mcp -->|"exposes"| node_simulate_tool
node_simulate_tool -->|"checks before reservation"| node_research_gates
node_wq_mcp -->|"reads lake first"| node_lake_layout
node_wq_mcp -->|"provider operations"| node_wq_client
node_wq_client -->|"uses"| node_wq_transport
node_wq_pipeline -->|"fetches remote domains"| node_wq_client
node_wq_pipeline -->|"persists staged data"| node_lake_writer
node_lake_writer -->|"writes Parquet and views"| node_lake_layout
node_wq_pipeline -->|"materializes"| node_scorecard
node_performance_projection -->|"projects into"| node_canonical_performance
node_lake_layout -->|"provider performance input"| node_performance_projection
node_canonical_performance -->|"canonical analytics input"| node_analytics
node_analytics -->|"supplies metrics"| node_portfolio
node_analytics -->|"report datasets"| node_visualization
node_center_mcp -->|"routes requests"| node_research_processor
node_research_processor -->|"enforces policy and gates"| node_research_gates
node_research_processor -->|"captures outcomes"| node_research_memory
node_research_processor -.->|"invokes projection"| node_performance_projection
node_research_gates -.->|"permits guarded simulation"| node_wq_client

click node_wq_mcp "https://github.com/lecoeurdelest/wqbr/blob/main/wq_brain_mcp/server.py"
click node_simulate_tool "https://github.com/lecoeurdelest/wqbr/blob/main/wq_brain_mcp/tools/simulate.py"
click node_center_mcp "https://github.com/lecoeurdelest/wqbr/blob/main/research_center_mcp/server.py"
click node_wq_client "https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain/client.py"
click node_wq_transport "https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain/transport.py"
click node_wq_pipeline "https://github.com/lecoeurdelest/wqbr/blob/main/research_platforms/worldquant/pipeline/run_all.py"
click node_scorecard "https://github.com/lecoeurdelest/wqbr/blob/main/research_platforms/worldquant/scorecard.py"
click node_lake_layout "https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain_lake/layout.py"
click node_lake_writer "https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain_lake/writer.py"
click node_canonical_performance "https://github.com/lecoeurdelest/wqbr/blob/main/research_data/performance.py"
click node_performance_projection "https://github.com/lecoeurdelest/wqbr/blob/main/research_pipeline/performance.py"
click node_analytics "https://github.com/lecoeurdelest/wqbr/blob/main/research_analytics/metrics.py"
click node_portfolio "https://github.com/lecoeurdelest/wqbr/blob/main/research_analytics/portfolio.py"
click node_visualization "https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain_viz/report.py"
click node_research_processor "https://github.com/lecoeurdelest/wqbr/blob/main/research_center/processor.py"
click node_research_memory "https://github.com/lecoeurdelest/wqbr/blob/main/research_center/memory.py"
click node_research_gates "https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain_research/gates.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_wq_mcp,node_simulate_tool,node_center_mcp toneBlue
class node_wq_client,node_wq_transport,node_wq_pipeline,node_scorecard toneAmber
class node_lake_layout,node_lake_writer,node_canonical_performance,node_performance_projection,node_analytics,node_portfolio,node_visualization toneMint
class node_research_processor,node_research_memory,node_research_gates toneRose
```

## Components

### MCP Interfaces

- [WorldQuant MCP server](https://github.com/lecoeurdelest/wqbr/blob/main/wq_brain_mcp/server.py): stdio MCP façade · Compatibility tools with lake-first reads and guarded submission. · `wq_brain_mcp/server.py`
- [Simulation tool](https://github.com/lecoeurdelest/wqbr/blob/main/wq_brain_mcp/tools/simulate.py): MCP tool · Returns local job UUIDs rather than remote progress handles. · `wq_brain_mcp/tools/simulate.py`
- [Research Center MCP](https://github.com/lecoeurdelest/wqbr/blob/main/research_center_mcp/server.py): stdio MCP gateway · Platform-neutral gateway for multi-provider research. · `research_center_mcp/server.py`

### WorldQuant Integration

- [BRAIN client](https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain/client.py): provider transport · Authentication, retries, rate limits, polling, validation, and payload decoding. · `wqbrain/client.py`
- [HTTP transport](https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain/transport.py): transport layer · `wqbrain/transport.py`
- [WorldQuant ingest](https://github.com/lecoeurdelest/wqbr/blob/main/research_platforms/worldquant/pipeline/run_all.py): orchestration pipeline · Ingests catalog, alpha, check, and PnL domains. · `research_platforms/worldquant/pipeline/run_all.py`
- [WorldQuant scorecards](https://github.com/lecoeurdelest/wqbr/blob/main/research_platforms/worldquant/scorecard.py): provider binding · `research_platforms/worldquant/scorecard.py`

### Data & Analytics

- [Lake layout](https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain_lake/layout.py): storage layout · Parquet and DuckDB-oriented durable local record. · `wqbrain_lake/layout.py`
- [Lake writer](https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain_lake/writer.py): atomic persistence · Idempotently materializes staged lake data and state. · `wqbrain_lake/writer.py`
- [Canonical performance](https://github.com/lecoeurdelest/wqbr/blob/main/research_data/performance.py): domain repository · Platform-scoped performance records and repository semantics. · `research_data/performance.py`
- [Performance projection](https://github.com/lecoeurdelest/wqbr/blob/main/research_pipeline/performance.py): projection pipeline · Projects provider performance into the canonical representation. · `research_pipeline/performance.py`
- [Offline analytics](https://github.com/lecoeurdelest/wqbr/blob/main/research_analytics/metrics.py): analytics port · Computes metrics, correlations, attribution, and portfolio analysis without BRAIN calls. · `research_analytics/metrics.py`
- [Shadow-book portfolio](https://github.com/lecoeurdelest/wqbr/blob/main/research_analytics/portfolio.py): portfolio analytics · Region-aware risk and performance analysis. · `research_analytics/portfolio.py`
- [Offline reports](https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain_viz/report.py): visualization · Creates static images and self-contained HTML reports. · `wqbrain_viz/report.py`

### Research Center

- [Research processor](https://github.com/lecoeurdelest/wqbr/blob/main/research_center/processor.py): control plane · Routes capabilities, processes submissions, and captures research events. · `research_center/processor.py`
- [Outcome memory](https://github.com/lecoeurdelest/wqbr/blob/main/research_center/memory.py): cited knowledge store · Stores outcomes and cited research knowledge. · `research_center/memory.py`
- [Research gates](https://github.com/lecoeurdelest/wqbr/blob/main/wqbrain_research/gates.py): policy enforcement · Checks expression and lineage before simulation budget reservation. · `wqbrain_research/gates.py`

## Connections

- WorldQuant MCP server → Simulation tool: exposes
- Simulation tool → Research gates: checks before reservation
- WorldQuant MCP server → Lake layout: reads lake first
- WorldQuant MCP server → BRAIN client: provider operations
- BRAIN client → HTTP transport: uses
- WorldQuant ingest → BRAIN client: fetches remote domains
- WorldQuant ingest → Lake writer: persists staged data
- Lake writer → Lake layout: writes Parquet and views
- WorldQuant ingest → WorldQuant scorecards: materializes
- Performance projection → Canonical performance: projects into
- Lake layout → Performance projection: provider performance input
- Canonical performance → Offline analytics: canonical analytics input
- Offline analytics → Shadow-book portfolio: supplies metrics
- Offline analytics → Offline reports: report datasets
- Research Center MCP → Research processor: routes requests
- Research processor → Research gates: enforces policy and gates
- Research processor → Outcome memory: captures outcomes
- Research processor → Performance projection: invokes projection
- Research gates → BRAIN client: permits guarded simulation
