How adithya880/contractrisk-ai works
ContractRisk AI is a contract-review prototype. Its main workflow takes a PDF or DOCX through extraction and clause segmentation, then combines clause classification, rule-based hazard detection, semantic precedent retrieval, and local-LLM reasoning into risk scores and conditional future scenarios. The FastAPI service exposes analysis to a Streamlit upload, progress, and results workflow; PostgreSQL stores completed analyses. The README documents the broad pipeline; sampled source confirms several orchestration and persistence relationships, but not every runtime connection.
Main entry points: app.py Streamlit workflow · analyzer.py Hybrid risk analysis · segmenter.py Clause segmentation · analysis.py Analysis endpoint
Components 18
User workflow
- Streamlit workflow
frontend/app.py - Contract upload
frontend/components/contract_uploader.py - Results inspection
frontend/components/results_view.py
API service
- FastAPI service
src/api/main.py - Analysis endpoint
src/api/routes/analysis.py
Document preparation
- Document extraction
src/document_processing/loader.py - Clause segmentation
src/clause_segmentation/segmenter.py
Risk intelligence
- BERT classification
src/models/bert_classifier.py - Regex hazard detection
src/risk_analysis/rule_engine.py - Clause embeddings
src/embeddings/embedder.py - FAISS precedent index
src/embeddings/index.py - RAG reasoning
src/rag/pipeline.py - Local LLM generation
src/rag/generator.py - Hybrid risk analysis
src/risk_analysis/analyzer.py - Hybrid risk scoring
src/risk_analysis/scoring.py - Scenario prediction
src/risk_analysis/scenario_predictor.py
Persistence
- PostgreSQL records
src/database/repositories.py
Other components
- Contract reviewer
Connections 22
- Contract reviewer → Streamlit workflow: starts review
README.md - Streamlit workflow → Contract upload: offers upload
README.md - Streamlit workflow → FastAPI service: submits analysis
README.md - FastAPI service → Analysis endpoint: routes requests
src/api/main.py - Analysis endpoint → Document extraction: loads contract
src/api/routes/analysis.py - Document extraction → Clause segmentation: provides extracted document
src/clause_segmentation/segmenter.py - Clause segmentation → BERT classification: segments classified
README.md - Clause segmentation → Regex hazard detection: segments scanned
README.md - Clause segmentation → Clause embeddings: clauses embedded
README.md - Clause embeddings → FAISS precedent index: builds vectors
src/embeddings/index.py - FAISS precedent index → RAG reasoning: supplies precedents
README.md - RAG reasoning → Local LLM generation: generates explanations
src/rag/pipeline.py - BERT classification → Hybrid risk analysis: classification input
README.md - Regex hazard detection → Hybrid risk analysis: rule matches
src/risk_analysis/analyzer.py - RAG reasoning → Hybrid risk analysis: retrieval evidence
src/risk_analysis/analyzer.py - Hybrid risk analysis → Hybrid risk scoring: aggregates factors
README.md - Hybrid risk analysis → Scenario prediction: predicts consequences
src/risk_analysis/analyzer.py - Scenario prediction → Local LLM generation: requests generation
src/risk_analysis/scenario_predictor.py - Analysis endpoint → PostgreSQL records: persists results
src/api/routes/analysis.py - FastAPI service → Streamlit workflow: returns analysis
README.md - Streamlit workflow → Results inspection: renders results
frontend/app.py - PostgreSQL records → Analysis endpoint: serves stored records
src/api/routes/analysis.py