Architecture

System design and technical decisions for Geetanjali.

Overview

Geetanjali uses retrieval-augmented generation (RAG) to ground ethical guidance in Bhagavad Geeta scripture. Users submit ethical dilemmas, the system retrieves relevant verses, and an LLM generates structured recommendations with citations.

User Query → Embedding → Vector Search → LLM Generation → Structured Output
                              ↓
                        Geeta Verses
                        (701 verses)

Components

┌─────────────────────────────────────────────────────────────────┐
│                        Docker Network                            │
│                                                                  │
│  ┌─────────────┐     ┌─────────────┐     ┌─────────────┐       │
│  │   Frontend  │────▶│   Backend   │────▶│  PostgreSQL │       │
│  │ (React/Nginx│     │  (FastAPI)  │     │   :5432     │       │
│  │    :80)     │     │    :8000    │     └─────────────┘       │
│  └─────────────┘     └──────┬──────┘                            │
│                             │                                    │
│               ┌─────────────┼─────────────┬──────────────┐      │
│               ▼             ▼             ▼              ▼      │
│         ┌──────────┐  ┌─────────┐  ┌─────────┐  ┌────────────┐ │
│         │ ChromaDB │  │  Redis  │  │ Ollama  │  │   Worker   │ │
│         │ 8001:8000│  │  :6379  │  │ :11434  │  │    (RQ)    │ │
│         └──────────┘  └─────────┘  └─────────┘  └────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Component Purpose
Frontend React SPA with verse browser, case submission, output display
Backend FastAPI handling auth, cases, RAG pipeline, verse management
Worker RQ background processor for async analysis jobs
PostgreSQL Cases, users, outputs, verses, feedback
ChromaDB Vector embeddings for semantic verse search
Redis Caching, session storage, task queues, rate limiting
Ollama Local LLM inference (primary), Anthropic Claude (fallback)

RAG Pipeline

1. Embedding

User query and all verses are embedded using sentence-transformers/all-MiniLM-L6-v2 (384 dimensions).

2. Retrieval

ChromaDB performs cosine similarity search, returning top-k relevant verses with scores.

3. Generation

Retrieved verses are passed as context to the LLM with a structured prompt requesting:

Data Model

users ──────┬──── cases ──────── outputs
            │        │              │
            │        └── messages   └── feedback
            │
verses ─────┴──── translations
   │
   └──── commentaries

Key entities:

Authentication

Anonymous users can create and view cases. Authenticated users get persistent history.

API Design

RESTful API at /api/v1/:

/auth/*          - Login, signup, refresh, logout
/cases/*         - CRUD + analyze
/verses/*        - Browse, search, daily verse
/outputs/*       - View analysis, submit feedback, export
/messages/*      - Follow-up questions on cases
/contact         - Contact form submission

Full OpenAPI docs at /docs when running.

Security

Deployment

Docker Compose orchestrates all 7 services:

services:
  ollama      # LLM inference (pre-built image, models in volume)
  postgres    # Primary database
  redis       # Cache, queues, rate limiting
  chromadb    # Vector database
  backend     # FastAPI with Uvicorn
  worker      # RQ background task processor
  frontend    # Nginx serving React build

Production considerations: