CHAIN-R
Privacy- and sovereignty-focused LLMs-as-a-service.
Democratising AI automation, security, and compliance — orchestrate your LLM fleet, enforce governance, and integrate intelligent agents into your own systems.
Setup · Architecture · Services · Development · Documentation
Overview
CHAIN-R is a full-stack, fully-containerised platform that lets users, developers, and organisations build, manage, and customise AI agents, tools, and multi-agent graphs — with security, privacy, and regulatory compliance built in from the ground up.
Orchestrate your LLM fleet — manage, monitor, and connect intelligent agents.
Ensure compliance & security — protect encrypted data flows across your network with granular access controls, audit trails, and provider-agnostic egress.
Integrate into your own systems — drive your LLMs through the CHAIN-R API with custom network configurations.
The platform exposes a rich domain model covering agents, models, conversations, knowledge bases, skills, workers, tools, evaluations, simulations, MCP servers, organisations, and projects — backed by LiteLLM for provider abstraction and LangGraph for multi-agent workflow execution.
Status: the core feature set is implemented and integrated end-to-end. See the roadmap for outstanding work and planned phases.
🧱 Tech Stack
| Layer | Technologies |
|---|---|
| Backend | Python 3.12 · FastAPI · Uvicorn · Pydantic v2 · SQLAlchemy 2 · Alembic |
| AI | LiteLLM · LangChain · LangGraph · LlamaIndex · OpenAI / Anthropic providers |
| Data | PostgreSQL 16 · Redis 7 · Neo4j 5 (graph) · Qdrant (vectors) · MinIO (object store) · Docling (document parsing) |
| Auth | Auth0 OAuth2 · server-side token storage · signed HTTP-only session cookies |
| Infra | Docker Compose · nginx (reverse proxy + virtual hosts) · isolated bridge networks |
| Observability | Grafana · Prometheus · Loki · Promtail · Tempo (OTLP traces) · cAdvisor · node-exporter |
| Tooling | uv (Python) · npm workspaces (JS/TS) · Make · VS Code Dev Containers · pre-commit · Ruff · Bandit · Pytest · Vitest |
🏛 Architecture
Serving architecture
nginx is the only host-exposed port (:8000). Every other service lives on one or more internal Docker networks, segmented by trust boundary. Traffic is routed by virtual host, and the authenticated app surface is session-gated at the proxy via nginx auth_request.
Internet
│
┌──────────▼──────────┐
│ nginx :8000 │ ← ONLY EXPOSED PORT
└──────────┬──────────┘
┌───────────────────┼────────────────────┐
dev.datachainr.com app.dev.datachainr.com auth.dev.datachainr.com
│ │ (auth_request) │
┌──────▼─────┐ ┌──────▼─────┐ │
│ fe-public │ │ fe-core │ │
└────────────┘ └──────┬─────┘ │
│ /api/* │
┌───────────▼───────────┐ ┌───────▼───────┐
│ svc-bff │◄───┤ svc-auth │
│ (BFF / proxy + JWT) │ │ (OAuth2) │
└───────────┬───────────┘ └───────┬───────┘
│ │
┌────────▼────────┐ ┌─────▼─────┐
│ svc-core │ │ redis │
│ (domain / CRUD) │ │ (sessions)│
└───┬────────┬────┘ └───────────┘
┌─────────────┘ └──────────────┐
┌─────▼─────┐ ┌─────▼──────┐
│ postgres- │ │ svc-ai │
│ core │ │ (LiteLLM / │
└───────────┘ │ LangGraph) │
└─────┬──────┘
┌──────────────┬──────────────┼───────────────┐
┌─────▼────┐ ┌─────▼────┐ ┌──────▼─────┐ ┌─────▼──────┐
│ postgres-│ │ qdrant │ │ neo4j │ │ minio │
│ ai │ │ (vectors)│ │ (graph) │ │ docling │
└──────────┘ └──────────┘ └────────────┘ └────────────┘
│
ai-egress-network
│
Amazon Bedrock, web search, pages
(svc-ai egress only)
Virtual hosts (all served on port 8000):
| Host | Routes to |
|---|---|
app.dev.datachainr.com | fe-core (authenticated UI) + /api/* → svc-bff (session-gated) |
auth.dev.datachainr.com | svc-auth — OAuth2 login/callback/logout |
monitoring.dev.datachainr.com | Grafana dashboards |
Network segmentation. Each tier sits on a dedicated bridge network; most are internal: true (no outbound access). Notably:
frontend-network— nginx ↔ frontends.bff-network— svc-auth / svc-bff ↔ Redis.backend-network(internal) — svc-bff → svc-core → svc-ai.db-network,ai-network,graph-db-network,file-storage-network(internal) — isolate Postgres, Qdrant, MinIO, Neo4j, and Docling.ai-egress-network—svc-ai's only path out: model calls (Amazon Bedrock), web search, page and feed fetches, tool calls. Every fetched URL must be https on 443 to a public address, checked again as the connection opens.svc-core's dashboard feeds use their ownfeed-egress-network.monitoring-network/otel-network/socket-proxy— observability pipeline.
Authentication. OAuth2 via Auth0. svc-auth runs the full flow; access tokens are stored server-side in Redis only. The browser holds a signed HTTP-only session cookie. For service-to-service defence-in-depth, svc-bff mints a short-lived, audience-bound internal JWT (X-Internal-Token) on every downstream call, which svc-core verifies; svc-core in turn mints tokens that svc-ai verifies. Identity is taken from the verified token rather than trusted from raw headers. See docs/system/security/auth-flow.md.
AI execution. svc-ai uses LiteLLM for provider abstraction and LangGraph for multi-agent workflows, with SSE streaming, RAG over Qdrant, graph context from Neo4j, and document ingestion via Docling/MinIO. svc-core orchestrates AI operations by calling svc-ai — it never calls LLM providers directly.
🧩 Services
| Service | Stack | Responsibility |
|---|---|---|
| fe-core | React + Vite | Authenticated single-page app for logged-in users (the product UI). |
| fe-shared | TS / npm package | Shared components, hooks, and logic consumed by both apps. |
| svc-auth | FastAPI · python-jose · itsdangerous · Redis | Auth0 OAuth2 flow and Redis-backed session management. |
| svc-bff | FastAPI · httpx · websockets · PyJWT | Backend-for-frontend: proxies frontend requests to backend services, injecting identity. |
| svc-core | FastAPI · SQLAlchemy · Alembic · Postgres · MinIO · Qdrant · Neo4j | Core business logic and CRUD for the full domain model; orchestrates svc-ai. |
| svc-ai | FastAPI · LiteLLM · LangChain · LangGraph · LlamaIndex | Model management, multi-agent execution, streaming, RAG, and document processing. |
| nginx | nginx (stable-alpine) | Reverse proxy, virtual-host routing, rate limiting, auth_request session gating. |
| redis | Redis 7 | Session/token store for svc-auth and svc-bff. |
| postgres-core / postgres-ai | PostgreSQL 16 | Relational stores for svc-core and svc-ai respectively. |
| neo4j / qdrant / minio / docling | — | Graph DB, vector DB, object storage, and document parsing for AI/RAG workloads. |
| Observability | Grafana · Prometheus · Loki · Promtail · Tempo · cAdvisor · node-exporter | Metrics, logs, and distributed traces. |
📁 Repository Layout
.
├── Makefile # Primary developer entrypoint (see `make help`)
├── VERSION # Current release version
├── chainr.code-workspace # VS Code multi-root workspace (per-module settings)
├── docs/ # Documentation
│ ├── SETUP.md # Full development setup guide
│ ├── guides/ # Developer guides (devcontainer, IDE, git, releases)
│ ├── spec/ # Auto-generated API / frontend / model specs (`make spec`)
│ └── system/ # System & security design docs
├── infra/ # Infrastructure configuration
├── modules/ # The containerised modules
│ ├── docker-compose.yml # Secure base stack definition
│ ├── docker-compose.override.yml# Dev overlay (host ports, tooling networks)
│ ├── docker-compose.prod.yml # Prod overlay (no host ports, secure cookies)
│ ├── dotenv/ # Environment files (+ example/ templates)
│ ├── fe/ # Frontend — npm workspaces
│ │ ├── core/ # authenticated app
│ │ ├── public/ # public app
│ │ └── shared/ # shared component/logic package
│ ├── nginx/ # Reverse proxy config (conf.d/ virtual hosts)
│ ├── monitoring/ # Grafana / Prometheus / Loki / Tempo / Promtail config
│ ├── svc-auth/ svc-bff/ svc-core/ svc-ai/ # Python services
│ └── test/ # Cross-service integration tests
├── templates/ # Files symlinked across modules (e.g. .dockerignore)
└── tools/ # Dev workflow scripts (spec, release, changelog, stats)
Each Python service follows a consistent FastAPI layout (app/router(s), app/services, app/db, app/common, app/dependency, app/middleware, with svc-ai additionally exposing agents, inference, knowledge, mcp, skills, and tools).
🚀 Getting Started
Prerequisites
Docker Desktop (or Docker Engine + Compose)
VS Code with the Dev Containers extension
The development environment is fully automated via VS Code Dev Containers — opening the repo and reopening in the container installs all tooling (uv, npm, linters, pre-commit hooks).
1. Clone & open in the Dev Container
Open the repository in VS Code and Reopen in Container when prompted.
2. Configure environment
Environment files live under modules/dotenv/, with templates in modules/dotenv/example/:
cp modules/dotenv/example/auth0.env.example modules/dotenv/dev/auth0.env
cp modules/dotenv/example/redis.env.example modules/dotenv/dev/redis.env
cp modules/dotenv/example/ai.env.example modules/dotenv/dev/ai.env
cp modules/dotenv/example/postgres-core.env.example modules/dotenv/dev/postgres-core.env
cp modules/dotenv/example/postgres-ai.env.example modules/dotenv/dev/postgres-ai.env
cp modules/dotenv/example/minio.env.example modules/dotenv/dev/minio.env
cp modules/dotenv/example/neo4j.env.example modules/dotenv/dev/neo4j.env
cp modules/.env.example modules/.env
Optional — dashboard feed widgets (weather, RSS, market):
cp modules/dotenv/example/dashboards.env.example modules/dotenv/dev/dashboards.env
Weather and RSS work with no configuration. The market widget needs a vendor API key; without one it renders a setup prompt rather than failing.
Optional — platform allowances and plan prices, off unless set:
cp modules/dotenv/example/billing.env.example modules/dotenv/dev/billing.env
Minimum required values:
| File | Key variables |
|---|---|
redis.env | REDIS_PASSWORD, SESSION_SECRET |
ai.env | OPENAI_API_KEY and/or ANTHROPIC_API_KEY |
postgres-core.env | POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB |
postgres-ai.env | POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB |
minio.env | MINIO_ROOT_USER, MINIO_ROOT_PASSWORD |
neo4j.env | NEO4J_AUTH — one user/password value |
.env | MINIO_ROOT_USER, MINIO_ROOT_PASSWORD, REDIS_PASSWORD (compose reads these for ${...}) |
Generate secure random secrets:
make generate-secrets # prints REDIS_PASSWORD, SESSION_SECRET, INTERNAL_JWT_SECRET
3. Configure local DNS
The stack uses virtual-host routing — add these to your /etc/hosts:
127.0.0.1 local.datachainr.com
127.0.0.1 app.local.datachainr.com
127.0.0.1 auth.local.datachainr.com
127.0.0.1 monitoring.local.datachainr.com
Use the local.datachainr.com family, not dev.datachainr.com — the latter is the real deployed dev environment's domain, and mapping it to 127.0.0.1 in your hosts file hijacks every request your machine makes to it, including outside this stack.
4. Start the stack
make fullstack # Build (first run) and start everything
make fullstack build=on # Force-rebuild images
make db-migrate # Run database migrations
Once running:
| URL | Service |
|---|---|
http://app.local.datachainr.com:8000 | Core app (authenticated) |
http://auth.local.datachainr.com:8000 | Auth service |
http://monitoring.local.datachainr.com:8000 | Grafana |
http://localhost:8080 | svc-core API (direct, dev only) |
http://localhost:5000 | svc-ai API (direct, dev only) |
localhost:5432 / localhost:5433 | postgres-core / postgres-ai (dev only) |
http://localhost:7474 | Neo4j browser (dev only) |
5. Auth0 setup
Create an Auth0 application (Regular Web Application).
Allowed callback URL:
http://auth.local.datachainr.com:8000/callback.Allowed logout URL:
http://local.datachainr.com:8000.Create an Auth0 API with audience
https://api.<your-domain>.Copy domain, client ID, client secret, and audience into
dotenv/dev/auth0.env.
Full details, including IDE configuration, live in docs/SETUP.md.
🛠 Development
All workflows are driven through make — run make help for the full list.
Stack
make fullstack # Start full stack
make fullstack-split # Start with split tmux logs per service
make down # Stop all services
make clean # Stop and remove volumes
make fresh # Clean rebuild everything
make rebuild # Rebuild images with no cache
Dependencies
make install # Install all deps (fe + be) + pre-commit hooks
make update # Update all dependencies
make rebuild-shared # Rebuild the fe-shared package
make audit # Security audit: npm audit fix + Python lockfile scan
make audit-fe # Node dependencies only (npm audit fix)
make audit-be # Python lockfiles only (osv-scanner)
make audit-deps # Every lockfile, Python and Node, in one pass
Dependency vulnerabilities are scanned with osv-scanner against every uv.lock and package-lock.json in the monorepo — on commit, in CI, and on demand. Report-only by default; see docs/system/security/dependency-scanning.md for the severity policy and how to make it blocking.
Code quality
make lint # Ruff + Bandit across Python services
make lint-fix # Auto-fix Ruff violations and reformat
Testing
make test # Unit tests (svc-ai + svc-core)
make test-ai # svc-ai unit tests
make test-core # svc-core unit tests
make test-cov # Unit tests with coverage
make test-integration # Integration tests against the running stack
Frontend apps use Vitest (npm test within each app under modules/fe/).
Logs & utilities
make logs # All services
make logs-auth | logs-app | logs-nginx | logs-fe | logs-be
make health # Check service health endpoints
make ps # Show running containers
make shell-be # Shell into svc-core
make redis-cli # Open Redis CLI
Database
make db-shell # Open psql shell
make db-migrate # alembic upgrade head
make db-reset # Drop, recreate, and migrate
Documentation & releases
make spec # Regenerate docs/spec/ from source
make release-patch # Patch release (also: release-minor / release-major)
📐 Design Principles
Configurable, extensible, well-structured code throughout.
Type safety everywhere — typed variables, classes, and functions; OOP, inheritance, and enums used where appropriate.
Design patterns (e.g. factories) used to keep object creation and orchestration simple.
Tests are mandatory for backend code — Python services are written with Pytest.
Package managers: uv for Python, npm (workspaces) for React/TypeScript.
🗺 Roadmap
The startup roadmap (MVP map, go-to-market timeline, market-evidence plan and investor readiness) lives in docs/business/.
Outstanding hardening work
Dedicated databases for svc-auth and svc-bff — per-service Postgres isolation.
Production hardening — environment-specific secret management.
COOKIE_SECUREis already on in the prod overlay.
✅ Done: the Cloudflare → host hop runs through an outbound-only
cloudflaredtunnel. The host has no inbound ports, and containers can't reach the instance role (docs/system/deployment/cloudflare-tunnel.md).✅ Done: internal service JWTs — svc-bff mints short-lived, audience-bound tokens that svc-core verifies, and svc-core mints tokens that svc-ai verifies (replacing trust in raw identity headers).
Planned phases
Phase 1 — Rules & Governance: policy, routing, and audit rules with a visual rule builder and an inference-time rules engine.
Phase 2 — Evals & Versioning: structured eval runs, regression detection, cost/latency breakdowns, and git-like version history for agents/prompts/skills.
Phase 3 — Access Control & Secrets Vault: workspace/agent/knowledge-level RBAC and a managed secrets vault referenced by name at runtime.
Phase 4 — Sandbox & Operational Tooling: an agent testing sandbox and operational cost/latency dashboards.
📚 Documentation
docs/SETUP.md — full development setup
docs/guides/ — devcontainer, IDE, git, and release guides
docs/spec/ — auto-generated API, frontend, and data-model specs
docs/system/ — system & security design docs
<sub>CHAIN-R — built with privacy, security, and compliance at its core.</sub>