How auracodeskm/brdagentbackend works
Purpose and Entry Points
BRD Agent is a Python backend that ingests corporate communications and generates source-grounded, multi-section Business Requirements Documents (BRDs). It exposes FastAPI HTTP/WebSocket interfaces and can also be run as a standalone pipeline.
• Application entry points: main.py, app/main.py
• API routes: app/api/routes/ingest.py, app/api/routes/generate.py
• Batch/background ingestion: background_ingest.py
API and Request Boundary
FastAPI receives uploads/ingestion requests and BRD-generation requests. Request/response contracts are centralized in schemas; configuration is environment-driven. Generation is intended to stream section progress/results to the external Next.js frontend over WebSockets.
• API composition: app/main.py
• Route handlers: app/api/routes/ingest.py, app/api/routes/generate.py
• Contracts/configuration: app/models/schemas.py, app/core/config.py
Ingestion and Index Construction
The ingestion pipeline converts raw communications into cleaned text and semantic chunks, then builds two retrieval representations: dense embeddings and a relationship-oriented knowledge graph. It supports the repository’s offline/local processing posture and has a standalone voice/transcript component.
• Pipeline: pipeline/ingestion.py
• Embedding model integration: models/embeddings.py
• Speech processing: whisper_engine.py
Dual Retrieval and Reranking
At query time, retrieval combines semantic vector search with graph-aware retrieval. The merged evidence is reranked before context is supplied to generation, separating evidence selection from document writing.
• Retrieval orchestration: pipeline/retrieval.py, pipeline/rag_engine.py
• Dense/vector and graph dependencies are represented through the pipeline; Redis-backed BM25/cache adapters live in cache/redis_bm25.py, cache/redis_cache.py
• Cross-encoder reranking: models/reranker.py
BRD Generation Pipeline
The generator produces structured BRD sections from retrieved evidence. The design supports a two-pass model strategy: a smaller local Qwen model extracts facts, then a larger Qwen model writes professional prose. Functional requirements can use multiple candidate generations and a merge/intersection pass to reduce unsupported requirements.
• Generation orchestration: pipeline/generator.py
• Local LLM adapter: models/llm.py
• Generation API boundary: app/api/routes/generate.py
Governance: Conflicts and Traceability
Post-retrieval/document-analysis stages identify contradictory stakeholder statements and create requirement-to-source mappings. These outputs are first-class BRD evidence, not merely UI metadata.
• Contradiction analysis: pipeline/conflict.py
• Requirement-source matrix: pipeline/traceability.py
• Operational verification artifacts: test_graph.py, audit_brd.md
Runtime and Infrastructure
The service runs on Python/FastAPI/Uvicorn and is designed for local Ollama inference, LightRAG graph storage, FAISS dense retrieval, Hugging Face BGE embedding/reranker models, and optional Redis/Upstash caching. It targets an NVIDIA RTX 4090-class 24 GB VRAM environment; model setup is automated separately.
• Dependencies: requirements.txt
• Model bootstrap: download_models.py
• Environment template: .env.example
Main entry points: generator.py BRD generator · ingestion.py Ingestion pipeline · retrieval.py Dual retrieval · generate.py Generate routes
Components 19
Service API
- Next.js frontend · Receives streamed BRD progress and results.
- FastAPI application
app/main.py - Ingest routes
app/api/routes/ingest.py - Generate routes · Streams generation updates over WebSockets.
app/api/routes/generate.py - Schemas & configuration
app/models/schemas.py
Ingestion & Indexing
- Background ingestion
background_ingest.py - Ingestion pipeline · Cleans communications and creates semantic chunks.
pipeline/ingestion.py - Speech processing
whisper_engine.py
Evidence Retrieval
- Dual retrieval · Combines dense search with graph-aware evidence.
pipeline/retrieval.py - RAG engine · Connects vector and graph retrieval representations.
pipeline/rag_engine.py - FAISS + LightRAG indexes · Dense vectors and relationship-oriented knowledge graph.
- Redis BM25/cache
cache/redis_bm25.py - Cross-encoder reranker
models/reranker.py
BRD Generation & Governance
- BRD generator · Builds structured sections and validates functional requirements through candidate merging.
pipeline/generator.py - Conflict analysis
pipeline/conflict.py - Traceability matrix
pipeline/traceability.py
Models & Runtime
- Embedding model
models/embeddings.py - Local Qwen adapter · Uses smaller fact extraction and larger prose-writing passes.
models/llm.py - Model bootstrap
download_models.py
Connections 26
- Next.js frontend → FastAPI application: HTTP / WebSocket
- FastAPI application → Ingest routes: mounts
- FastAPI application → Generate routes: mounts
- Schemas & configuration → Ingest routes: request contracts
- Schemas & configuration → Generate routes: request contracts
- Ingest routes → Ingestion pipeline: ingests uploads
- Background ingestion → Ingestion pipeline: runs batch ingestion
- Speech processing → Ingestion pipeline: transcripts
- Ingestion pipeline → Embedding model: embeds chunks
- Embedding model → FAISS + LightRAG indexes: dense vectors
- Ingestion pipeline → FAISS + LightRAG indexes: entities and relationships
- Ingestion pipeline → Redis BM25/cache: BM25/cache data
- Generate routes → BRD generator: starts BRD generation
- BRD generator → Dual retrieval: queries evidence
- Dual retrieval → RAG engine: orchestrates
- RAG engine → FAISS + LightRAG indexes: vector + graph search
- Dual retrieval → Redis BM25/cache: BM25/cache lookup
- Dual retrieval → Cross-encoder reranker: reranks merged evidence
- Cross-encoder reranker → BRD generator: grounded context
- BRD generator → Local Qwen adapter: fact extraction and prose
- BRD generator → Conflict analysis: analyzes statements
- BRD generator → Traceability matrix: maps requirements to sources
- BRD generator → Generate routes: sections and progress
- Model bootstrap → Embedding model: installs
- Model bootstrap → Cross-encoder reranker: installs
- Model bootstrap → Local Qwen adapter: installs