Agencio Predict - Algorithm Builder & Trading System Architecture
Complete UX/UI Flows + System Diagnostics
End-to-end user journey from algorithm creation through backtesting to results analysis. Shows all user touchpoints and decision points.
React component tree for the algorithms page and BacktestModal.
BacktestModal: 663 lines (page.tsx:2097-2759)Stat: Reusable metric display componentTuningField: Number input with labelResponsiveContainer: Recharts wrapper with minHeightReact state transitions within BacktestModal component.
running: Boolean - controls loading stateresult: BacktestResponse | null - API responseerror: string | null - error messageshowTuning: Boolean - tuning panel visibilityoverrides: Record - risk parameter overridesHow backtest results are transformed into Recharts visualizations.
High-level architecture showing how the backtesting system integrates with the broader platform.
Internal data flow within runAlgorithmBacktest().
Complete map of backtest-related API endpoints.
From raw equity curve to 13+ metrics plus enhanced analysis.
How errors propagate from backend to frontend and are displayed to users.
Errors.unauthorized() - 401, missing/invalid authErrors.notFound() - 404, algorithm not foundErrors.forbidden() - 403, dataset access deniedErrors.validation() - 400, backtest engine failureMulti-layer validation from API input to DSL evaluation.
Structured logging flow from backend services to observability stack.
LOG_LEVEL=debug - All messagesLOG_LEVEL=info - Info, warn, error (default)LOG_LEVEL=warn - Warn and error onlyLOG_PRETTY=true - Human-readable (dev only)Identified performance bottlenecks and their mitigations.
How paper trading executor uses the same DSL evaluator as backtesting.
Real-time signal aggregation feeding into trading decisions.
Complete journey from backtesting to live trading.
How trading credits are reserved and released.
Entity relationships for backtest-related tables.
All files involved in the backtesting system with their responsibilities.
| File Path | Purpose | Lines |
|---|---|---|
| apps/web/src/app/admin/algorithms/page.tsx | Main page, BacktestModal component, chart rendering | 2097-2759 |
| apps/web/src/app/api/predict/v1/algorithms/[id]/backtest/route.ts | API route wrapper, delegates to handler | ~10 |
| packages/fe/src/components/trading/backtest/BacktestEnhancedView.tsx | 5-tab enhanced metrics interface | ~293 |
| packages/fe/src/components/trading/backtest/TailRiskPanel.tsx | VaR, CVaR, Cornish-Fisher display | ~80 |
| packages/fe/src/components/trading/backtest/DrawdownEventsTable.tsx | Sortable drawdown history table | ~120 |
| packages/fe/src/components/trading/backtest/StreakMetrics.tsx | Win/loss streak analysis | ~70 |
| packages/fe/src/components/trading/backtest/MonthlyHeatmap.tsx | Monthly returns heatmap | ~100 |
| File Path | Purpose | Lines |
|---|---|---|
| packages/be/src/algorithms/api/handlers.ts | handleBacktestAlgorithm(), handleWalkForward(), etc. | 462-750 |
| packages/be/src/algorithms/backtest/engine.ts | runAlgorithmBacktest(), bar-by-bar evaluation | ~1700 |
| packages/be/src/algorithms/backtest/enhanced-metrics.ts | calculateEnhancedMetrics(), tail risk, streaks | ~400 |
| packages/be/src/algorithms/backtest/walk-forward.ts | runWalkForwardBacktest(), cross-validation | ~300 |
| packages/be/src/algorithms/backtest/monte-carlo.ts | runMonteCarloSimulation(), bootstrap | ~250 |
| packages/be/src/algorithms/backtest/regime-stress.ts | runRegimeStress(), historical crises | ~200 |
| packages/be/src/algorithms/backtest/portfolio-engine.ts | runPortfolioBacktest(), multi-symbol | ~650 |
| packages/be/src/backtest/metrics.ts | Sharpe, Sortino, VaR, all core metrics | ~1870 |
| packages/be/src/algorithms/dsl/evaluator.ts | DSL evaluation, no-look-ahead, indicators | ~600 |
| packages/be/src/algorithms/paper/executor.ts | tickRun(), paper trading, price validation | ~3800 |
| packages/be/src/algorithms/graduation-service.ts | Graduation gates, PSR check, walk-forward consistency | ~400 |
| packages/be/src/trading/services/credits-service.ts | Credit reservation, release, P&L sync | ~200 |
| packages/be/src/all-seeing-eye/orchestrator/index.ts | Real-time signal aggregation, insights | ~500 |
| File Path | Purpose | Key Types |
|---|---|---|
| packages/shared/src/backtest.ts | Shared backtest type definitions | BacktestTrade, EquityPoint, BacktestMetrics |
| packages/be/src/algorithms/dsl/types.ts | DSL primitive definitions | StrategyAST, Expression, 40+ primitives |
| File Path | Coverage |
|---|---|
| packages/be/src/algorithms/backtest/engine.test.ts | 7 e2e tests: user DSL, AI-translated, AI auto-built |
| packages/be/src/backtest/metrics.test.ts | 31 unit tests: pure math functions |
| packages/be/src/algorithms/backtest/garch.test.ts | GARCH volatility model tests |
| packages/be/src/algorithms/backtest/hurst.test.ts | Hurst exponent calculation tests |
| packages/be/src/algorithms/backtest/factor-attribution.test.ts | Alpha, beta, R-squared tests |