rmi-backend/ARCHITECTURE.md

2.7 KiB

RMI Backend — Architecture

Status: canonical Last updated: 2026-07-07

Overview

FastAPI monolith serving crypto risk intelligence via HTTP, Telegram, and MCP. Domains are consolidated under app/domains/ per AUDIT-2026-Q3 Phase 4.

High-level flow

Client (Web / Telegram / AI Agent)
    ↓
nginx → rmi-backend container (:8000)
    ↓
FastAPI routers (mounted by app/mount.py)
    ↓
app/domains/<domain>/service.py  →  app/infra/ + app/domains/<domain>/repository.py
    ↓
Postgres / Redis / Qdrant / Neo4j / ClickHouse

Components

Path Purpose
app/factory.py FastAPI app factory (lifespan, middleware, error handlers, routers)
app/mount.py Single source of truth for router mounting
app/core/ Cross-cutting concerns (logging, errors, redis, http, auth, config)
app/api/v1/ Thin HTTP transport layer (public, auth, admin, x402, mcp)
app/domains/ Business logic domains: auth, billing, databus, news, reports, scanner, scanners, telegram, threat, token, tokens, wallet, x402
app/domains/scanners/ Token risk scanners (IP — will move to rmi-ip in Phase 6)
app/domains/databus/ 30+ third-party data provider integrations
app/domains/telegram/rugmunchbot/ Telegram bot command handlers
app/mcp/ MCP manifest and tool manager
app/infra/ External integrations (ollama, langfuse, vector stores, chain clients)
app/wallet_memory/ Wallet label + clustering subsystem (IP — will move to rmi-ip in Phase 6)
app/routers/ Legacy HTTP route handlers (being migrated to app/domains/ or app/api/v1/)

Storage

Store Use Container / Host
Postgres Primary OLTP, Ponder indexer data rmi-postgres
Redis Cache, Celery queue rmi-redis
Qdrant Vector embeddings rmi-qdrant
Neo4j Wallet graph / labels rmi-neo4j
ClickHouse Analytics, 39M address labels rmi-clickhouse

Interfaces

Endpoint Purpose
GET /health Health check (degraded — ETH RPC endpoint missing)
GET /metrics Prometheus metrics
GET /docs Swagger/OpenAPI docs
POST /scanner/scan Live token scan
POST /mcp/... MCP tool endpoints

Current issues

  • app/routers/x402_tools.py (212 KB) and app/routers/x402_enforcement.py (108 KB) violate the 500-line limit and should become separate services or split by domain.
  • sqlite3 is used in 5 files for local state; should migrate to Postgres/aiosqlite.
  • F-string logs and print() statements prevent structured log aggregation.
  • mypy has a structural issue with app/domains/auth/ that needs resolution.

Deployment

ssh netcup
cd /root/backend/
docker compose pull
docker compose up -d rmi-backend