# gitbrewhub/contract-obligation-agent architecture

> Architecture diagram of the GitHub repository gitbrewhub/contract-obligation-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gitbrewhub/contract-obligation-agent
- Repository: https://github.com/gitbrewhub/contract-obligation-agent

## Overview

Contract.AI accepts PDF/DOCX contracts and returns structured obligations with source evidence, verification status, deadlines, and risk signals for review. Its principal workflow is orchestrated by LangGraph and persists results for Flask API access and a React review interface. The graph preserves the documented processing stages and the separate ingestion, retrieval, and persistence layers. Some frontend/API details and implementation internals are unsampled; those connections are shown only where the README documents them.

Main entry points: [`graph/nodes.py`](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/graph/nodes.py) (Workflow Stages), [`pipeline/contract_pipeline.py`](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/pipeline/contract_pipeline.py) (Contract Pipeline), [`database/retrieval.py`](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/database/retrieval.py) (Evidence Retrieval), [`database/repository.py`](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/database/repository.py) (Record Repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Workflow"]
  node_workflow["LangGraph Workflow<br/>[workflow.py]"]
  node_workflow_nodes["Workflow Stages<br/>[nodes.py]"]
  node_standalone_pipeline["Contract Pipeline"]
end

subgraph group_analysis["Analysis"]
  node_extraction["Obligation Extraction"]
  node_nvidia_client["NVIDIA Client<br/>[nvidia_client.py]"]
  node_validation["Schema Validation<br/>[validation.py]"]
  node_verification["Source Verification"]
  node_deadline["Deadline Parsing<br/>[deadline_parser.py]"]
  node_risk["Risk Analysis<br/>[risk_engine.py]"]
end

subgraph group_data["Ingestion &amp; Data"]
  node_ingestion["Text Ingestion<br/>[loader.py]"]
  node_parsers["PDF / DOCX Parsers<br/>[pdf_parser.py]"]
  node_chunker["Text Chunking<br/>[chunker.py]"]
  node_embedder["Text Embeddings<br/>[embedder.py]"]
  node_retrieval["Evidence Retrieval<br/>[retrieval.py]"]
  node_repository["Record Repository<br/>[repository.py]"]
  node_store[("PostgreSQL + pgvector<br/>[schema.sql]")]
end

subgraph group_product["Review Product"]
  node_api["Flask REST API<br/>[app.py]"]
  node_frontend["Contract Review UI<br/>[App.jsx]"]
end

node_reviewer(("Contract Reviewer"))
node_contract["PDF / DOCX Contract"]
node_nvidia{{"NVIDIA-hosted LLM"}}

node_reviewer -->|"uploads contract"| node_frontend
node_contract -->|"submits document"| node_api
node_api -->|"starts workflow"| node_workflow
node_workflow -->|"dispatches stages"| node_workflow_nodes
node_workflow_nodes -->|"extracts text"| node_ingestion
node_ingestion -->|"selects parser"| node_parsers
node_workflow_nodes -->|"chunks text"| node_chunker
node_workflow_nodes -->|"embeds chunks"| node_embedder
node_workflow_nodes -->|"extracts obligations"| node_extraction
node_extraction -->|"calls client"| node_nvidia_client
node_nvidia_client -.->|"requests inference"| node_nvidia
node_workflow_nodes -->|"validates output"| node_validation
node_workflow_nodes -->|"retrieves evidence"| node_retrieval
node_retrieval -->|"embeds query"| node_embedder
node_workflow_nodes -->|"verifies evidence"| node_verification
node_verification -->|"embeds passages"| node_embedder
node_workflow_nodes -->|"parses deadlines"| node_deadline
node_workflow_nodes -->|"evaluates risk"| node_risk
node_workflow_nodes -->|"stores obligations"| node_repository
node_repository -->|"writes records"| node_store
node_workflow_nodes -->|"stores chunks"| node_repository
node_repository -->|"writes chunks"| node_store
node_workflow_nodes -->|"searches chunks"| node_retrieval
node_retrieval -->|"queries vectors"| node_store
node_api -->|"reads obligations"| node_retrieval
node_api -.->|"serves results"| node_frontend
node_standalone_pipeline -->|"extracts text"| node_ingestion
node_standalone_pipeline -->|"extracts obligations"| node_extraction
node_standalone_pipeline -->|"validates output"| node_validation
node_standalone_pipeline -->|"retrieves evidence"| node_retrieval
node_standalone_pipeline -->|"verifies evidence"| node_verification
node_standalone_pipeline -->|"evaluates risk"| node_risk
node_standalone_pipeline -->|"stores results"| node_repository

click node_workflow "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/graph/workflow.py"
click node_workflow_nodes "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/graph/nodes.py"
click node_standalone_pipeline "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/pipeline/contract_pipeline.py"
click node_ingestion "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/ingestion/loader.py"
click node_parsers "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/ingestion/pdf_parser.py"
click node_chunker "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/ingestion/chunker.py"
click node_embedder "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/ingestion/embedder.py"
click node_extraction "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/agents/extraction_agent.py"
click node_nvidia_client "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/agents/nvidia_client.py"
click node_validation "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/agents/validation.py"
click node_retrieval "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/database/retrieval.py"
click node_verification "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/agents/verification_agent.py"
click node_deadline "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/utils/deadline_parser.py"
click node_risk "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/agents/risk_engine.py"
click node_repository "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/database/repository.py"
click node_store "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/database/schema.sql"
click node_api "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/backend/app.py"
click node_frontend "https://github.com/gitbrewhub/contract-obligation-agent/blob/main/frontend/src/App.jsx"

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_workflow,node_workflow_nodes,node_standalone_pipeline,node_reviewer toneBlue
class node_extraction,node_nvidia_client,node_validation,node_verification,node_deadline,node_risk toneAmber
class node_ingestion,node_parsers,node_chunker,node_embedder,node_retrieval,node_repository,node_store toneMint
class node_api,node_frontend toneRose
class node_contract,node_nvidia toneIndigo
```

## Components

### Workflow

- [LangGraph Workflow](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/graph/workflow.py): `graph/workflow.py`
- [Workflow Stages](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/graph/nodes.py): `graph/nodes.py`
- [Contract Pipeline](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/pipeline/contract_pipeline.py): `pipeline/contract_pipeline.py`

### Analysis

- [Obligation Extraction](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/agents/extraction_agent.py): `agents/extraction_agent.py`
- [NVIDIA Client](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/agents/nvidia_client.py): `agents/nvidia_client.py`
- [Schema Validation](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/agents/validation.py): `agents/validation.py`
- [Source Verification](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/agents/verification_agent.py): `agents/verification_agent.py`
- [Deadline Parsing](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/utils/deadline_parser.py): `utils/deadline_parser.py`
- [Risk Analysis](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/agents/risk_engine.py): `agents/risk_engine.py`

### Ingestion & Data

- [Text Ingestion](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/ingestion/loader.py): `ingestion/loader.py`
- [PDF / DOCX Parsers](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/ingestion/pdf_parser.py): `ingestion/pdf_parser.py`
- [Text Chunking](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/ingestion/chunker.py): `ingestion/chunker.py`
- [Text Embeddings](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/ingestion/embedder.py): `ingestion/embedder.py`
- [Evidence Retrieval](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/database/retrieval.py): `database/retrieval.py`
- [Record Repository](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/database/repository.py): `database/repository.py`
- [PostgreSQL + pgvector](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/database/schema.sql): `database/schema.sql`

### Review Product

- [Flask REST API](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/backend/app.py): `backend/app.py`
- [Contract Review UI](https://github.com/gitbrewhub/contract-obligation-agent/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`

### Other components

- **Contract Reviewer**
- **PDF / DOCX Contract**
- **NVIDIA-hosted LLM**

## Connections

- Contract Reviewer → Contract Review UI: uploads contract (evidence: `README.md`)
- PDF / DOCX Contract → Flask REST API: submits document (evidence: `README.md`)
- Flask REST API → LangGraph Workflow: starts workflow (evidence: `backend/app.py`)
- LangGraph Workflow → Workflow Stages: dispatches stages (evidence: `graph/workflow.py`)
- Workflow Stages → Text Ingestion: extracts text (evidence: `graph/nodes.py`)
- Text Ingestion → PDF / DOCX Parsers: selects parser (evidence: `ingestion/loader.py`)
- Workflow Stages → Text Chunking: chunks text (evidence: `graph/nodes.py`)
- Workflow Stages → Text Embeddings: embeds chunks (evidence: `graph/nodes.py`)
- Workflow Stages → Obligation Extraction: extracts obligations (evidence: `graph/nodes.py`)
- Obligation Extraction → NVIDIA Client: calls client (evidence: `agents/extraction_agent.py`)
- NVIDIA Client → NVIDIA-hosted LLM: requests inference (evidence: `README.md`)
- Workflow Stages → Schema Validation: validates output (evidence: `graph/nodes.py`)
- Workflow Stages → Evidence Retrieval: retrieves evidence (evidence: `graph/nodes.py`)
- Evidence Retrieval → Text Embeddings: embeds query (evidence: `database/retrieval.py`)
- Workflow Stages → Source Verification: verifies evidence (evidence: `graph/nodes.py`)
- Source Verification → Text Embeddings: embeds passages (evidence: `agents/verification_agent.py`)
- Workflow Stages → Deadline Parsing: parses deadlines (evidence: `graph/nodes.py`)
- Workflow Stages → Risk Analysis: evaluates risk (evidence: `graph/nodes.py`)
- Workflow Stages → Record Repository: stores obligations (evidence: `graph/nodes.py`)
- Record Repository → PostgreSQL + pgvector: writes records (evidence: `database/repository.py`)
- Workflow Stages → Record Repository: stores chunks (evidence: `graph/nodes.py`)
- Record Repository → PostgreSQL + pgvector: writes chunks (evidence: `database/repository.py`)
- Workflow Stages → Evidence Retrieval: searches chunks (evidence: `graph/nodes.py`)
- Evidence Retrieval → PostgreSQL + pgvector: queries vectors (evidence: `database/retrieval.py`)
- Flask REST API → Evidence Retrieval: reads obligations (evidence: `backend/app.py`)
- Flask REST API → Contract Review UI: serves results (evidence: `README.md`)
- Contract Pipeline → Text Ingestion: extracts text (evidence: `pipeline/contract_pipeline.py`)
- Contract Pipeline → Obligation Extraction: extracts obligations (evidence: `pipeline/contract_pipeline.py`)
- Contract Pipeline → Schema Validation: validates output (evidence: `pipeline/contract_pipeline.py`)
- Contract Pipeline → Evidence Retrieval: retrieves evidence (evidence: `pipeline/contract_pipeline.py`)
- Contract Pipeline → Source Verification: verifies evidence (evidence: `pipeline/contract_pipeline.py`)
- Contract Pipeline → Risk Analysis: evaluates risk (evidence: `pipeline/contract_pipeline.py`)
- Contract Pipeline → Record Repository: stores results (evidence: `pipeline/contract_pipeline.py`)
