Desenvolvimento Local — Development Setup

Requisitos

Ferramenta Versão Finalidade
Bun 1.x+ Runtime do backend (Master Bot, Child Bot, MCP)
Node.js 22+ Build do frontend (npm)
Docker Latest Opcional — para containerização
Git Latest Repositório

Início Rápido

git clone [email protected]:SerhiiInUa/citadel-v2.git
cd citadel-v2
cp .env.example .env
# Redaguje o .env — adicione os tokens dos bots

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

Por que o hook: bloqueia git push quando você altera código sem atualizar a documentação. Bypass: git push --no-verify. Detalhes — seção "Documentation Law" do CLAUDE.md.

Frontend

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

O Vite faz proxy automaticamente para:

Comandos de Build

Backend

Master Bot (CRM API)

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

Este é o servidor principal da API com 68+ endpoints. Requer MASTER_BOT_TOKEN no .env.

Child Bot (AI Proxy)

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

Proxy Telegram ↔ Claude CLI por projeto. Requer CITADEL_BOT_TOKEN no .env.

MCP State Bridge

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

Gerenciador de estado, SSE, WebSocket.

Portas

Porta Serviço Descrição
5173 Vite Dev Server Frontend + proxy da API
19200 MCP State Bridge Estado, SSE, WebSocket
19210 Master Bot CRM API (68+ endpoints)
19211 Child Bot Health check
18888 Nginx (VPS) Apenas produção
18889 Nginx (Docker) Frontend Docker

Variáveis de Ambiente (.env)

Obrigatórias

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

Para funcionalidade completa

CITADEL_BOT_TOKEN=...          # Token do Child Bot
GITHUB_CLIENT_ID=...           # GitHub OAuth
GITHUB_CLIENT_SECRET=...
GOOGLE_CLIENT_ID=...           # Google OAuth
GOOGLE_CLIENT_SECRET=...

Opcionais

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

Docker (opcional)

# Stack completo
docker compose -f docker/docker-compose.yml up -d --build

# Apenas o frontend
docker compose -f docker/docker-compose.yml up -d frontend

Estrutura do Projeto

citadel-v2/
├── master-bot/          # Telegram оркестратор + CRM API (:19210)
├── child-bot/           # Per-project AI proxy (:19211)
├── mcp-server/          # State bridge (:19200)
├── shared/              # Спільний код (db, auth, routes, migrations)
├── frontend/            # React CRM + Phaser (Vite)
├── clients/             # ARC CLI
├── services/            # NotebookLM Bridge (Python)
├── 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)

Workflow Típico de Desenvolvimento

  1. Inicie o frontend: cd frontend && npm run dev
  2. Inicie o Master Bot: cd master-bot && bun run bot.ts
  3. Abra http://localhost:5173
  4. Registre-se via email (email_provider=console → código no terminal)
  5. Crie um projeto pela interface
  6. Trabalhe com os workers pelo Workspace

Verificação Rápida de Tipos

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

Solução de Problemas

Problema Solução
Port already in use lsof -i :19210kill <PID>
Erro de CORS Verifique CRM_ALLOWED_ORIGINS no .env
Frontend não encontra a API Verifique se o Master Bot está rodando na porta :19210
Bun não encontra módulos Execute bun install no diretório correspondente
Erros de i18n cd frontend && npm run i18n:compile