# thanhdatttt/cryptox architecture

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

- Interactive diagram: https://gitdiagram.com/thanhdatttt/cryptox
- Repository: https://github.com/thanhdatttt/cryptox

## Overview

#### Purpose and maturity
Cryptox is an educational crypto-strategy laboratory focused on extensible strategy authoring, market/news inputs, bounded backtesting, evaluation, and ranking. It is a TypeScript monorepo targeting a synchronous modular monolith. Current source is largely a scaffold: module APIs and composition points exist, but most business behavior is unimplemented and no end-to-end product flow is verified.

#### Runtime entry points and composition
The backend is the primary server composition boundary: `apps/backend/src/main.ts` starts it, while `apps/backend/src/app.module.ts` and `apps/backend/src/compose.ts` assemble application dependencies. The frontend is a separate Vite client entry at `apps/frontend/src/main.tsx`, with HTML bootstrap in `apps/frontend/index.html`; it remains a placeholder. Module-local `api/bootstrap.ts` files are intended to construct public in-process module APIs.

#### Module-first boundaries
Business capabilities are isolated under `modules/`, conventionally split into `domain`, `application`, `infrastructure`, and public `api` layers. Consumers should use public APIs rather than internal layers, exemplified by `modules/strategy/api/index.ts`, `modules/market-data/api/index.ts`, and `modules/backtesting/api/index.ts`. Shared transport contracts are outside business modules in `packages/contracts/rest/index.ts` and `packages/contracts/websocket/index.ts`, preventing transport types from becoming module internals.

#### Strategy and input pipeline
The intended workflow begins with market data, news, and sentiment inputs. Market-data exposes snapshot-oriented access through `modules/market-data/api/snapshot-reader.ts` and its API bootstrap. News and sentiment are separate modules with application ports (`modules/news/application/ports.ts`, `modules/sentiment/application/ports.ts`), supporting provider isolation and failure containment. Strategy definitions and extension points belong to `modules/strategy/domain/contracts.ts` and `modules/strategy/application/ports.ts`, which should consume these capabilities through their published APIs.

#### Backtest execution boundary
Backtesting is explicitly bounded and local for MVP. Its application defines replaceable dependencies in `modules/backtesting/application/ports.ts`; the approved concrete executor is `modules/backtesting/infrastructure/local/bounded-local-backtest-executor.ts`. The public adapter resides in `modules/backtesting/api/index.ts`. This boundary permits a future worker/queue implementation without changing strategy-facing or API-facing contracts; distributed queues are not part of the approved runtime.

#### Results, evaluation, and leaderboard
Backtest outputs flow into evaluation and then ranking. Evaluation owns its domain contract and public boundary in `modules/evaluation/domain/contracts.ts` and `modules/evaluation/api/index.ts`. Leaderboard owns ranking-facing contracts and ports in `modules/leaderboard/domain/contracts.ts` and `modules/leaderboard/application/ports.ts`. Search is a separate query capability rather than a cross-module persistence concern, exposed through `modules/search/api/index.ts`.

#### Transport, infrastructure, and constraints
REST is the command/query transport; WebSocket is reserved for realtime market-data delivery, with message shapes in `packages/contracts/websocket/market-data.ts`. Local infrastructure includes PostgreSQL-oriented migrations at `infra/db/migrations/001_enable_pgcrypto.js` and Docker composition in `infra/docker-compose.yml`. No authentication, multitenancy, LLM integration, Redis/BullMQ, microservices, Kafka, CQRS, or event sourcing is approved for MVP. Architecture intent and dependency direction are governed by `docs/architecture.md` and validated in part by `scripts/check-architecture-rules.mjs`.

