Technical Reference
Non-technical technical reference for Torq architecture, APIs, schemas, contracts, events, indexers, GraphQL, and background jobs.
This page explains the technical system without assuming the reader can read code.
The most important rule is:
Chain -> Indexer -> Projector -> Postgres -> API -> FrontendThat rule means the app should show shared protocol state only after it has passed through the canonical read model.
Architecture stack
Protocol, data, API, and workspaces stay separate
Technical posture
Many DeFi frontends read contracts, index events, and show market state. Torq's technical design is stricter for shared state: the frontend should not reconstruct protocol truth for investor, operator, or admin views. The technical product is a controlled credit facility operating system with contracts, indexers, projectors, API surfaces, role workspaces, and post-write verification.
Architecture
| Layer | Plain meaning | Source evidence |
|---|---|---|
| Contracts | Value-moving runtime and authority rules. | protocol/contracts/** and active V2 contract inventory. |
| Indexer | Watches chain and runtime events. | services/indexer/data/indexer/**. |
| Projectors | Convert observed events into current-state rows. | services/indexer/data/indexer/projectors/**. |
| Postgres | Stores canonical application truth. | services/indexer/data/migrations/**. |
| APIs | Serve persisted state and controlled mutation surfaces. | services/indexer/api/** and GraphQL schema files. |
| Frontend | Role-specific workspaces that consume API state. | apps/web/src/app/router.tsx and workspace pages. |
| Docs | Product manual and generated source map. | apps/docs/content/docs/**. |
APIs
| API group | What it does |
|---|---|
| Public GraphQL | Serves read-oriented product state from Postgres. |
| Operator GraphQL | Serves operator and workspace mutation/read surfaces with stronger auth expectations. |
| Tracked mutation progress | Reports post-write execution and projection progress. |
| Wallet-flow health | Helps diagnose wallet execution path readiness. |
| Workspace messages | Supports messages, replies, amendments, target selection, and expiry. |
| Faucet ETH claim | Supports local/test funding flows. |
| Quicknode streams | Receives stream events where configured. |
| Agent credit | Provides borrower-route inputs for supported borrow and repay flows. |
Database schema
Torq uses Postgres current-state and support tables to hold application truth. Migration files in
services/indexer/data/migrations/** define the schema history.
Plain examples of table families:
- vault current state
- market current state
- borrower debt and partition state
- asset policy and registry rows
- oracle and NAV report rows
- permission and role rows
- tracked mutation progress
- workspace messages
- accounting and reconciliation evidence
Smart contracts
The active V2 inventory includes:
| Contract group | Examples |
|---|---|
| Core runtime | TorqSharedCreditMarketV2, shared market execution modules, TorqVaultKernelMultiVaultV2, vault kernel modules, TorqVaultMarketRegistryV2. |
| Governance and permissions | ProtocolManagerGateV2, ProtocolPermissionManager, ScopedEntityAuthority, ScopedWorkspaceTimelockExecutor, TorqTimelock, wallet compliance policy. |
| Oracles and valuation | SignedNavAdapterV2, SingleFeedAdapterV2, SupplyAwareSingleFeedAdapterV2, PairMultiHopAdapterV2, ConservativeMinAdapterV2, TorqOracleFactory. |
| Interest rate models | Adaptive, capped, staged, and factory/deployer contracts. |
| Partner | Vault partner manager and wrapper contracts. |
| Tranche and tokens | Tranche share token and supporting types/libraries. |
Events
Events are contract or service records that say something happened. Torq uses events and snapshots so projectors can update Postgres.
Examples:
- vault deposit or redemption activity
- borrow, repay, collateral, or liquidation activity
- oracle or NAV updates
- role, permission, or timelock activity
- market and vault configuration changes
Indexers
The indexer observes state, then projectors write deterministic current rows. A deterministic projector should give the same answer when replayed over the same inputs.
Why this matters: if every workspace uses the same projected rows, the lender, borrower, operator, and auditor can discuss one state instead of comparing different screens.
Truth path
Shared protocol state has one route into the product
V2 events and state
Ingestion and snapshots
Domain-owned derivation
Canonical app truth
Served read model
Role-specific view
GraphQL
GraphQL is the API language Torq uses for many read and operator surfaces. In Torq, GraphQL is not the root truth source for shared protocol fields. It is a serving layer over Postgres.
Background jobs
| Job family | Purpose |
|---|---|
| Snapshot indexing | Keeps projected state current. |
| Live-feed relay | Moves external feed data into supported paths. |
| Contract verification | Tracks deployed contract verification state. |
| Workspace message expiry | Maintains message lifecycle. |
| AI allocator | Supports allocator assistance where configured. |
| Projection repair or follow-up | Helps reconcile pending tracked mutations. |
File-size and release checks
The web app has a file-size budget and Preline/design-system gates for frontend runtime work. The manual documents these as operator/developer fields because docs and UI can otherwise drift away from the actual product.
For reviewers
Use Generated Source Map and Coverage Report for the current route, surface, action, API, schema, contract, accounting, and governance evidence used by this manual.