System Architecture
Overview
CHAIN-R is a privacy-first LLM-as-a-service platform. The system is fully containerised and follows a layered microservice architecture where nginx is the only publicly exposed endpoint.
Container Topology
Internet
↓
[nginx:8000] ←──────────────── ONLY EXPOSED PORT
↓
frontend-network
↓
[fe-public] [fe-core]
↓
(nginx virtual-host proxy)
↓
bff-network
↓
[svc-auth] [svc-bff]
↓ ↓
[redis] backend-network
↓
[svc-core] [svc-ai]
↓ ↓
db-network ai-network (internal)
↓ ↓
[postgres-core] [postgres-ai]
[qdrant]
[minio]
[docling]
graph-db-network (internal)
↓
[neo4j] ←── (svc-core)
file-storage-network (internal)
↓
[minio] [qdrant] [docling] ←── (svc-core)
ai-egress-network
↓
[Amazon Bedrock, web search, pages, tools] ←── (svc-ai only)
feed-egress-network
↓
[dashboard feed publishers] ←── (svc-core only)
Virtual Hosts
All traffic enters on port 8000 and is routed by nginx hostname:
| Host | Destination | Notes |
|---|---|---|
app.dev.datachainr.com | fe-core + svc-bff for /api/* | Session-gated via auth_request |
auth.dev.datachainr.com | svc-auth | OAuth2 / Auth0 flow endpoints |
Services
Edge & Routing
| Service | Purpose |
|---|
Frontend
| Service | Purpose |
|---|---|
| fe-public | Public-facing React app — marketing and Auth0 login redirect |
Backend
| Service | Purpose |
|---|---|
| svc-bff | Backend-for-Frontend — proxies authenticated frontend requests to svc-core with injected identity headers |
| svc-core | Core business logic, resource CRUD, conversation persistence, orchestration of AI operations |
| svc-ai | LLM execution (LiteLLM), multi-agent graphs (LangGraph), RAG, streaming SSE, simulation |
Data & Storage
| Service | Purpose |
|---|---|
| postgres-core | Relational database for svc-core (agents, knowledge, conversations, etc.) |
| postgres-ai | Relational database for svc-ai (model/provider registry, LLM invocations) |
| neo4j | Graph knowledge bases |
| qdrant | Vector database for RAG (semantic search over knowledge documents) |
| minio | S3-compatible object storage for knowledge base documents |
| docling | Document parsing service (PDF, DOCX → structured text) |
Request Flow
Unauthenticated Request
Browser → nginx (app.dev.datachainr.com)
→ auth_request → svc-auth /verify → 401
→ nginx redirects to svc-auth /login
→ svc-auth → Auth0 /authorize
→ Auth0 → svc-auth /callback
→ svc-auth stores tokens in Redis, sets HTTP-only session cookie
→ redirect to app
Authenticated API Request
Browser → nginx (app.dev.datachainr.com/api/*)
→ auth_request → svc-auth /verify → 200 (X-User-Id, X-Session-Id)
→ nginx → svc-bff
→ svc-bff reads access_token from Redis, injects identity headers + mints internal JWT
→ svc-bff → svc-core (Authorization: Bearer <token>, X-Internal-Token, X-User-Id, X-User-Email)
→ svc-core verifies X-Internal-Token, mints aud=svc-ai token
→ svc-core → svc-ai (for LLM execution / model registry; svc-ai verifies X-Internal-Token)
LLM Streaming
Browser (EventSource) → svc-bff /ws/* → svc-core → svc-ai
→ svc-ai streams SSE frames: status → token → token → done
→ svc-core streams through to svc-bff → nginx → browser
Network Segments
| Network | Members |
|---|---|
bff-network | nginx, svc-auth, svc-bff, redis |
backend-network | svc-bff, svc-core, svc-ai |
db-network | svc-core, postgres-core |
ai-network | svc-ai, postgres-ai, qdrant, minio, docling, neo4j |
graph-db-network | svc-core, neo4j |
file-storage-network | svc-core, minio, qdrant, docling |
ai-egress-network | svc-ai (outbound: Amazon Bedrock, web search, page and feed fetches, tools) |
feed-egress-network | svc-core (outbound: dashboard feed publishers) |
Authentication
Auth0 is the identity provider. No local username/password system exists.
Tokens (access + refresh) are stored server-side in Redis only — the browser never sees them.
The browser holds a signed HTTP-only session cookie containing only a session ID.
nginx enforces authentication via
auth_requeston every request toapp.dev.datachainr.combefore the request reaches svc-bff.svc-core maintains a local
userstable as a mirror of Auth0 identity, keyed onauth0_id, for relational resource ownership.
See security/auth-flow.md for the detailed login, verify, and logout flows.
Database Ownership
Each service owns its database exclusively — no cross-database foreign keys. Inter-service data access is via API calls only.
| Service | Database | Status |
|---|---|---|
| svc-ai | postgres-ai | In place |
| svc-auth | (dedicated Postgres planned) | Not yet added |
| svc-bff | (dedicated Postgres planned) | Not yet added |
See data/schema.md for the full entity breakdown per service.