How youcef3939/credit-courtroom works
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: main.py FastAPI server · pipeline_adapter.py Pipeline adapter · nodes.py Debate stages · debate_workflow.py LangGraph debate
Components 20
Decision Workbench
- React workbench · Case investigation, verdict, evidence, transcript, and policy workflows.
frontend/src/App.tsx - API client
frontend/src/lib/api.ts
API & Audit Boundary
- FastAPI server
apps/api/main.py - Case-run routes
apps/api/routes_case_run.py - Cases & runs routes
apps/api/routes_cases.py - Pipeline adapter
apps/api/pipeline_adapter.py - Run store
apps/api/run_store.py - Policy routes
apps/api/routes_policies.py
Decision Engine
- LangGraph debate · Coordinates the auditable multi-agent loan verdict.
workflow/debate_workflow.py - Debate stages · Runs opening, rebuttal, final argument, and verdict stages.
workflow/nodes.py - Shared debate state
workflow/debate_state.py - LLM control
workflow/llm.py
Evidence Systems
- Applicant encoder
core/encoder_runtime.py - Similar-case retrieval · Returns applicant precedents with repayment and default labels.
retrieval/neighbors.py - Historical case ingestion
ingestion/dataset1_profiles/ingest_dataset1.py - Policy indexing
ingestion/policies/ingest_policies.py - Policy RAG · Supplies clauses for compliance citations.
apps/retrieval/policies.py
External Services
- Applicant vector memory
docker-compose.yml - Supabase policy store
core/supabase_client.py - Groq
Connections 22
- 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