Split the raggr service into raggr-blue (8080) and raggr-green (8081) behind compose profiles, add a /api/health endpoint and container healthcheck, and add scripts/deploy.sh to build the inactive color, wait for it to become healthy, then gracefully stop the old one. Makefile targets resolve the active color automatically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4.4 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
SimbaRAG is a RAG (Retrieval-Augmented Generation) conversational AI system for querying information about Simba (a cat). It ingests documents from Paperless-NGX, stores embeddings in PostgreSQL via pgvector, and uses LLMs (Ollama or OpenAI) to answer questions.
Commands
Development
# Start environment (raggr runs as raggr-blue/raggr-green behind compose profiles)
docker compose --profile blue up --build
# View logs (Makefile resolves the active color)
make logs
Database Migrations (Aerich/Tortoise ORM)
# Generate migration (must run in Docker with DB access)
make migrate-new
# Apply migrations (auto-runs on startup, manual if needed)
make migrate
# View migration history
make migrate-history
Migrations must be backward-compatible: blue-green deploys run aerich upgrade in the new container while the old code still serves.
Frontend
cd raggr-frontend
yarn install
yarn build # Production build
yarn dev # Dev server (rarely needed, backend serves frontend)
Production
Zero-downtime blue-green deploy: raggr-blue (port 8080) and raggr-green (port 8081) alternate behind Caddy health checks. See docs/deployment.md.
make redeploy # git pull + scripts/deploy.sh (build new color, wait healthy, stop old)
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Docker Compose │
├─────────────────────────────────────────────────────────────┤
│ raggr-blue/green (8080/8081) │ postgres (port 5432) │
│ ├── Quart backend │ PostgreSQL 16 + pgvector│
│ └── React frontend (served) │ │
└─────────────────────────────────────────────────────────────┘
Backend (root directory):
app.py- Quart application entry, serves API and static frontendmain.py- RAG logic, document indexing, LLM interaction, LangChain agentllm.py- LLM client with Ollama primary, OpenAI fallbackaerich_config.py- Database migration configurationblueprints/- API routes organized as Quart blueprintsusers/- OIDC auth, JWT tokens, RBAC with LDAP groupsconversation/- Chat conversations and message historyrag/- Document indexing endpoints (admin-only)
config/- Configuration modulesoidc_config.py- OIDC authentication configuration
utils/- Reusable utilitieschunker.py- Document chunking for embeddingscleaner.py- PDF cleaning and summarizationimage_process.py- Image description with LLMrequest.py- Paperless-NGX API client
scripts/- Administrative and utility scriptsadd_user.py- Create users manuallyuser_message_stats.py- User message statisticsmanage_vectorstore.py- Vector store management CLIinspect_vector_store.py- Inspect ChromaDB contentsquery.py- Query generation utilities
migrations/- Database migration files
Frontend (raggr-frontend/):
- React 19 with Rsbuild bundler
- Tailwind CSS for styling
- Built to
dist/, served by backend at/
Auth Flow: LLDAP → Authelia (OIDC) → Backend JWT → Frontend localStorage
Testing
Always run make test before pushing code to ensure all tests pass.
make test # Run tests
make test-cov # Run tests with coverage
Key Patterns
- All endpoints are async (
async def) - Use
@jwt_refresh_token_requiredfor authenticated endpoints - Use
@admin_requiredfor admin-only endpoints (checkslldap_admingroup) - Tortoise ORM models in
blueprints/*/models.py - Frontend API services in
raggr-frontend/src/api/
Environment Variables
See .env.example. Key ones:
DATABASE_URL- PostgreSQL connectionOIDC_*- Authelia OIDC configurationOLLAMA_URL- Local LLM serverOPENAI_API_KEY- Fallback LLMPAPERLESS_TOKEN/BASE_URL- Document source