# youcef3939/credit-courtroom architecture

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

- Interactive diagram: https://gitdiagram.com/youcef3939/credit-courtroom
- Repository: https://github.com/youcef3939/credit-courtroom

## Overview

#### Purpose and Entry Points
Credit Courtroom is a credit-decision support platform that produces auditable loan verdicts from applicant features, similar historical cases, policy clauses, and an LLM-driven multi-agent debate. The primary server entry point is `apps/api/main.py`; the browser client boots from `frontend/src/main.tsx` and `frontend/src/App.tsx`. A standalone workflow demonstration is available at `run_debate_demo.py`.

#### API and Case Execution Boundary
FastAPI exposes case creation, execution, dashboards, retrieval, policy management, embedding, and health routes. Case-run orchestration is centered in `apps/api/routes_case_run.py`, which adapts API payloads into the decision pipeline through `apps/api/pipeline_adapter.py`. Case/run persistence and audit-oriented state are handled by `apps/api/run_store.py`; route separation includes `apps/api/routes_cases.py` and `apps/api/routes_runs.py`.

#### Applicant Encoding and Decision Memory
Applicant input is converted to the trained 128-dimensional feature vector using encoder artifacts and runtime code in `core/encoder_runtime.py` and `core/encoder.py`. Historical applicant records are ingested into Qdrant by `ingestion/dataset1_profiles/ingest_dataset1.py`. At decision time, `retrieval/neighbors.py` performs top-K similarity retrieval with applicant payloads and repayment/default labels; `retrieval/qdrant/retrieve_cases.py` adds payload-filtered retrieval. This is the evidence boundary between raw applicant data and agent reasoning.

#### Debate Workflow and LLM Control Flow
The core decision engine is a LangGraph workflow in `workflow/debate_workflow.py`, with shared structured state in `workflow/debate_state.py`. Nodes in `workflow/nodes.py` sequence Risk, Advocate, Moderator, and Judge stages: opening, rebuttal/counter, final argument, then verdict. Prompts in `workflow/prompts.py` require agents to reason from retrieved precedents; LLM access is abstracted through `workflow/llm.py` and configured for Groq.

#### Policy RAG and Compliance Evidence
Policy documents are uploaded and indexed through API routes including `apps/api/routes_policies.py` and `apps/api/routes_policies_list.py`. Ingestion scripts `ingestion/policies/ingest_policies.py` and `ingestion/policies/embed_policies.py` parse documents, chunk clauses, and embed them. `apps/retrieval/policies.py` retrieves relevant policy chunks through Supabase vector capabilities, while `core/supabase_client.py` establishes the Supabase boundary. Judge output is expected to cite policy evidence explicitly.

#### Frontend Decision Workbench
The Vite/React frontend communicates with the backend through `frontend/src/lib/api.ts`. Core investigator workflows are represented by `frontend/src/pages/NewCase.tsx`, `frontend/src/pages/CaseDetail.tsx`, and `frontend/src/pages/Dashboard.tsx`; policy upload/management is in `frontend/src/pages/Policies.tsx`. The UI renders verdicts, evidence, transcripts, and fraud-oriented placeholders via components such as `frontend/src/components/ui-custom/EvidenceCard.tsx` and `frontend/src/components/ui-custom/TranscriptMessage.tsx`.

#### Runtime Infrastructure and Limits
Python 3.10+ runs FastAPI, LangGraph, encoder inference, retrieval, and ingestion; Node 18+ runs the Vite frontend. `docker-compose.yml` provisions Qdrant for applicant-vector search and Neo4j for future fraud-graph capabilities. External dependencies are Groq for LLM inference and Supabase Storage/vector RPC for policy RAG. Neo4j fraud signals are partial/placeholder rather than a primary implemented decision stage.

Main entry points: [`apps/api/main.py`](https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/main.py) (FastAPI server), [`apps/api/pipeline_adapter.py`](https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/pipeline_adapter.py) (Pipeline adapter), [`workflow/nodes.py`](https://github.com/youcef3939/credit-courtroom/blob/main/workflow/nodes.py) (Debate stages), [`workflow/debate_workflow.py`](https://github.com/youcef3939/credit-courtroom/blob/main/workflow/debate_workflow.py) (LangGraph debate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Decision Workbench"]
  node_frontend["React workbench<br/>Vite / React<br/>[App.tsx]"]
  node_frontend_api["API client<br/>frontend boundary<br/>[api.ts]"]
end

subgraph group_api["API & Audit Boundary"]
  node_api_server["FastAPI server<br/>API entry point<br/>[main.py]"]
  node_case_run_routes["Case-run routes<br/>execution API<br/>[routes_case_run.py]"]
  node_case_routes["Cases & runs routes<br/>audit API<br/>[routes_cases.py]"]
  node_pipeline_adapter["Pipeline adapter<br/>API-to-workflow adapter"]
  node_run_store[("Run store<br/>case audit state<br/>[run_store.py]")]
  node_policy_routes["Policy routes<br/>policy API<br/>[routes_policies.py]"]
end

subgraph group_decision["Decision Engine"]
  node_debate_workflow{{"LangGraph debate<br/>decision workflow<br/>[debate_workflow.py]"}}
  node_debate_nodes["Debate stages<br/>[nodes.py]"]
  node_debate_state["Shared debate state<br/>structured workflow state<br/>[debate_state.py]"]
  node_llm["LLM control<br/>Groq abstraction<br/>[llm.py]"]
end

subgraph group_evidence["Evidence Systems"]
  node_encoder["Applicant encoder<br/>128-dim feature encoder<br/>[encoder_runtime.py]"]
  node_case_retrieval["Similar-case retrieval<br/>Qdrant top-K search<br/>[neighbors.py]"]
  node_case_ingestion["Historical case ingestion<br/>profile vector ingestion<br/>[ingest_dataset1.py]"]
  node_policy_ingestion["Policy indexing<br/>document chunking & embedding<br/>[ingest_policies.py]"]
  node_policy_retrieval["Policy RAG<br/>policy chunk retrieval<br/>[policies.py]"]
end

subgraph group_infra["External Services"]
  node_qdrant[("Applicant vector memory<br/>Qdrant<br/>[docker-compose.yml]")]
  node_supabase[("Supabase policy store<br/>Storage & vector RPC<br/>[supabase_client.py]")]
  node_groq["Groq<br/>LLM inference service"]
end

node_frontend -->|"uses"| node_frontend_api
node_frontend_api -->|"HTTP requests"| node_api_server
node_api_server -->|"serves"| node_case_run_routes
node_api_server -->|"serves"| node_case_routes
node_api_server -->|"serves"| node_policy_routes
node_case_run_routes -->|"starts case run"| node_pipeline_adapter
node_pipeline_adapter -->|"encodes applicant"| node_encoder
node_encoder -->|"feature vector"| node_case_retrieval
node_case_retrieval -->|"similarity search"| node_qdrant
node_pipeline_adapter -->|"invokes"| node_debate_workflow
node_debate_workflow -->|"reads and updates"| node_debate_state
node_debate_workflow -->|"executes"| node_debate_nodes
node_debate_nodes -->|"uses precedents"| node_case_retrieval
node_debate_nodes -->|"uses policy evidence"| node_policy_retrieval
node_debate_nodes -->|"generates arguments"| node_llm
node_llm -->|"inference"| node_groq
node_pipeline_adapter -->|"persists audit trail"| node_run_store
node_case_routes -->|"reads cases and runs"| node_run_store
node_policy_routes -->|"uploads for indexing"| node_policy_ingestion
node_policy_ingestion -->|"stores chunks and vectors"| node_supabase
node_policy_retrieval -->|"vector query"| node_supabase
node_case_ingestion -->|"indexes historical profiles"| node_qdrant

click node_frontend "https://github.com/youcef3939/credit-courtroom/blob/main/frontend/src/App.tsx"
click node_frontend_api "https://github.com/youcef3939/credit-courtroom/blob/main/frontend/src/lib/api.ts"
click node_api_server "https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/main.py"
click node_case_run_routes "https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/routes_case_run.py"
click node_case_routes "https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/routes_cases.py"
click node_pipeline_adapter "https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/pipeline_adapter.py"
click node_run_store "https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/run_store.py"
click node_policy_routes "https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/routes_policies.py"
click node_debate_workflow "https://github.com/youcef3939/credit-courtroom/blob/main/workflow/debate_workflow.py"
click node_debate_nodes "https://github.com/youcef3939/credit-courtroom/blob/main/workflow/nodes.py"
click node_debate_state "https://github.com/youcef3939/credit-courtroom/blob/main/workflow/debate_state.py"
click node_llm "https://github.com/youcef3939/credit-courtroom/blob/main/workflow/llm.py"
click node_encoder "https://github.com/youcef3939/credit-courtroom/blob/main/core/encoder_runtime.py"
click node_case_retrieval "https://github.com/youcef3939/credit-courtroom/blob/main/retrieval/neighbors.py"
click node_qdrant "https://github.com/youcef3939/credit-courtroom/blob/main/docker-compose.yml"
click node_case_ingestion "https://github.com/youcef3939/credit-courtroom/blob/main/ingestion/dataset1_profiles/ingest_dataset1.py"
click node_policy_ingestion "https://github.com/youcef3939/credit-courtroom/blob/main/ingestion/policies/ingest_policies.py"
click node_policy_retrieval "https://github.com/youcef3939/credit-courtroom/blob/main/apps/retrieval/policies.py"
click node_supabase "https://github.com/youcef3939/credit-courtroom/blob/main/core/supabase_client.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_frontend,node_frontend_api toneBlue
class node_api_server,node_case_run_routes,node_case_routes,node_pipeline_adapter,node_run_store,node_policy_routes toneAmber
class node_debate_workflow,node_debate_nodes,node_debate_state,node_llm toneMint
class node_encoder,node_case_retrieval,node_case_ingestion,node_policy_ingestion,node_policy_retrieval toneRose
class node_qdrant,node_supabase,node_groq toneIndigo
```

## Components

### Decision Workbench

- [React workbench](https://github.com/youcef3939/credit-courtroom/blob/main/frontend/src/App.tsx): Vite / React · Case investigation, verdict, evidence, transcript, and policy workflows. · `frontend/src/App.tsx`
- [API client](https://github.com/youcef3939/credit-courtroom/blob/main/frontend/src/lib/api.ts): frontend boundary · `frontend/src/lib/api.ts`

### API & Audit Boundary

- [FastAPI server](https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/main.py): API entry point · `apps/api/main.py`
- [Case-run routes](https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/routes_case_run.py): execution API · `apps/api/routes_case_run.py`
- [Cases & runs routes](https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/routes_cases.py): audit API · `apps/api/routes_cases.py`
- [Pipeline adapter](https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/pipeline_adapter.py): API-to-workflow adapter · `apps/api/pipeline_adapter.py`
- [Run store](https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/run_store.py): case audit state · `apps/api/run_store.py`
- [Policy routes](https://github.com/youcef3939/credit-courtroom/blob/main/apps/api/routes_policies.py): policy API · `apps/api/routes_policies.py`

### Decision Engine

- [LangGraph debate](https://github.com/youcef3939/credit-courtroom/blob/main/workflow/debate_workflow.py): decision workflow · Coordinates the auditable multi-agent loan verdict. · `workflow/debate_workflow.py`
- [Debate stages](https://github.com/youcef3939/credit-courtroom/blob/main/workflow/nodes.py): Risk · Advocate · Moderator · Judge · Runs opening, rebuttal, final argument, and verdict stages. · `workflow/nodes.py`
- [Shared debate state](https://github.com/youcef3939/credit-courtroom/blob/main/workflow/debate_state.py): structured workflow state · `workflow/debate_state.py`
- [LLM control](https://github.com/youcef3939/credit-courtroom/blob/main/workflow/llm.py): Groq abstraction · `workflow/llm.py`

### Evidence Systems

- [Applicant encoder](https://github.com/youcef3939/credit-courtroom/blob/main/core/encoder_runtime.py): 128-dim feature encoder · `core/encoder_runtime.py`
- [Similar-case retrieval](https://github.com/youcef3939/credit-courtroom/blob/main/retrieval/neighbors.py): Qdrant top-K search · Returns applicant precedents with repayment and default labels. · `retrieval/neighbors.py`
- [Historical case ingestion](https://github.com/youcef3939/credit-courtroom/blob/main/ingestion/dataset1_profiles/ingest_dataset1.py): profile vector ingestion · `ingestion/dataset1_profiles/ingest_dataset1.py`
- [Policy indexing](https://github.com/youcef3939/credit-courtroom/blob/main/ingestion/policies/ingest_policies.py): document chunking & embedding · `ingestion/policies/ingest_policies.py`
- [Policy RAG](https://github.com/youcef3939/credit-courtroom/blob/main/apps/retrieval/policies.py): policy chunk retrieval · Supplies clauses for compliance citations. · `apps/retrieval/policies.py`

### External Services

- [Applicant vector memory](https://github.com/youcef3939/credit-courtroom/blob/main/docker-compose.yml): Qdrant · `docker-compose.yml`
- [Supabase policy store](https://github.com/youcef3939/credit-courtroom/blob/main/core/supabase_client.py): Storage & vector RPC · `core/supabase_client.py`
- **Groq**: LLM inference service

## Connections

- React workbench → API client: uses
- API client → FastAPI server: HTTP requests
- FastAPI server → Case-run routes: serves
- FastAPI server → Cases & runs routes: serves
- FastAPI server → Policy routes: serves
- Case-run routes → Pipeline adapter: starts case run
- Pipeline adapter → Applicant encoder: encodes applicant
- Applicant encoder → Similar-case retrieval: feature vector
- Similar-case retrieval → Applicant vector memory: similarity search
- Pipeline adapter → LangGraph debate: invokes
- LangGraph debate → Shared debate state: reads and updates
- LangGraph debate → Debate stages: executes
- Debate stages → Similar-case retrieval: uses precedents
- Debate stages → Policy RAG: uses policy evidence
- Debate stages → LLM control: generates arguments
- LLM control → Groq: inference
- Pipeline adapter → Run store: persists audit trail
- Cases & runs routes → Run store: reads cases and runs
- Policy routes → Policy indexing: uploads for indexing
- Policy indexing → Supabase policy store: stores chunks and vectors
- Policy RAG → Supabase policy store: vector query
- Historical case ingestion → Applicant vector memory: indexes historical profiles
