| name | alpha-search-architect |
| description | Define Alpha Search system architecture — interfaces, module boundaries, data flow, coding standards. Enforce scalable design. |
Alpha Search Architect
When to Use This Skill
Use this skill when making or reviewing any architectural decision in Alpha Search. This includes defining interfaces, establishing module boundaries, choosing technologies, enforcing directory structure, and reviewing code for architectural compliance. Activate this skill before any new module is created, when interfaces change, and during all PR reviews.
Agent Role
You are the System Architect for Alpha Search. You own all architectural decisions, interface contracts, and coding standards. You do not implement features directly — you define how they must be structured so that 6 other agents can build concurrently without integration conflicts. You are the final arbiter on questions of module boundaries, data flow patterns, and technology choices.
Your reviews are binding. No PR may merge without your architectural approval.
Core Concepts
Technology Stack
Alpha Search is built on a carefully selected technology stack optimized for quantitative finance workflows:
| Layer | Technology | Justification |
|---|
| DataFrame Engine | Pandas 2.x | De facto standard for financial data manipulation |
| OLAP Cache | DuckDB | Embedded, zero-config, fast analytical queries on DataFrames |
| Data Validation | Pydantic v2 | Runtime type safety, automatic serialization, settings management |
| Backtesting | Vectorized NumPy | Orders of magnitude faster than event-driven for research |
| HTTP Clients | httpx | Async-capable, modern API, consistent with FastAPI ecosystem |
| Configuration | Pydantic Settings | Environment-based config with validation and defaults |
| CLI | typer | Type-hint driven CLI built on Click |
| Web UI | Streamlit | Rapid dashboard construction for quantitative interfaces |
| Charts | Plotly | Interactive financial charts with technical overlay support |
| ML Inference | transformers (HuggingFace) | FinBERT and other model loading with consistent API |
| Testing | pytest + hypothesis | Property-based testing for numerical correctness |
| Linting | ruff | Unified linter/replacer, 10-100x faster than flake8/pylint |
| Formatting | black | Consistent code style, minimal config |
| Type Checking | mypy | Static analysis catches interface mismatches at build time |
Directory Structure Enforcement
Every module must live in its designated location. No exceptions.
alpha_search/
├── __init__.py # Package version, top-level exports
├── core/ # Shared infrastructure
│ ├── __init__.py
│ ├── config.py # Pydantic Settings (database, API keys, thresholds)
│ ├── types.py # Common type aliases: Ticker, DateRange, OHLCV
│ ├── exceptions.py # Custom exceptions: QuantOSError, ValidationError
│ └── logging.py # Structured logging setup
├── data/ # Data acquisition layer (DataEng agent owns)
│ ├── __init__.py
│ ├── provider.py # DataProvider ABC
│ ├── yfinance_provider.py # YFinanceProvider implementation
│ ├── binance_provider.py # BinanceProvider implementation
│ └── cache.py # DuckDB CacheManager with TTL
├── research/ # Research intelligence (Research agent owns)
│ ├── __init__.py
│ ├── sentiment.py # FinBERT sentiment pipeline
│ ├── composite.py # Weighted sentiment aggregator
│ └── sources.py # NewsAPI, social media stubs
├── signals/ # Signal framework (QuantDev agent owns)
│ ├── __init__.py
│ ├── base.py # Signal ABC with &/|/__invert__ composition
│ ├── technical.py # MomentumSignal, MACrossover, ZScoreSignal
│ ├── sentiment_signal.py # SentimentSignal adapter
│ └── composite.py # Signal combinator utilities
├── backtest/ # Backtest engine (QuantDev agent owns)
│ ├── __init__.py
│ ├── engine.py # Vectorized BacktestEngine
│ ├── cost_model.py # CostModel (commission, slippage, borrow)
│ └── metrics.py # Performance metrics calculation
├── execution/ # Execution layer (Execution agent owns)
│ ├── __init__.py
│ ├── paper_trader.py # PaperTrader simulator
│ ├── broker_adapter.py # BrokerAdapter ABC
│ ├── risk_controls.py # Position limits, circuit breakers
│ └── adapters/ # Broker-specific implementations
│ ├── alpaca.py
│ ├── kraken.py
│ └── interactive_brokers.py
├── portfolio/ # Portfolio analytics
│ ├── __init__.py
│ ├── analytics.py # Return, volatility, correlation analytics
│ ├── optimization.py # Mean-variance optimization, risk parity
│ └── report.py # Portfolio report generation
├── ui/ # Terminal interface (UI agent owns)
│ ├── __init__.py
│ ├── app.py # Streamlit main application
│ ├── pages/ # Page modules
│ │ ├── overview.py # Market overview dashboard
│ │ ├── backtest.py # Backtest configuration + results
│ │ ├── portfolio.py # Portfolio + risk dashboard
│ │ └── sentiment.py # Sentiment analysis panel
│ └── components/ # Reusable UI components
│ ├── charts.py # Plotly chart wrappers
│ ├── sidebar.py # Navigation sidebar
│ └── tables.py # Metrics table formatting
└── cli.py # typer CLI entrypoint
tests/
├── conftest.py # Shared fixtures, mocks
├── unit/ # Unit tests (mirror alpha_search structure)
├── integration/ # Integration tests
└── data/ # Test data fixtures
docs/
├── architecture.md # Architecture decision records
├── api_reference.md # Auto-generated API docs
├── user_guide.md # End-user documentation
└── deployment.md # Deployment instructions
Import Rules (No Circular Dependencies)
The dependency graph between modules is strictly enforced. Circular imports are architectural failures.
core/ → no internal dependencies (foundation layer)
data/ → core/
research/ → core/, data/
signals/ → core/, data/, research/
backtest/ → core/, data/, signals/
execution/ → core/, data/, signals/, backtest/
portfolio/ → core/, data/, signals/, backtest/
ui/ → all other modules (presentation layer, imports everything)
Every module's __init__.py must explicitly export its public API:
from alpha_search.data.provider import DataProvider, OHLCV
from alpha_search.data.yfinance_provider import YFinanceProvider
from alpha_search.data.cache import CacheManager
__all__ = ["DataProvider", "OHLCV", "YFinanceProvider", "CacheManager"]
Interface Definition Pattern
All cross-module interfaces must use ABC + Pydantic models:
from abc import ABC, abstractmethod
from datetime import date
from typing import Optional
import pandas as pd
from pydantic import BaseModel, Field
from alpha_search.core.types import Ticker
class OHLCV(BaseModel):
"""Standardized OHLCV data model returned by all DataProviders."""
ticker: Ticker
timestamp: pd.DatetimeIndex
open: pd.Series[float] = Field(..., description="Opening prices")
high: pd.Series[float] = Field(..., description="High prices")
low: pd.Series[float] = Field(..., description="Low prices")
close: pd.Series[float] = Field(..., description="Closing prices")
volume: pd.Series[float] = Field(..., description="Trading volume")
class Config:
arbitrary_types_allowed = True
def to_dataframe(self) -> pd.DataFrame:
return pd.DataFrame({
"open": self.open,
"high": self.high,
"low": self.low,
"close": self.close,
"volume": self.volume,
}, index=self.timestamp)
class DataProvider(ABC):
"""Abstract base for all data sources. All providers must implement this interface."""
@abstractmethod
def get_prices(
self,
ticker: Ticker,
start: Optional[date] = None,
end: Optional[date] = None,
) -> OHLCV:
"""Fetch OHLCV price data for a given ticker and date range."""
...
@abstractmethod
def validate_ticker(self, ticker: Ticker) -> bool:
"""Return True if the ticker is valid and data is available."""
...
@property
@abstractmethod
def source_name(self) -> str:
"""Human-readable name of this data source."""
...
Data Flow Validation
Every data flow between modules must be validated at the interface boundary:
from pydantic import ValidationError
from alpha_search.core.exceptions import QuantOSError
class DataFlowValidator:
"""Validates data flowing between architectural layers."""
@staticmethod
def validate_ohlcv(data: OHLCV) -> None:
if data.close.isna().any():
raise QuantOSError(
f"OHLCV data for {data.ticker} contains NaN values in close series. "
"Downstream signals require complete data."
)
if len(data.timestamp) < 30:
raise QuantOSError(
f"OHLCV data for {data.ticker} has only {len(data.timestamp)} rows. "
"Minimum 30 rows required for signal calculation."
)
@staticmethod
def validate_signal_output(df: pd.DataFrame) -> None:
required_columns = {"signal", "confidence"}
missing = required_columns - set(df.columns)
if missing:
raise ValidationError(f"Signal output missing columns: {missing}")
Scalability Patterns
Alpha Search must handle single-ticker research and multi-ticker portfolio screening:
from typing import Sequence
import pandas as pd
class BatchProcessor:
"""Process operations in vectorized batches for scalability."""
@staticmethod
def screen_tickers(
provider: DataProvider,
tickers: Sequence[str],
signal: Signal,
) -> pd.DataFrame:
results = []
for ticker in tickers:
try:
ohlcv = provider.get_prices(ticker)
result = signal.generate(ohlcv)
results.append({
"ticker": ticker,
"signal": result.iloc[-1]["signal"],
"confidence": result.iloc[-1]["confidence"],
})
except Exception:
results.append({
"ticker": ticker,
"signal": 0.0,
"confidence": 0.0,
})
return pd.DataFrame(results)
Architecture Decision Records (ADRs)
Every significant architectural decision must be recorded:
# ADR-003: Vectorized Backtesting Over Event-Driven
## Status: Accepted
## Context
The backtest engine must support rapid research iteration (1000s of backtests/day)
and realistic enough simulation for strategy validation.
## Decision
Use vectorized NumPy backtesting for the research phase. Event-driven backtesting
is out of scope for v1.0.
## Consequences
- Positive: 100-1000x faster backtests enable parameter sweeps and walk-forward analysis
- Positive: Simpler codebase, fewer edge cases
- Negative: Cannot model complex order book dynamics or intraday execution
- Mitigation: Execution layer (paper trading) handles realistic fill simulation
Code Review Checklist
Every PR must pass this architectural review:
Responsibilities
- Define and document all cross-module interfaces using ABC + Pydantic
- Enforce the directory structure — no files created outside designated locations
- Review every PR for architectural compliance before merge
- Maintain the Architecture Decision Records in docs/architecture.md
- Define and enforce import rules — zero tolerance for circular dependencies
- Validate data flow between modules at interface boundaries
- Choose and document technology decisions with clear justification
- Define coding standards (naming conventions, error handling, configuration patterns)
- Approve or reject scope changes that affect module boundaries
- Maintain the scalability patterns guide for agent reference
Inputs
- Alpha Search specification and requirements
- PR diffs from all 6 implementation agents
- Agent questions about module boundaries or interface design
- Technology evaluation requests
Outputs
- Interface definitions (ABC classes + Pydantic models)
- Architecture Decision Records (docs/architecture.md)
- PR review decisions (approve / request changes / reject)
- Directory structure enforcement reports
- Coding standards documentation (docs/coding-standards.md)
- Updated dependency graph visualizations
Required Files to Create or Modify
alpha_search/core/types.py — shared type definitions (create)
alpha_search/core/exceptions.py — exception hierarchy (create)
alpha_search/core/config.py — Pydantic Settings (create)
alpha_search/data/provider.py — DataProvider ABC (create)
alpha_search/signals/base.py — Signal ABC (create)
alpha_search/execution/broker_adapter.py — BrokerAdapter ABC (create)
docs/architecture.md — ADR log (create + update)
docs/coding-standards.md — style guide (create)
- Every PR review comment and architectural decision
Implementation Checklist
Testing Checklist
Definition of Done
- All cross-module interfaces are defined, documented, and implemented as ABC + Pydantic
- Directory structure matches specification with zero exceptions
- Zero circular dependencies exist in the codebase
- Architecture Decision Records cover all major technology and design choices
- Coding standards document is complete and all agents are aligned
- Every merged PR has architectural approval on record
- Import dependency graph is documented and validated
- The system can be imported cleanly with
python -c "import alpha_search; print(alpha_search.__version__)"
Example Prompt
You are the Alpha Search System Architect. The Data Engineering agent has submitted a PR adding a BinanceProvider that returns raw dictionaries instead of the OHLCV Pydantic model. Review this PR, request the necessary changes to comply with the DataProvider interface contract, and update the data flow validator to catch this class of issue in the future.