# shardul2711/ai-compliance-risk-copilot architecture

> Architecture diagram of the GitHub repository shardul2711/ai-compliance-risk-copilot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shardul2711/ai-compliance-risk-copilot
- Repository: https://github.com/shardul2711/ai-compliance-risk-copilot

## Overview

AI Compliance Risk Copilot accepts regulatory and contract documents through a web portal, processes them into searchable chunks, and runs a multi-agent compliance and risk analysis that produces recommendations and executive reports. The portal also exposes document chat, audit logs, and account workflows. The graph preserves the documented analysis stages and RAG/ML capabilities; some subsystem links rely on README descriptions because their implementation was not sampled.

Main entry points: [`backend/langgraph/workflow.py`](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/langgraph/workflow.py) (Analysis Workflow), [`frontend/services/api.ts`](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/services/api.ts) (REST Client), [`backend/agents/llm_client.py`](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/llm_client.py) (Ollama Client), [`backend/app/main.py`](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/main.py) (FastAPI Gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_portal["Web Portal"]
  node_portal_pages["Portal Pages<br/>[page.tsx]"]
  node_upload_page["Document Upload<br/>[page.tsx]"]
  node_analysis_page["Analysis View<br/>[page.tsx]"]
  node_chat_page["Document Chat<br/>[page.tsx]"]
  node_reports_page["Reports View<br/>[page.tsx]"]
  node_audit_page["Audit View<br/>[page.tsx]"]
  node_api_client["REST Client<br/>[api.ts]"]
end

subgraph group_api["API and Storage"]
  node_api_gateway["FastAPI Gateway<br/>[main.py]"]
  node_auth_routes["Authentication<br/>[auth.py]"]
  node_document_routes["Document API<br/>[documents.py]"]
  node_audit_routes["Audit API<br/>[audit.py]"]
  node_sql_store[("Relational Records<br/>[models.py]")]
end

subgraph group_analysis["Document Analysis"]
  node_pdf_processing["PDF Processing<br/>[pdf_service.py]"]
  node_workflow["Analysis Workflow<br/>[workflow.py]"]
  node_classification["Document Classification<br/>[document_agent.py]"]
  node_clause_extraction["Clause Extraction<br/>[clause_agent.py]"]
  node_compliance_mapping["Compliance Mapping"]
  node_risk_analysis["Risk Analysis<br/>[risk_agent.py]"]
  node_recommendations["Recommendations"]
  node_executive_report["Executive Reporting<br/>[report_agent.py]"]
end

subgraph group_intelligence["RAG and ML"]
  node_prediction["Risk Prediction"]
  node_ml_service["ML and Explanations<br/>[ml_service.py]"]
  node_llm_client["Ollama Client<br/>[llm_client.py]"]
  node_embedder["Text Embeddings<br/>[embedder.py]"]
  node_vector_store[("Qdrant Vector Store<br/>[qdrant_store.py]")]
  node_retriever["RAG Retriever<br/>[retriever.py]"]
end

node_officer(("Compliance Officer"))
node_ollama["Ollama Service"]

node_officer -->|"uploads documents"| node_upload_page
node_officer -->|"uses portal"| node_portal_pages
node_upload_page -->|"calls upload"| node_api_client
node_portal_pages -->|"requests data"| node_api_client
node_analysis_page -->|"requests analysis"| node_api_client
node_chat_page -.->|"sends questions"| node_api_client
node_reports_page -->|"requests reports"| node_api_client
node_audit_page -->|"requests logs"| node_api_client
node_api_client -->|"REST requests"| node_api_gateway
node_api_gateway -->|"routes auth"| node_auth_routes
node_api_gateway -->|"routes documents"| node_document_routes
node_api_gateway -->|"routes audits"| node_audit_routes
node_document_routes -->|"processes PDFs"| node_pdf_processing
node_document_routes -->|"triggers analysis"| node_workflow
node_pdf_processing -->|"stores chunks"| node_vector_store
node_workflow -->|"dispatches stage"| node_classification
node_workflow -->|"dispatches stage"| node_clause_extraction
node_workflow -->|"dispatches stage"| node_compliance_mapping
node_workflow -->|"dispatches stage"| node_risk_analysis
node_workflow -->|"dispatches stage"| node_prediction
node_workflow -->|"dispatches stage"| node_recommendations
node_workflow -->|"dispatches stage"| node_executive_report
node_prediction -->|"requests prediction"| node_ml_service
node_workflow -->|"persists results"| node_sql_store
node_audit_routes -->|"reads audit logs"| node_sql_store
node_classification -->|"calls LLM"| node_llm_client
node_clause_extraction -->|"calls LLM"| node_llm_client
node_compliance_mapping -->|"calls LLM"| node_llm_client
node_risk_analysis -->|"calls LLM"| node_llm_client
node_recommendations -->|"calls LLM"| node_llm_client
node_executive_report -->|"calls LLM"| node_llm_client
node_llm_client -->|"HTTP inference"| node_ollama
node_vector_store -->|"embeds chunks"| node_embedder
node_retriever -->|"searches chunks"| node_vector_store
node_retriever -->|"generates answer"| node_ollama
node_document_routes -->|"answers chat"| node_retriever

click node_portal_pages "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/dashboard/page.tsx"
click node_upload_page "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/upload/page.tsx"
click node_analysis_page "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/analysis/%5Bid%5D/page.tsx"
click node_chat_page "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/chat/%5Bid%5D/page.tsx"
click node_reports_page "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/reports/page.tsx"
click node_audit_page "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/audit/page.tsx"
click node_api_client "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/services/api.ts"
click node_api_gateway "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/main.py"
click node_auth_routes "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/api/auth.py"
click node_document_routes "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/api/documents.py"
click node_audit_routes "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/api/audit.py"
click node_sql_store "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/models/models.py"
click node_pdf_processing "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/services/pdf_service.py"
click node_workflow "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/langgraph/workflow.py"
click node_classification "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/document_agent.py"
click node_clause_extraction "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/clause_agent.py"
click node_compliance_mapping "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/compliance_agent.py"
click node_risk_analysis "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/risk_agent.py"
click node_prediction "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/prediction_agent.py"
click node_ml_service "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/services/ml_service.py"
click node_recommendations "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/recommendation_agent.py"
click node_executive_report "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/report_agent.py"
click node_llm_client "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/llm_client.py"
click node_embedder "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/rag/embeddings/embedder.py"
click node_vector_store "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/rag/vectorstore/qdrant_store.py"
click node_retriever "https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/rag/retriever/retriever.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_portal_pages,node_upload_page,node_analysis_page,node_chat_page,node_reports_page,node_audit_page,node_api_client toneBlue
class node_api_gateway,node_auth_routes,node_document_routes,node_audit_routes,node_sql_store toneAmber
class node_pdf_processing,node_workflow,node_classification,node_clause_extraction,node_compliance_mapping,node_risk_analysis,node_recommendations,node_executive_report toneMint
class node_prediction,node_ml_service,node_llm_client,node_embedder,node_vector_store,node_retriever toneRose
class node_officer,node_ollama toneIndigo
```

## Components

### Web Portal

- [Portal Pages](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/dashboard/page.tsx): `frontend/app/dashboard/page.tsx`
- [Document Upload](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/upload/page.tsx): `frontend/app/upload/page.tsx`
- [Analysis View](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/analysis/%5Bid%5D/page.tsx): `frontend/app/analysis/[id]/page.tsx`
- [Document Chat](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/chat/%5Bid%5D/page.tsx): `frontend/app/chat/[id]/page.tsx`
- [Reports View](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/reports/page.tsx): `frontend/app/reports/page.tsx`
- [Audit View](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/app/audit/page.tsx): `frontend/app/audit/page.tsx`
- [REST Client](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/frontend/services/api.ts): `frontend/services/api.ts`

### API and Storage

- [FastAPI Gateway](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/api/auth.py): `backend/app/api/auth.py`
- [Document API](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/api/documents.py): `backend/app/api/documents.py`
- [Audit API](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/api/audit.py): `backend/app/api/audit.py`
- [Relational Records](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/models/models.py): `backend/app/models/models.py`

### Document Analysis

- [PDF Processing](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/services/pdf_service.py): `backend/app/services/pdf_service.py`
- [Analysis Workflow](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/langgraph/workflow.py): `backend/langgraph/workflow.py`
- [Document Classification](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/document_agent.py): `backend/agents/document_agent.py`
- [Clause Extraction](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/clause_agent.py): `backend/agents/clause_agent.py`
- [Compliance Mapping](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/compliance_agent.py): `backend/agents/compliance_agent.py`
- [Risk Analysis](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/risk_agent.py): `backend/agents/risk_agent.py`
- [Recommendations](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/recommendation_agent.py): `backend/agents/recommendation_agent.py`
- [Executive Reporting](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/report_agent.py): `backend/agents/report_agent.py`

### RAG and ML

- [Risk Prediction](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/prediction_agent.py): `backend/agents/prediction_agent.py`
- [ML and Explanations](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/app/services/ml_service.py): `backend/app/services/ml_service.py`
- [Ollama Client](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/agents/llm_client.py): `backend/agents/llm_client.py`
- [Text Embeddings](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/rag/embeddings/embedder.py): `backend/rag/embeddings/embedder.py`
- [Qdrant Vector Store](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/rag/vectorstore/qdrant_store.py): `backend/rag/vectorstore/qdrant_store.py`
- [RAG Retriever](https://github.com/shardul2711/ai-compliance-risk-copilot/blob/main/backend/rag/retriever/retriever.py): `backend/rag/retriever/retriever.py`

### Other components

- **Compliance Officer**
- **Ollama Service**

## Connections

- Compliance Officer → Document Upload: uploads documents (evidence: `README.md`)
- Compliance Officer → Portal Pages: uses portal (evidence: `README.md`)
- Document Upload → REST Client: calls upload (evidence: `frontend/app/upload/page.tsx`)
- Portal Pages → REST Client: requests data (evidence: `frontend/app/dashboard/page.tsx`)
- Analysis View → REST Client: requests analysis (evidence: `frontend/app/analysis/[id]/page.tsx`)
- Document Chat → REST Client: sends questions
- Reports View → REST Client: requests reports (evidence: `frontend/app/reports/page.tsx`)
- Audit View → REST Client: requests logs (evidence: `frontend/app/audit/page.tsx`)
- REST Client → FastAPI Gateway: REST requests (evidence: `README.md`)
- FastAPI Gateway → Authentication: routes auth (evidence: `backend/app/main.py`)
- FastAPI Gateway → Document API: routes documents (evidence: `backend/app/main.py`)
- FastAPI Gateway → Audit API: routes audits (evidence: `backend/app/main.py`)
- Document API → PDF Processing: processes PDFs (evidence: `backend/app/api/documents.py`)
- Document API → Analysis Workflow: triggers analysis (evidence: `backend/app/api/documents.py`)
- PDF Processing → Qdrant Vector Store: stores chunks (evidence: `backend/app/services/pdf_service.py`)
- Analysis Workflow → Document Classification: dispatches stage (evidence: `backend/langgraph/workflow.py`)
- Analysis Workflow → Clause Extraction: dispatches stage (evidence: `README.md`)
- Analysis Workflow → Compliance Mapping: dispatches stage (evidence: `backend/langgraph/workflow.py`)
- Analysis Workflow → Risk Analysis: dispatches stage (evidence: `README.md`)
- Analysis Workflow → Risk Prediction: dispatches stage (evidence: `backend/langgraph/workflow.py`)
- Analysis Workflow → Recommendations: dispatches stage (evidence: `README.md`)
- Analysis Workflow → Executive Reporting: dispatches stage (evidence: `backend/langgraph/workflow.py`)
- Risk Prediction → ML and Explanations: requests prediction (evidence: `backend/agents/prediction_agent.py`)
- Analysis Workflow → Relational Records: persists results (evidence: `backend/langgraph/workflow.py`)
- Audit API → Relational Records: reads audit logs (evidence: `backend/app/api/audit.py`)
- Document Classification → Ollama Client: calls LLM (evidence: `backend/agents/document_agent.py`)
- Clause Extraction → Ollama Client: calls LLM (evidence: `backend/agents/clause_agent.py`)
- Compliance Mapping → Ollama Client: calls LLM (evidence: `backend/agents/compliance_agent.py`)
- Risk Analysis → Ollama Client: calls LLM (evidence: `backend/agents/risk_agent.py`)
- Recommendations → Ollama Client: calls LLM (evidence: `backend/agents/recommendation_agent.py`)
- Executive Reporting → Ollama Client: calls LLM (evidence: `backend/agents/report_agent.py`)
- Ollama Client → Ollama Service: HTTP inference (evidence: `backend/agents/llm_client.py`)
- Qdrant Vector Store → Text Embeddings: embeds chunks (evidence: `backend/rag/vectorstore/qdrant_store.py`)
- RAG Retriever → Qdrant Vector Store: searches chunks (evidence: `backend/rag/retriever/retriever.py`)
- RAG Retriever → Ollama Service: generates answer (evidence: `backend/rag/retriever/retriever.py`)
- Document API → RAG Retriever: answers chat (evidence: `backend/app/api/documents.py`)
