How justicecanada/otto works
Project type and purpose
• Otto is a full-stack, monolithic Django platform exposing multiple sub-applications (“apps”) (chat, laws, librarian, text_extractor) combined under one codebase.
• It serves dynamic HTML/JS front-ends, runs asynchronous workloads via Celery, and persists data in PostgreSQL (with pgbouncer). It also integrates with external AI/LLM APIs, vector stores, and provides Docker/Kubernetes deployment.
Main components
a. Clients & Frontend
• Web browser or automated load-test clients interacting via HTTP/HTTPS.
• Django templates + static assets (JS/CSS) delivered by Django or CDN.
b. Web Tier
• Nginx or cloud Load Balancer (in prod).
• Django application server (Gunicorn or Daphne, ASGI) serving web requests, routing via otto/urls.py.
• Modular Django “apps”:
– chat: real-time AI chat UI + cost estimation + persistence
– laws: XML ingestion, full-text search, vector embedding queries
– librarian: document upload, data-source management
– text_extractor: OCR/back-end pipelines
– otto (core): authentication, admin UI, feature toggles, Celery setup
c. Asynchronous Tier
• Celery workers (gevent pool) for: law ingestion, file translation, document processing, cost calculations.
• Celery Beat (django_celery_beat) for scheduled tasks (e.g., exchange rate updates, cleanup jobs).
• Celery broker (e.g., Redis or RabbitMQ configured via ENV in .env.example).
d. Persistence & Caching
• PostgreSQL database (django/postgres_wrapper + pgbouncer for connection pooling)
• Optional cache layer (Redis or Memcached) for session data, short-term caching, tiktoken cost estimates.
• Vector store (could be Postgres with pgvector or external—and referenced in code via cache_tiktoken.py, law embeddings).
e. External Services
• LLM APIs (OpenAI, Azure OpenAI, etc.) invoked from django/chat/llm.py and django/laws/prompts.py.
• Corporate Q&A library ingestion or other data sources via management commands.
• Azure Container Registry & AKS for production Docker deployment.
Relationships & interactions
– Client → (HTTPS) → Load Balancer/Nginx → Django (request/response)
– Django → (SQL) → PostgreSQL via pgbouncer
– Django → (Broker) → Celery tasks enqueued
– Celery Worker → (SQL) → PostgreSQL
– Celery Worker → (External API) → LLM services or vector DB
– Celery Beat → (Broker) → scheduled tasks
– Django & Celery → (Cache) → Redis/Memcached for transient data
– Django static files → CDN or Nginx
Architectural patterns & design principles
– Monolithic Django with clear app–level boundaries (MVC pattern).
– Asynchronous task queue for long-running or IO-bound jobs.
– Connection pooling (pgbouncer) to optimize DB throughput under load.
– DevContainer + Docker for reproducible dev environment; Dockerfile + compose for local services.
– Kubernetes deployment manifests (external repo) for production.
Detail orientation
– Don’t collapse the async tier into the web tier—show Celery Beat & Worker queue separately.
– Call out pgbouncer as an intermediate pool component.
– For each Django app, annotate its primary responsibilities (e.g., “chat: UI + LLM calls + cost estimation”).
– Show Dev/Prod infra only if relevant: DevContainer, Docker Compose (local), AKS cluster (prod).