# niharxd/trustchainai architecture

> Architecture diagram of the GitHub repository niharxd/trustchainai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/niharxd/trustchainai
- Repository: https://github.com/niharxd/trustchainai

## Overview

TrustChain AI is a multi-tenant procurement decision workspace. Its principal workflow is supplier and case management, private PDF evidence intake and extraction, evidence validation and intelligence, deterministic policy-based risk assessment, human review, and audit. The graph also preserves simulation, replay, policy management, and ledger verification. Some relationships are supported only by README descriptions or the source index; unsampled implementation links are omitted or marked unverified.

Main entry points: [`src/lib/supabase.ts`](https://github.com/niharxd/trustchainai/blob/main/src/lib/supabase.ts) (Supabase client), [`src/services/evidence.ts`](https://github.com/niharxd/trustchainai/blob/main/src/services/evidence.ts) (Evidence service), [`src/services/decision-workflow.ts`](https://github.com/niharxd/trustchainai/blob/main/src/services/decision-workflow.ts) (Decision workflow service), [`src/App.tsx`](https://github.com/niharxd/trustchainai/blob/main/src/App.tsx) (Workspace routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Workspace"]
  node_app["Workspace routing<br/>[App.tsx]"]
  node_auth["Authentication<br/>[auth.tsx]"]
  node_org["Organization access"]
  node_suppliers["Supplier management"]
  node_cases["Procurement cases"]
  node_procurement_service["Procurement service<br/>[procurement.ts]"]
  node_organizations_service["Organization service<br/>[organizations.ts]"]
end

subgraph group_evidence["Evidence"]
  node_evidence_ui["Evidence workspace"]
  node_evidence_service["Evidence service<br/>[evidence.ts]"]
  node_pdf["PDF extraction<br/>[pdf-extraction.ts]"]
  node_extract_fn["Extraction function<br/>[index.ts]"]
  node_intelligence_ui["Evidence intelligence"]
  node_intelligence["Evidence analysis"]
  node_requirements["Evidence requirements"]
end

subgraph group_decisions["Decision Governance"]
  node_policy_ui["Policy workspace"]
  node_policy["Decision policies<br/>[decision-policy.ts]"]
  node_decision_ui["Decision workspace"]
  node_risk["Risk engine<br/>[risk-engine.ts]"]
  node_workflow_service["Decision workflow service"]
  node_workflow_fn["Decision workflow function<br/>[index.ts]"]
  node_human_review["Human review<br/>[human-review.ts]"]
  node_simulator["Risk simulator"]
  node_replay["Decision replay"]
  node_replay_lib["Replay reconstruction<br/>[decision-replay.ts]"]
  node_audit["Audit ledger"]
end

subgraph group_platform["Shared Platform"]
  node_supabase["Supabase client<br/>[supabase.ts]"]
  node_database[("PostgreSQL records<br/>[database.ts]")]
  node_storage[("Private evidence storage<br/>[evidence.ts]")]
  node_validation["Procurement validation"]
  node_environment["Runtime configuration<br/>[environment.ts]"]
end

node_reviewer(("Procurement team"))

node_reviewer -->|"uses workspace"| node_app
node_app -->|"provides session"| node_auth
node_app -->|"gates access"| node_org
node_org -->|"loads memberships"| node_organizations_service
node_reviewer -->|"manages suppliers"| node_suppliers
node_reviewer -->|"manages cases"| node_cases
node_suppliers -->|"loads and saves"| node_procurement_service
node_cases -->|"loads and saves"| node_procurement_service
node_suppliers -->|"validates input"| node_validation
node_cases -->|"validates input"| node_validation
node_evidence_ui -->|"uploads documents"| node_evidence_service
node_evidence_service -->|"uploads files"| node_storage
node_evidence_service -->|"uses extraction"| node_pdf
node_reviewer -->|"submits PDFs"| node_evidence_ui
node_extract_fn -.->|"extracts evidence"| node_evidence_service
node_evidence_ui -->|"reviews findings"| node_intelligence_ui
node_intelligence_ui -->|"analyzes evidence"| node_intelligence
node_intelligence -->|"checks requirements"| node_requirements
node_policy_ui -->|"configures rules"| node_policy
node_decision_ui -->|"requests assessment"| node_workflow_service
node_workflow_service -->|"invokes workflow"| node_workflow_fn
node_workflow_fn -->|"calculates risk"| node_risk
node_risk -->|"applies policy"| node_policy
node_risk -->|"uses findings"| node_intelligence
node_decision_ui -->|"records review"| node_human_review
node_reviewer -->|"reviews recommendation"| node_decision_ui
node_simulator -->|"loads policy data"| node_workflow_service
node_simulator -->|"compares scenarios"| node_policy
node_replay -->|"reconstructs history"| node_replay_lib
node_replay -->|"loads snapshots"| node_workflow_service
node_reviewer -->|"verifies ledger"| node_audit
node_procurement_service -->|"queries records"| node_supabase
node_workflow_service -->|"reads and writes"| node_supabase
node_organizations_service -->|"loads organizations"| node_supabase
node_evidence_service -->|"stores metadata"| node_supabase
node_supabase -->|"types records"| node_database
node_auth -->|"manages sessions"| node_supabase
node_supabase -->|"reads configuration"| node_environment

click node_app "https://github.com/niharxd/trustchainai/blob/main/src/App.tsx"
click node_auth "https://github.com/niharxd/trustchainai/blob/main/src/app/auth.tsx"
click node_org "https://github.com/niharxd/trustchainai/blob/main/src/app/organization-context.tsx"
click node_suppliers "https://github.com/niharxd/trustchainai/blob/main/src/pages/SuppliersWorkspace.tsx"
click node_cases "https://github.com/niharxd/trustchainai/blob/main/src/pages/ProcurementCasesWorkspace.tsx"
click node_evidence_ui "https://github.com/niharxd/trustchainai/blob/main/src/pages/EvidenceWorkspace.tsx"
click node_evidence_service "https://github.com/niharxd/trustchainai/blob/main/src/services/evidence.ts"
click node_pdf "https://github.com/niharxd/trustchainai/blob/main/src/lib/pdf-extraction.ts"
click node_extract_fn "https://github.com/niharxd/trustchainai/blob/main/supabase/functions/extract-evidence/index.ts"
click node_intelligence_ui "https://github.com/niharxd/trustchainai/blob/main/src/pages/EvidenceIntelligenceWorkspace.tsx"
click node_intelligence "https://github.com/niharxd/trustchainai/blob/main/src/lib/evidence-intelligence.ts"
click node_requirements "https://github.com/niharxd/trustchainai/blob/main/src/lib/evidence-requirements.ts"
click node_policy_ui "https://github.com/niharxd/trustchainai/blob/main/src/pages/PolicyWorkspace.tsx"
click node_policy "https://github.com/niharxd/trustchainai/blob/main/src/lib/decision-policy.ts"
click node_decision_ui "https://github.com/niharxd/trustchainai/blob/main/src/pages/DecisionWorkspace.tsx"
click node_risk "https://github.com/niharxd/trustchainai/blob/main/src/lib/risk-engine.ts"
click node_workflow_service "https://github.com/niharxd/trustchainai/blob/main/src/services/decision-workflow.ts"
click node_workflow_fn "https://github.com/niharxd/trustchainai/blob/main/supabase/functions/decision-workflow/index.ts"
click node_human_review "https://github.com/niharxd/trustchainai/blob/main/src/lib/human-review.ts"
click node_simulator "https://github.com/niharxd/trustchainai/blob/main/src/pages/RiskSimulatorWorkspace.tsx"
click node_replay "https://github.com/niharxd/trustchainai/blob/main/src/pages/DecisionReplayWorkspace.tsx"
click node_replay_lib "https://github.com/niharxd/trustchainai/blob/main/src/lib/decision-replay.ts"
click node_audit "https://github.com/niharxd/trustchainai/blob/main/src/pages/AuditLedgerWorkspace.tsx"
click node_procurement_service "https://github.com/niharxd/trustchainai/blob/main/src/services/procurement.ts"
click node_organizations_service "https://github.com/niharxd/trustchainai/blob/main/src/services/organizations.ts"
click node_supabase "https://github.com/niharxd/trustchainai/blob/main/src/lib/supabase.ts"
click node_database "https://github.com/niharxd/trustchainai/blob/main/src/types/database.ts"
click node_storage "https://github.com/niharxd/trustchainai/blob/main/src/services/evidence.ts"
click node_validation "https://github.com/niharxd/trustchainai/blob/main/src/lib/procurement-validation.ts"
click node_environment "https://github.com/niharxd/trustchainai/blob/main/src/lib/environment.ts"

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_app,node_auth,node_org,node_suppliers,node_cases,node_procurement_service,node_organizations_service toneBlue
class node_evidence_ui,node_evidence_service,node_pdf,node_extract_fn,node_intelligence_ui,node_intelligence,node_requirements toneAmber
class node_policy_ui,node_policy,node_decision_ui,node_risk,node_workflow_service,node_workflow_fn,node_human_review,node_simulator,node_replay,node_replay_lib,node_audit toneMint
class node_supabase,node_database,node_storage,node_validation,node_environment toneRose
class node_reviewer toneIndigo
```

## Components

### Workspace

- [Workspace routing](https://github.com/niharxd/trustchainai/blob/main/src/App.tsx): `src/App.tsx`
- [Authentication](https://github.com/niharxd/trustchainai/blob/main/src/app/auth.tsx): `src/app/auth.tsx`
- [Organization access](https://github.com/niharxd/trustchainai/blob/main/src/app/organization-context.tsx): `src/app/organization-context.tsx`
- [Supplier management](https://github.com/niharxd/trustchainai/blob/main/src/pages/SuppliersWorkspace.tsx): `src/pages/SuppliersWorkspace.tsx`
- [Procurement cases](https://github.com/niharxd/trustchainai/blob/main/src/pages/ProcurementCasesWorkspace.tsx): `src/pages/ProcurementCasesWorkspace.tsx`
- [Procurement service](https://github.com/niharxd/trustchainai/blob/main/src/services/procurement.ts): `src/services/procurement.ts`
- [Organization service](https://github.com/niharxd/trustchainai/blob/main/src/services/organizations.ts): `src/services/organizations.ts`

### Evidence

- [Evidence workspace](https://github.com/niharxd/trustchainai/blob/main/src/pages/EvidenceWorkspace.tsx): `src/pages/EvidenceWorkspace.tsx`
- [Evidence service](https://github.com/niharxd/trustchainai/blob/main/src/services/evidence.ts): `src/services/evidence.ts`
- [PDF extraction](https://github.com/niharxd/trustchainai/blob/main/src/lib/pdf-extraction.ts): `src/lib/pdf-extraction.ts`
- [Extraction function](https://github.com/niharxd/trustchainai/blob/main/supabase/functions/extract-evidence/index.ts): `supabase/functions/extract-evidence/index.ts`
- [Evidence intelligence](https://github.com/niharxd/trustchainai/blob/main/src/pages/EvidenceIntelligenceWorkspace.tsx): `src/pages/EvidenceIntelligenceWorkspace.tsx`
- [Evidence analysis](https://github.com/niharxd/trustchainai/blob/main/src/lib/evidence-intelligence.ts): `src/lib/evidence-intelligence.ts`
- [Evidence requirements](https://github.com/niharxd/trustchainai/blob/main/src/lib/evidence-requirements.ts): `src/lib/evidence-requirements.ts`

### Decision Governance

- [Policy workspace](https://github.com/niharxd/trustchainai/blob/main/src/pages/PolicyWorkspace.tsx): `src/pages/PolicyWorkspace.tsx`
- [Decision policies](https://github.com/niharxd/trustchainai/blob/main/src/lib/decision-policy.ts): `src/lib/decision-policy.ts`
- [Decision workspace](https://github.com/niharxd/trustchainai/blob/main/src/pages/DecisionWorkspace.tsx): `src/pages/DecisionWorkspace.tsx`
- [Risk engine](https://github.com/niharxd/trustchainai/blob/main/src/lib/risk-engine.ts): `src/lib/risk-engine.ts`
- [Decision workflow service](https://github.com/niharxd/trustchainai/blob/main/src/services/decision-workflow.ts): `src/services/decision-workflow.ts`
- [Decision workflow function](https://github.com/niharxd/trustchainai/blob/main/supabase/functions/decision-workflow/index.ts): `supabase/functions/decision-workflow/index.ts`
- [Human review](https://github.com/niharxd/trustchainai/blob/main/src/lib/human-review.ts): `src/lib/human-review.ts`
- [Risk simulator](https://github.com/niharxd/trustchainai/blob/main/src/pages/RiskSimulatorWorkspace.tsx): `src/pages/RiskSimulatorWorkspace.tsx`
- [Decision replay](https://github.com/niharxd/trustchainai/blob/main/src/pages/DecisionReplayWorkspace.tsx): `src/pages/DecisionReplayWorkspace.tsx`
- [Replay reconstruction](https://github.com/niharxd/trustchainai/blob/main/src/lib/decision-replay.ts): `src/lib/decision-replay.ts`
- [Audit ledger](https://github.com/niharxd/trustchainai/blob/main/src/pages/AuditLedgerWorkspace.tsx): `src/pages/AuditLedgerWorkspace.tsx`

### Shared Platform

- [Supabase client](https://github.com/niharxd/trustchainai/blob/main/src/lib/supabase.ts): `src/lib/supabase.ts`
- [PostgreSQL records](https://github.com/niharxd/trustchainai/blob/main/src/types/database.ts): `src/types/database.ts`
- [Private evidence storage](https://github.com/niharxd/trustchainai/blob/main/src/services/evidence.ts): `src/services/evidence.ts`
- [Procurement validation](https://github.com/niharxd/trustchainai/blob/main/src/lib/procurement-validation.ts): `src/lib/procurement-validation.ts`
- [Runtime configuration](https://github.com/niharxd/trustchainai/blob/main/src/lib/environment.ts): `src/lib/environment.ts`

### Other components

- **Procurement team**

## Connections

- Procurement team → Workspace routing: uses workspace (evidence: `README.md`)
- Workspace routing → Authentication: provides session (evidence: `src/App.tsx`)
- Workspace routing → Organization access: gates access (evidence: `src/App.tsx`)
- Organization access → Organization service: loads memberships (evidence: `src/app/organization-context.tsx`)
- Procurement team → Supplier management: manages suppliers (evidence: `README.md`)
- Procurement team → Procurement cases: manages cases (evidence: `README.md`)
- Supplier management → Procurement service: loads and saves (evidence: `src/pages/SuppliersWorkspace.tsx`)
- Procurement cases → Procurement service: loads and saves (evidence: `src/pages/ProcurementCasesWorkspace.tsx`)
- Supplier management → Procurement validation: validates input (evidence: `src/pages/SuppliersWorkspace.tsx`)
- Procurement cases → Procurement validation: validates input (evidence: `src/pages/ProcurementCasesWorkspace.tsx`)
- Evidence workspace → Evidence service: uploads documents (evidence: `src/pages/EvidenceWorkspace.tsx`)
- Evidence service → Private evidence storage: uploads files (evidence: `src/services/evidence.ts`)
- Evidence service → PDF extraction: uses extraction (evidence: `src/services/evidence.ts`)
- Procurement team → Evidence workspace: submits PDFs (evidence: `README.md`)
- Extraction function → Evidence service: extracts evidence
- Evidence workspace → Evidence intelligence: reviews findings (evidence: `README.md`)
- Evidence intelligence → Evidence analysis: analyzes evidence (evidence: `src/pages/EvidenceIntelligenceWorkspace.tsx`)
- Evidence analysis → Evidence requirements: checks requirements (evidence: `src/lib/evidence-intelligence.ts`)
- Policy workspace → Decision policies: configures rules (evidence: `src/pages/PolicyWorkspace.tsx`)
- Decision workspace → Decision workflow service: requests assessment (evidence: `src/pages/DecisionWorkspace.tsx`)
- Decision workflow service → Decision workflow function: invokes workflow (evidence: `src/services/decision-workflow.ts`)
- Decision workflow function → Risk engine: calculates risk (evidence: `supabase/functions/decision-workflow/index.ts`)
- Risk engine → Decision policies: applies policy (evidence: `src/lib/risk-engine.ts`)
- Risk engine → Evidence analysis: uses findings (evidence: `src/lib/risk-engine.ts`)
- Decision workspace → Human review: records review (evidence: `src/pages/DecisionWorkspace.tsx`)
- Procurement team → Decision workspace: reviews recommendation (evidence: `README.md`)
- Risk simulator → Decision workflow service: loads policy data (evidence: `src/pages/RiskSimulatorWorkspace.tsx`)
- Risk simulator → Decision policies: compares scenarios (evidence: `src/pages/RiskSimulatorWorkspace.tsx`)
- Decision replay → Replay reconstruction: reconstructs history (evidence: `src/pages/DecisionReplayWorkspace.tsx`)
- Decision replay → Decision workflow service: loads snapshots (evidence: `src/pages/DecisionReplayWorkspace.tsx`)
- Procurement team → Audit ledger: verifies ledger (evidence: `README.md`)
- Procurement service → Supabase client: queries records (evidence: `src/services/procurement.ts`)
- Decision workflow service → Supabase client: reads and writes (evidence: `src/services/decision-workflow.ts`)
- Organization service → Supabase client: loads organizations (evidence: `src/services/organizations.ts`)
- Evidence service → Supabase client: stores metadata (evidence: `src/services/evidence.ts`)
- Supabase client → PostgreSQL records: types records (evidence: `src/lib/supabase.ts`)
- Authentication → Supabase client: manages sessions (evidence: `src/app/auth.tsx`)
- Supabase client → Runtime configuration: reads configuration (evidence: `src/lib/supabase.ts`)
