Skip to content

docs: Add comprehensive UML architecture documentation for Criptotrade#67

Merged
danzeroum merged 3 commits into
masterfrom
claude/uml-analysis-multilang-emp0n3
Jul 13, 2026
Merged

docs: Add comprehensive UML architecture documentation for Criptotrade#67
danzeroum merged 3 commits into
masterfrom
claude/uml-analysis-multilang-emp0n3

Conversation

@danzeroum

Copy link
Copy Markdown
Owner

Summary

This PR adds a comprehensive architectural documentation file (docs/uml/arquitetura-uml.md) that provides a complete analysis of the Criptotrade platform's structure, design patterns, and system interactions. The document serves as a reference guide for understanding the codebase organization, dependencies, and data flows across the Python backend, React frontend, and supporting infrastructure.

Key Changes

  • Structural mapping: Documents the complete directory hierarchy with responsibility assignments for each module (agents, orchestration, strategies, analysis, backtest, API, etc.)
  • System boundaries and communication: Details the two-process architecture (API + orchestrator loop) communicating via SQLite WAL and append-only JSONL files
  • Dependency analysis: Catalogs external dependencies by language (Python, React, TypeScript) and their roles in the system
  • Use case diagram: Maps actors (operator, orchestrator, exchange, LLM) and their interactions with the system
  • Package diagram: Shows logical organization and directed dependencies between modules, highlighting the presentation → application → domain → infrastructure layering
  • Component diagram: Illustrates runtime topology (nginx, FastAPI, orchestrator loop, SQLite, external services)
  • Class diagrams by layer: Detailed breakdowns of:
    • Agent hierarchy and specialization (Strategy, Risk, Execution agents)
    • Orchestration pipeline (SquadOrchestrator, CircuitBreaker, PositionStore)
    • Strategy pattern and technical analysis components
    • Backtest and evaluation engines
    • Core infrastructure (ledger, metrics, exchange client, alerts, LLM)
    • Risk management and guardrails
    • HITL (Human-in-the-Loop) order management and API contracts
    • Frontend React component structure
  • Sequence diagrams: Shows temporal flows for:
    • Main trading cycle (analyze → strategy → risk → HITL → execution → ledger)
    • Cross-process HITL approval coordination via SQLite
    • Asynchronous backtest job execution
  • Activity diagrams: Illustrates decision workflows for signal generation and circuit breaker logic
  • Deployment diagram: Documents containerized production topology with nginx, FastAPI, orchestrator, and shared state volumes

Notable Implementation Details

  • Identifies architectural patterns: Strategy pattern for trading strategies, Event Sourcing for ledger, Pub/Sub for alerts, Template Method for agent execution
  • Highlights design decisions: fail-safe defaults (dry-run mode, graceful LLM degradation), cross-process coordination via SQLite WAL, append-only event log for auditability
  • Documents known issues and improvement opportunities:
    • Duplicate class names (ContinuousEvaluator, AdaptivePlanner, SquadOrchestrator)
    • Two disconnected agent base classes (BaseAgent vs SafeAgentBase)
    • Unused "BuildToValue" orchestration cluster (planning/routing/consensus)
    • Redundant order validation logic
    • Potential for Kelly criterion integration in position sizing
  • Clarifies the multi-language composition: Python-centric (168 files, ~18.7k LOC) with React frontend and TypeScript contract generation, no Rust code present
  • Explains the HITL gate mechanism: auto-approval below threshold, human approval above, 300s timeout with fail-closed cancellation

https://claude.ai/code/session_017hpSLazvYy2mPm4QhR9B3r

claude added 3 commits July 12, 2026 23:52
Recursive static analysis of the whole repository producing 18 UML
diagrams (Mermaid + PlantUML): use case, packages, components, 8 layered
class diagrams, 3 sequence diagrams, 2 activity flowcharts, HITL order
state machine, and deployment. Documents the trading pipeline
(Strategy->Risk->Guardrails->HITL->Execution), the cross-process HITL
bridge over SQLite, the OpenAPI/openapi.d.ts contract linking the Python
backend and React console, and infra spine (ledger/db/metrics/exchange).

Includes traceability table (entity -> source file) and an architecture
critique covering cohesion/coupling and refactoring opportunities
(duplicate class names, the unused BuildToValue orchestration cluster,
two agent base hierarchies, redundant order-validation policies).

Notes the actual repo composition (Python-centric; React/JSX console;
one generated TS contract file; no Rust) and adapts the requested
multi-language methodology accordingly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017hpSLazvYy2mPm4QhR9B3r
Complements the class-level UML doc with an architecture-level view of
the entire repository, using the C4 model plus supporting views:

- C4 L1 System Context, L2 Containers, L3 Components (API + Loop)
- Data architecture: ERD from migrations (orders, open_positions,
  circuit_breaker_state, cycle_events, backtest_jobs, journal_entries,
  ledger_events) + append-only file stores (ledger/XES/alerts/memory)
- Data flow (signal -> order -> fill -> metrics), runtime/process view
- Deployment topologies (dev, prod self-contained, VPS gateway)
- CI/CD pipeline (Python CI + phase validation, OpenAPI drift gate)
- Observability (Prometheus/Grafana, structured logs, XES process
  mining, SSE alerts) and security (network isolation, auth, guardrails,
  sandbox, secrets)
- Architecture recommendations with a prioritized findings table and a
  proposed incremental target-state diagram

All diagrams in Mermaid, validated for balanced fences/braces.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017hpSLazvYy2mPm4QhR9B3r
Maps every data element that flows through the whole repository — inputs,
outputs, intermediate/state, and persisted data — across all languages
present (Python, JSX/JS, the generated TypeScript contract, HTML, SQL,
YAML, .env, Docker). Notes explicitly that no Rust code exists.

Contents:
- Env-var inventory (defaults, coercion, consumers) and YAML policy config
- Persisted data: every SQL table/column + JSONL/JSON stores + the ledger
  event-store payload schema per event_type (the XES process log)
- Canonical in-transit structures: the task/analysis/signal/market_data
  (both shapes)/strategy_result/risk_result/execution_result/Order dicts
  with exact keys and file:line
- Per-module data catalog (agents, orchestration, strategies, analysis,
  backtest, risk, safety, core, hitl, memory, journal, tools, evaluation,
  consensus/routing/planning, protocols, utils)
- API layer: DTOs, route I/O, middleware data; frontend CT_API + mock +
  per-screen state; the openapi.d.ts transversal contract
- End-to-end lifecycle trace of a signal -> order -> fill -> metric
- "Data lost in the class" (assigned-but-never-read) section, as requested
- Data anomalies (two market_data shapes, entry->entry_price bridge,
  mean_reversion never selected, ab_tests.jsonl not valid JSON, etc.)

Docs only; no source code changed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017hpSLazvYy2mPm4QhR9B3r
@danzeroum danzeroum merged commit 1cfd1f7 into master Jul 13, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants