How framech01/a-law-ai works
A-Law AI is a FastAPI service for lease-contract OCR and analysis, plus a Korean legal RAG chatbot. Spring Boot initiates synchronous REST requests or asynchronous RabbitMQ analysis; contract analysis combines summarization, clause risk checks, and missing-clause detection, while OCR can fetch images from shared S3. The chatbot classifies questions, retrieves and reranks legal sources, generates an answer, and checks citations. Paths and principal calls follow the README and SOURCE INDEX; unsampled subsystem links are shown only where the README documents them.
Main entry points: routers.py REST API · graph.py Chat workflow · analyzer.py Contract analysis · pipeline.py Legal RAG pipeline
Components 27
API entrypoints
- REST API
app/api/routers.py - Contract endpoints
app/api/endpoints/contract.py - OCR endpoints
app/api/endpoints/ocr.py - Chat endpoints
app/api/endpoints/chat.py - RAG admin endpoints
app/api/endpoints/rag.py
Contract analysis
- Contract analysis
app/services/analyzer.py - Clause risk analysis
app/services/risk/analyzer.py - Clause splitting
app/services/risk/clause_splitter.py - Rule prefilter
app/services/risk/prefilter.py - Missing clauses
app/services/risk/missing.py - Contract summary
app/services/summarizer.py - OCR service
app/services/ocr/ocr_service.py - Upstage OCR pipeline
app/ocr/upstage_ocr.py
Legal assistant
- Chatbot service
app/services/chatbot.py - Chat sessions
app/services/chat_session.py - Chat workflow
app/rag/graph.py - Domain classifier
app/rag/domain.py - Legal RAG pipeline
app/rag/pipeline.py - Citation verifier
app/rag/citations.py
External integrations
- RabbitMQ consumer
app/services/rabbitmq_consumer.py - S3 client
app/util/s3_client.py - Shared S3
- RabbitMQ
- Pinecone
Shared runtime
- LLM runtime
app/core/llm.py - Configuration
app/core/config.py
Other components
- Spring Boot
Connections 33
- Spring Boot → REST API: calls REST
README.md - REST API → Contract endpoints: routes requests
app/api/routers.py - REST API → OCR endpoints: routes requests
app/api/routers.py - REST API → Chat endpoints: routes requests
app/api/routers.py - REST API → RAG admin endpoints: routes requests
app/api/routers.py - Contract endpoints → Contract analysis: invokes analysis
app/api/endpoints/contract.py - Contract analysis → Contract summary: generates summary
app/services/analyzer.py - Contract analysis → Clause risk analysis: runs risk checks
app/services/analyzer.py - Clause risk analysis → Clause splitting: splits clauses
app/services/risk/analyzer.py - Clause risk analysis → Rule prefilter: screens clauses
app/services/risk/analyzer.py - Clause risk analysis → Missing clauses: checks omissions
app/services/risk/analyzer.py - OCR endpoints → OCR service: requests OCR
app/api/endpoints/ocr.py - OCR service → Upstage OCR pipeline: processes images
app/services/ocr/ocr_service.py - Chat endpoints → Chatbot service: handles chat
app/api/endpoints/chat.py - Chatbot service → Chat sessions: loads session
app/services/chatbot.py - Chatbot service → Chat workflow: runs workflow
app/services/chatbot.py - Chat workflow → Domain classifier: classifies query
app/rag/graph.py - Chat workflow → Legal RAG pipeline: retrieves evidence
app/rag/graph.py - Chat workflow → Citation verifier: verifies answer
app/rag/graph.py - RAG admin endpoints → Legal RAG pipeline: indexes and searches
app/api/endpoints/rag.py - RabbitMQ consumer → RabbitMQ: consumes requests
README.md - Spring Boot → RabbitMQ: publishes analysis
README.md - RabbitMQ consumer → Contract analysis: runs analysis
app/services/rabbitmq_consumer.py - RabbitMQ consumer → S3 client: fetches contract image
app/services/rabbitmq_consumer.py - S3 client → Shared S3: reads image
app/util/s3_client.py - RabbitMQ consumer → RabbitMQ: publishes result
README.md - Legal RAG pipeline → Pinecone: searches vectors
app/rag/pipeline.py - Legal RAG pipeline → LLM runtime: uses embeddings
- Contract analysis → LLM runtime: requests generation
app/services/analyzer.py - Chat workflow → LLM runtime: generates answer
app/rag/graph.py - OCR service → LLM runtime: structures OCR
- LLM runtime → Configuration: reads settings
app/core/llm.py - Legal RAG pipeline → Configuration: reads settings
app/rag/pipeline.py