How divyansh0208/legal-ai works
Sahayak is a legal-assistance web app for document-grounded Q&A, PDF analysis, and voice queries. Users enter through the React home/chat/upload experience: chat calls the query API, which runs retrieval and LLM generation before returning an answer; uploaded PDFs are validated, parsed (with OCR when needed), indexed, summarized, and recorded. Voice audio is transcribed into text through a separate endpoint. The graph follows explicit calls and README-described capabilities; some internal parsing, embedding, and frontend handoffs are supported by the source index rather than shown excerpts.
Main entry points: routes_upload.py Upload endpoint · client.js API client · routes_query.py Query endpoint · pipeline.py Answer and summary
Components 24
Web experience
- Web app routes
frontend/src/App.jsx - Home guidance
frontend/src/pages/Home.jsx - Chat interface
frontend/src/components/ChatWindow.jsx - Chat state
frontend/src/hooks/useChat.js - Upload interface
frontend/src/components/FileUpload.jsx - Voice input
frontend/src/components/VoiceInput.jsx - API client
frontend/src/api/client.js
API services
- FastAPI app
main.py - Query endpoint
app/api/routes_query.py - Upload endpoint
app/api/routes_upload.py - Voice endpoint
app/api/routes_voice.py
Document intelligence
- PDF and OCR
app/parsing/pdf_parser.py - Chunking and retrieval
app/rag/retriever.py - Text embeddings
app/embeddings/embedder.py - Answer and summary
app/rag/pipeline.py - Safety prompts
app/rag/prompts.py - Audio transcription
app/voice/transcribe.py
Persistence and security
- Chroma vector store
app/rag/retriever.py - SQL database
app/db/database.py - Chat and document records
app/db/models.py - Upload validation
app/core/security.py - Uploaded PDF files
app/api/routes_upload.py
Other components
- Legal help seeker
- Groq language and speech APIs
Connections 35
- Legal help seeker → Web app routes: uses
README.md - Web app routes → Home guidance: routes to
frontend/src/App.jsx - Web app routes → Chat interface: routes to
frontend/src/App.jsx - Web app routes → Upload interface: routes to
frontend/src/App.jsx - Chat interface → Chat state: uses
frontend/src/pages/Chat.jsx - Chat state → API client: calls
frontend/src/hooks/useChat.js - Upload interface → API client: calls
frontend/src/components/FileUpload.jsx - Voice input → API client: calls
frontend/src/components/VoiceInput.jsx - Legal help seeker → Chat interface: asks
README.md - Legal help seeker → Upload interface: uploads PDF
README.md - API client → Query endpoint: posts query
frontend/src/api/client.js - API client → Upload endpoint: posts PDF
frontend/src/api/client.js - API client → Voice endpoint: posts audio
frontend/src/api/client.js - FastAPI app → Query endpoint: registers
main.py - FastAPI app → Upload endpoint: registers
main.py - FastAPI app → Voice endpoint: registers
main.py - Query endpoint → Answer and summary: calls
app/api/routes_query.py - Query endpoint → SQL database: uses session
app/api/routes_query.py - SQL database → Chat and document records: registers tables
app/db/database.py - Query endpoint → Chat and document records: writes chat history
app/api/routes_query.py - Upload endpoint → Upload validation: validates file
app/api/routes_upload.py - Upload endpoint → PDF and OCR: extracts text
app/api/routes_upload.py - PDF and OCR → Chunking and retrieval: provides document text
- Upload endpoint → Chunking and retrieval: indexes text
app/api/routes_upload.py - Upload endpoint → Answer and summary: requests summary
app/api/routes_upload.py - Upload endpoint → Uploaded PDF files: writes PDF
app/api/routes_upload.py - Upload endpoint → Chat and document records: stores metadata
app/api/routes_upload.py - Answer and summary → Chunking and retrieval: retrieves context
app/rag/pipeline.py - Answer and summary → Safety prompts: formats prompts
app/rag/pipeline.py - Answer and summary → Groq language and speech APIs: requests generation
app/rag/pipeline.py - Chunking and retrieval → Text embeddings: embeds text
app/rag/retriever.py - Chunking and retrieval → Chroma vector store: stores and queries
app/rag/retriever.py - Voice endpoint → Audio transcription: transcribes
app/api/routes_voice.py - Audio transcription → Groq language and speech APIs: uses Whisper
README.md - FastAPI app → Upload validation: installs headers
main.py