Local Development — Development Setup

Requirements

Tool Version Purpose
Bun 1.x+ Backend runtime (Master Bot, Child Bot, MCP)
Node.js 22+ Frontend build (npm)
Docker Latest Optional — for containerization
Git Latest Repository

Quick Start

git clone [email protected]:SerhiiInUa/citadel-v2.git
cd citadel-v2
cp .env.example .env
# Edit .env — add bot tokens

# One-time: activate the pre-push doc-coverage hook (Phase 49.1)
bash scripts/setup-hooks.sh

Why the hook: blocks git push when you change code without updating docs. Bypass: git push --no-verify. Details — CLAUDE.md section "Documentation Law".

Frontend

cd frontend
npm install
npm run dev          # → http://localhost:5173

Vite automatically proxies:

Build Commands

Backend

Master Bot (CRM API)

cd master-bot
bun install
bun run bot.ts       # → http://localhost:19210

This is the main API server with 68+ endpoints. Requires MASTER_BOT_TOKEN in .env.

Child Bot (AI Proxy)

cd child-bot
bun install
bun run bot.ts       # → http://localhost:19211

Per-project Telegram ↔ Claude CLI proxy. Requires CITADEL_BOT_TOKEN in .env.

MCP State Bridge

cd mcp-server
bun install
bun run server.ts    # → http://localhost:19200

State manager, SSE, WebSocket.

Ports

Port Service Description
5173 Vite Dev Server Frontend + API proxy
19200 MCP State Bridge State, SSE, WebSocket
19210 Master Bot CRM API (68+ endpoints)
19211 Child Bot Health check
18888 Nginx (VPS) Production only
18889 Nginx (Docker) Docker frontend

Environment Variables (.env)

Required

MASTER_BOT_TOKEN=...           # Telegram @BotFather
CRM_ALLOWED_ORIGINS=http://localhost:5173

For Full Functionality

CITADEL_BOT_TOKEN=...          # Child bot token
GITHUB_CLIENT_ID=...           # GitHub OAuth
GITHUB_CLIENT_SECRET=...
GOOGLE_CLIENT_ID=...           # Google OAuth
GOOGLE_CLIENT_SECRET=...

Optional

HEALTH_PORT=19210
CITADEL_DIR=/path/to/citadel-v2
EMAIL_PROVIDER=console          # 'console' for dev (prints to terminal)
[email protected]

Docker (optional)

# Full stack
docker compose -f docker/docker-compose.yml up -d --build

# Frontend only
docker compose -f docker/docker-compose.yml up -d frontend

Project Structure

citadel-v2/
├── master-bot/          # Telegram orchestrator + CRM API (:19210)
├── child-bot/           # Per-project AI proxy (:19211)
├── mcp-server/          # State bridge (:19200)
├── shared/              # Shared code (db, auth, routes, migrations)
├── frontend/            # React CRM + Phaser (Vite)
├── clients/             # ARC CLI
├── services/            # archived Phase 36 NotebookLM Bridge (decommissioned 2026-06-05; RAG moved into shared/rag.ts in Phase 71)
├── config/              # Registry, vault, workers
├── skills/              # Skill definitions + evals
├── docker/              # Compose + Dockerfiles + Nginx
├── infra/nginx/         # VPS Nginx config
├── scripts/             # Deploy, build scripts
├── docs/                # Documentation
└── data/                # SQLite DB (auto-created)

Typical Development Workflow

  1. Start the frontend: cd frontend && npm run dev
  2. Start the Master Bot: cd master-bot && bun run bot.ts
  3. Open http://localhost:5173
  4. Register via email (email_provider=console → code appears in the terminal)
  5. Create a project via the UI
  6. Work with workers via the Workspace

Quick Type Check

cd master-bot && bun build --no-bundle bot.ts    # Type-check backend
cd frontend && npx vite build                     # Type-check + build frontend

Troubleshooting

Problem Solution
Port already in use lsof -i :19210kill <PID>
CORS error Check CRM_ALLOWED_ORIGINS in .env
Frontend can't reach API Check that the Master Bot is running on :19210
Bun can't find modules bun install in the corresponding directory
i18n errors cd frontend && npm run i18n:compile