Workspace Structure
The backend uses a Rust workspace — a collection of related packages (called "crates") that are compiled together. Each crate has a specific responsibility.
Crates
apps/server — Application Entry Point
The main binary. Responsible for:
- Loading configuration (from files or environment variables)
- Starting the Axum HTTP server
- Launching background workers on their schedules
- Initializing database connections
This is the only crate that produces a runnable binary. Everything else is a library.
crates/api — Internal API (unused)
Contains HTTP route definitions built with Axum/Utoipa. This crate exists in the workspace but is not used in production — the frontend queries the shared PostgreSQL database directly via Prisma instead of going through a backend API.
crates/workers — DeFi Indexing Engine
The largest and most complex crate. Contains:
- Protocol services — one service per DeFi protocol (Uniswap, Aave, Morpho, etc.)
- External API clients — HTTP clients for Krystal, CoinGecko, Yearn, etc.
- Position coordinator — orchestrates position detection and valuation
- Scraping utilities — headless Chrome for dynamic data (Morpho)
Each protocol service follows the same pattern: fetch data, transform it, store it.
crates/storage — Database Layer
Contains 43 SeaORM entity definitions and repository implementations.
| Folder | Purpose |
|---|---|
entities/ |
Database table definitions (one file per table) |
repositories/ |
Query logic (find, create, update) |
migrations/ |
Referenced from migrations/pg/ |
crates/types — Shared Types
Enums, structs, and constants used across multiple crates. Includes:
- Protocol identifiers (Uniswap, Aave, etc.)
- Chain identifiers (Base, Ethereum, etc.)
- Common DeFi types (token amounts, addresses)
crates/channels — Inter-Service Messaging
Message passing primitives for communication between workers. Uses Tokio channels for async messaging within the application.
crates/math — DeFi Calculations
Mathematical utilities for:
- Concentrated liquidity calculations (tick math, sqrtPrice)
- APY/APR computations
- Decimal precision handling (via
rust_decimal)
Dependency Graph
apps/server
├── crates/api
│ ├── crates/storage
│ ├── crates/types
│ └── crates/channels
├── crates/workers
│ ├── crates/storage
│ ├── crates/types
│ ├── crates/math
│ └── crates/channels
└── (config, scheduler)
The api and workers crates are siblings — they don't depend on each other. They share data through the database and through channels.