How 24p61a6662-stack/legal_document works
Legal Document Assistant provides contract upload and analysis, legal-document Q&A, risk and compliance review, contract comparison, and account access. The principal evidenced workflow is a user chat or upload in the React app, a request to the FastAPI backend, then RAG retrieval and answer generation for chat; uploads are parsed and sent for analysis. The README documents a modular ingestion and retrieval stack, while sampled source also shows a separate direct-upload and streaming-chat implementation. Several frontend/backend endpoint contracts differ, so those links are not treated as verified. Unsampled service connections are shown only where documented, and then as unverified.
Main entry points: main.py Chat and upload API · ingest.py Document ingestion · rag_pipeline.py RAG response logic · App.js Chat app
Components 25
User interface
- Chat app
frontend/src/App.js - Chat window
frontend/src/components/ChatWindow.js - Message display
frontend/src/components/MessageBubble.js - Chat history UI
frontend/src/components/Sidebar.js - Analysis panels
frontend/src/components/CompareContracts.js - Contract upload UI
frontend/src/components/UploadContract.js - API client
frontend/src/api/api.js
API and identity
- Chat and upload API
backend/app/main.py - Additional API routes
backend/app/api/routes.py - Account routes
backend/app/auth/auth_routes.py - Token and passwords
backend/app/auth/auth_handler.py
Document Q&A
- RAG response logic
backend/app/rag/rag_pipeline.py - Document ingestion
backend/app/rag/ingest.py - Text chunking
backend/app/services/chunker.py - Embedding generation
backend/app/services/embedder_service.py - Vector store
backend/app/services/vector_store.py - Semantic retrieval
backend/app/services/retriever.py - LLM generation
backend/app/services/llm_service.py
Legal analysis
- File parsing
backend/app/services/document_loader.py - Risk review
backend/app/services/risk_analyzer.py - Compliance review
backend/app/services/compliance_checker.py - Contract comparison
backend/app/services/contract_comparator.py
Conversation state
- Chat history database
backend/app/main.py
Other components
- Legal assistant user
- Ollama model service
Connections 26
- Legal assistant user → Chat app: asks or uploads
frontend/src/App.js - Chat app → Chat and upload API: streams chat
frontend/src/App.js - Chat app → Chat and upload API: posts upload
frontend/src/App.js - Legal assistant user → Chat window: enters query
frontend/src/components/ChatWindow.js - Chat window → Message display: renders messages
frontend/src/components/ChatWindow.js - Legal assistant user → Contract upload UI: selects document
- Contract upload UI → API client: requests upload
frontend/src/api/api.js - Analysis panels → API client: requests analysis
frontend/src/components/CompareContracts.js - API client → Chat and upload API: calls API
- Chat and upload API → RAG response logic: gets RAG response
backend/app/main.py - Additional API routes → RAG response logic: gets RAG response
backend/app/api/routes.py - Chat and upload API → File parsing: parses upload
- Chat and upload API → Ollama model service: requests analysis
backend/app/main.py - Chat and upload API → Chat history database: reads and writes
backend/app/main.py - Account routes → Token and passwords: uses credentials
backend/app/auth/auth_routes.py - RAG response logic → Semantic retrieval: retrieves context
- Semantic retrieval → Vector store: queries vectors
backend/app/services/retriever.py - Document ingestion → File parsing: loads documents
- Document ingestion → Text chunking: chunks text
- Document ingestion → Embedding generation: embeds text
- Document ingestion → Vector store: stores vectors
- RAG response logic → Ollama model service: generates answer
backend/app/rag/rag_pipeline.py - LLM generation → Ollama model service: generates response
backend/app/services/llm_service.py - Chat and upload API → Risk review: requests review
- Chat and upload API → Compliance review: requests check
- Chat and upload API → Contract comparison: requests comparison