Main entry points: [`modules/strategy/api/index.ts`](https://github.com/thanhdatttt/cryptox/blob/main/modules/strategy/api/index.ts) (Strategy API), [`apps/backend/src/compose.ts`](https://github.com/thanhdatttt/cryptox/blob/main/apps/backend/src/compose.ts) (Backend composition), [`modules/backtesting/api/index.ts`](https://github.com/thanhdatttt/cryptox/blob/main/modules/backtesting/api/index.ts) (Backtesting API), [`apps/backend/src/main.ts`](https://github.com/thanhdatttt/cryptox/blob/main/apps/backend/src/main.ts) (Backend server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_frontend["Vite frontend<br/>client placeholder<br/>[main.tsx]"]
  node_backend["Backend server<br/>composition runtime<br/>[main.ts]"]
  node_backend_composition{{"Backend composition<br/>dependency assembly<br/>[compose.ts]"}}
end

subgraph group_inputs["Input modules"]
  node_market_data["Market data API<br/>module public API<br/>[snapshot-reader.ts]"]
  node_news["News module<br/>provider-isolated input<br/>[ports.ts]"]
  node_sentiment["Sentiment module<br/>provider-isolated input<br/>[ports.ts]"]
end

subgraph group_core["Strategy pipeline"]
  node_strategy["Strategy API<br/>module public API<br/>[index.ts]"]
  node_strategy_contracts["Strategy contracts<br/>domain and application ports<br/>[contracts.ts]"]
  node_backtesting["Backtesting API<br/>module public API<br/>[index.ts]"]
  node_local_executor["Bounded local executor<br/>local backtest executor"]
end

subgraph group_outputs["Results and discovery"]
  node_evaluation["Evaluation API<br/>module public API<br/>[index.ts]"]
  node_leaderboard["Leaderboard ports<br/>ranking boundary<br/>[ports.ts]"]
  node_search["Search API<br/>query module API<br/>[index.ts]"]
end

subgraph group_platform["Transport and local platform"]
  node_rest_contracts["REST contracts<br/>shared transport contracts<br/>[index.ts]"]
  node_websocket_contracts["Market-data WS contracts<br/>realtime message contracts<br/>[market-data.ts]"]
  node_postgres[("PostgreSQL migrations<br/>local database schema")]
  node_architecture_rules["Architecture rules<br/>dependency validation"]
end

node_frontend -->|"REST commands and queries"| node_backend
node_backend -->|"starts"| node_backend_composition
node_backend_composition -->|"wires"| node_strategy
node_backend_composition -->|"wires"| node_backtesting
node_backend_composition -->|"wires"| node_evaluation
node_backend_composition -->|"wires"| node_leaderboard
node_backend_composition -->|"wires"| node_search
node_backend -->|"uses"| node_rest_contracts
node_market_data -->|"realtime delivery shapes"| node_websocket_contracts
node_strategy -->|"publishes"| node_strategy_contracts
node_strategy -->|"reads snapshots"| node_market_data
node_strategy -->|"consumes published API"| node_news
node_strategy -->|"consumes published API"| node_sentiment
node_strategy -->|"submits strategy"| node_backtesting
node_backtesting -->|"delegates execution"| node_local_executor
node_local_executor -.->|"uses local persistence"| node_postgres
node_backtesting -->|"emits results"| node_evaluation
node_evaluation -->|"provides evaluated results"| node_leaderboard
node_leaderboard -->|"exposes ranked results"| node_search
node_architecture_rules -.->|"validates boundaries"| node_strategy
node_architecture_rules -.->|"validates boundaries"| node_backtesting

click node_frontend "https://github.com/thanhdatttt/cryptox/blob/main/apps/frontend/src/main.tsx"
click node_backend "https://github.com/thanhdatttt/cryptox/blob/main/apps/backend/src/main.ts"
click node_backend_composition "https://github.com/thanhdatttt/cryptox/blob/main/apps/backend/src/compose.ts"
click node_market_data "https://github.com/thanhdatttt/cryptox/blob/main/modules/market-data/api/snapshot-reader.ts"
click node_news "https://github.com/thanhdatttt/cryptox/blob/main/modules/news/application/ports.ts"
click node_sentiment "https://github.com/thanhdatttt/cryptox/blob/main/modules/sentiment/application/ports.ts"
click node_strategy "https://github.com/thanhdatttt/cryptox/blob/main/modules/strategy/api/index.ts"
click node_strategy_contracts "https://github.com/thanhdatttt/cryptox/blob/main/modules/strategy/domain/contracts.ts"
click node_backtesting "https://github.com/thanhdatttt/cryptox/blob/main/modules/backtesting/api/index.ts"
click node_local_executor "https://github.com/thanhdatttt/cryptox/blob/main/modules/backtesting/infrastructure/local/bounded-local-backtest-executor.ts"
click node_evaluation "https://github.com/thanhdatttt/cryptox/blob/main/modules/evaluation/api/index.ts"
click node_leaderboard "https://github.com/thanhdatttt/cryptox/blob/main/modules/leaderboard/application/ports.ts"
click node_search "https://github.com/thanhdatttt/cryptox/blob/main/modules/search/api/index.ts"
click node_rest_contracts "https://github.com/thanhdatttt/cryptox/blob/main/packages/contracts/rest/index.ts"
click node_websocket_contracts "https://github.com/thanhdatttt/cryptox/blob/main/packages/contracts/websocket/market-data.ts"
click node_postgres "https://github.com/thanhdatttt/cryptox/blob/main/infra/db/migrations/001_enable_pgcrypto.js"
click node_architecture_rules "https://github.com/thanhdatttt/cryptox/blob/main/scripts/check-architecture-rules.mjs"

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_frontend,node_backend,node_backend_composition toneBlue
class node_market_data,node_news,node_sentiment toneAmber
class node_strategy,node_strategy_contracts,node_backtesting,node_local_executor toneMint
class node_evaluation,node_leaderboard,node_search toneRose
class node_rest_contracts,node_websocket_contracts,node_postgres,node_architecture_rules toneIndigo
```

## Components

### Runtime

- [Vite frontend](https://github.com/thanhdatttt/cryptox/blob/main/apps/frontend/src/main.tsx): client placeholder · Separate placeholder client. · `apps/frontend/src/main.tsx`
- [Backend server](https://github.com/thanhdatttt/cryptox/blob/main/apps/backend/src/main.ts): composition runtime · Primary synchronous application host. · `apps/backend/src/main.ts`
- [Backend composition](https://github.com/thanhdatttt/cryptox/blob/main/apps/backend/src/compose.ts): dependency assembly · `apps/backend/src/compose.ts`

### Input modules

- [Market data API](https://github.com/thanhdatttt/cryptox/blob/main/modules/market-data/api/snapshot-reader.ts): module public API · Publishes snapshot-oriented market access. · `modules/market-data/api/snapshot-reader.ts`
- [News module](https://github.com/thanhdatttt/cryptox/blob/main/modules/news/application/ports.ts): provider-isolated input · `modules/news/application/ports.ts`
- [Sentiment module](https://github.com/thanhdatttt/cryptox/blob/main/modules/sentiment/application/ports.ts): provider-isolated input · `modules/sentiment/application/ports.ts`

### Strategy pipeline

- [Strategy API](https://github.com/thanhdatttt/cryptox/blob/main/modules/strategy/api/index.ts): module public API · Strategy definitions and extensions consume published inputs. · `modules/strategy/api/index.ts`
- [Strategy contracts](https://github.com/thanhdatttt/cryptox/blob/main/modules/strategy/domain/contracts.ts): domain and application ports · `modules/strategy/domain/contracts.ts`
- [Backtesting API](https://github.com/thanhdatttt/cryptox/blob/main/modules/backtesting/api/index.ts): module public API · Stable boundary for backtest requests and results. · `modules/backtesting/api/index.ts`
- [Bounded local executor](https://github.com/thanhdatttt/cryptox/blob/main/modules/backtesting/infrastructure/local/bounded-local-backtest-executor.ts): local backtest executor · Approved MVP execution implementation. · `modules/backtesting/infrastructure/local/bounded-local-backtest-executor.ts`

### Results and discovery

- [Evaluation API](https://github.com/thanhdatttt/cryptox/blob/main/modules/evaluation/api/index.ts): module public API · `modules/evaluation/api/index.ts`
- [Leaderboard ports](https://github.com/thanhdatttt/cryptox/blob/main/modules/leaderboard/application/ports.ts): ranking boundary · `modules/leaderboard/application/ports.ts`
- [Search API](https://github.com/thanhdatttt/cryptox/blob/main/modules/search/api/index.ts): query module API · Separate discovery capability. · `modules/search/api/index.ts`

### Transport and local platform

- [REST contracts](https://github.com/thanhdatttt/cryptox/blob/main/packages/contracts/rest/index.ts): shared transport contracts · `packages/contracts/rest/index.ts`
- [Market-data WS contracts](https://github.com/thanhdatttt/cryptox/blob/main/packages/contracts/websocket/market-data.ts): realtime message contracts · `packages/contracts/websocket/market-data.ts`
- [PostgreSQL migrations](https://github.com/thanhdatttt/cryptox/blob/main/infra/db/migrations/001_enable_pgcrypto.js): local database schema · `infra/db/migrations/001_enable_pgcrypto.js`
- [Architecture rules](https://github.com/thanhdatttt/cryptox/blob/main/scripts/check-architecture-rules.mjs): dependency validation · Enforces intended dependency direction. · `scripts/check-architecture-rules.mjs`

## Connections

- Vite frontend → Backend server: REST commands and queries
- Backend server → Backend composition: starts
- Backend composition → Strategy API: wires
- Backend composition → Backtesting API: wires
- Backend composition → Evaluation API: wires
- Backend composition → Leaderboard ports: wires
- Backend composition → Search API: wires
- Backend server → REST contracts: uses
- Market data API → Market-data WS contracts: realtime delivery shapes
- Strategy API → Strategy contracts: publishes
- Strategy API → Market data API: reads snapshots
- Strategy API → News module: consumes published API
- Strategy API → Sentiment module: consumes published API
- Strategy API → Backtesting API: submits strategy
- Backtesting API → Bounded local executor: delegates execution
- Bounded local executor → PostgreSQL migrations: uses local persistence
- Backtesting API → Evaluation API: emits results
- Evaluation API → Leaderboard ports: provides evaluated results
- Leaderboard ports → Search API: exposes ranked results
- Architecture rules → Strategy API: validates boundaries
- Architecture rules → Backtesting API: validates boundaries
