# patrick0-cpu/loan-decision-engine architecture

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

- Interactive diagram: https://gitdiagram.com/patrick0-cpu/loan-decision-engine
- Repository: https://github.com/patrick0-cpu/loan-decision-engine

## Overview

This is a Streamlit loan-officer decision-support prototype: submitted applications become worker-processed cases, documents are read and checked, financial and risk results inform a model recommendation, and an officer makes the final decision. Separate event handling and an approval-gated outbox govern external actions. The dashboard also provides portfolio/model views, a read-only data assistant, audit and operations tools. The README documents several subsystems whose source was not sampled; those links are shown only where documented, and the graph does not imply unverified internal calls.

Main entry points: [`loan_system/workflow.py`](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/workflow.py) (Application workflow), [`loan_system/events.py`](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/events.py) (Event recording), [`worker.py`](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/worker.py) (Event worker), [`app/pages/4_Officer_review_queue.py`](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/pages/4_Officer_review_queue.py) (Officer review)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_intake["Intake and documents"]
  node_bulkintake["Bulk intake<br/>[bulk_tab.py]"]
  node_reader["Document reader<br/>[document_reader.py]"]
  node_extraction["Field extraction<br/>[extraction.py]"]
  node_guard["Content guard<br/>[guard.py]"]
  node_doccheck["Document checks<br/>[doc_check.py]"]
end

subgraph group_assessment["Case assessment"]
  node_workflow["Application workflow<br/>[workflow.py]"]
  node_calculations["Financial calculations<br/>[calculations.py]"]
  node_consistency["Consistency checks<br/>[consistency.py]"]
  node_risk["EBM risk scorer<br/>[risk_scorer.py]"]
  node_snapshot["Input snapshot<br/>[snapshot.py]"]
  node_decision["Kev recommendation<br/>[decision.py]"]
end

subgraph group_operations["Human review and operations"]
  node_reviewpage["Officer review"]
  node_operationspage["Operations monitor<br/>[6_Operations.py]"]
  node_queue["Queue priority<br/>[queue_priority.py]"]
  node_oversight["Approval gate<br/>[oversight.py]"]
  node_emergency["Emergency stop<br/>[emergency.py]"]
  node_monitor["Workload monitor<br/>[monitor.py]"]
  node_auth["Role authorization<br/>[auth.py]"]
end

subgraph group_platform["Dashboard and data"]
  node_dashboard["Streamlit dashboard<br/>[shared.py]"]
  node_scorepage["Application intake"]
  node_auditpage["Audit log view<br/>[5_Audit_log.py]"]
  node_assistant["Data assistant<br/>[assistant.py]"]
  node_query["Read-only data queries<br/>[query.py]"]
  node_tracing["Optional tracing<br/>[tracing.py]"]
end

subgraph group_actions["Events and external actions"]
  node_events["Event recording<br/>[events.py]"]
  node_worker["Event worker<br/>[worker.py]"]
  node_outbox["Action outbox<br/>[outbox.py]"]
  node_receiver["Simulated receiver<br/>[client.py]"]
  node_database[("SQLite database<br/>[db.py]")]
end

node_officer(("Loan officer"))

node_officer -->|"uses"| node_dashboard
node_officer -->|"submits case"| node_scorepage
node_dashboard -->|"offers chat"| node_assistant
node_scorepage -->|"records application"| node_events
node_bulkintake -->|"records events"| node_events
node_events -->|"claims events"| node_worker
node_worker -->|"processes case"| node_workflow
node_workflow -->|"reads documents"| node_reader
node_reader -->|"extracts fields"| node_extraction
node_workflow -->|"scans content"| node_guard
node_workflow -->|"checks documents"| node_doccheck
node_workflow -->|"calculates metrics"| node_calculations
node_workflow -->|"checks consistency"| node_consistency
node_workflow -->|"scores risk"| node_risk
node_workflow -->|"records snapshot"| node_snapshot
node_workflow -->|"requests recommendation"| node_decision
node_workflow -->|"sets priority"| node_queue
node_officer -->|"reviews case"| node_reviewpage
node_reviewpage -->|"records decision"| node_events
node_reviewpage -->|"orders cases"| node_queue
node_reviewpage -->|"reruns checks"| node_workflow
node_worker -->|"applies decision"| node_oversight
node_oversight -->|"queues approved actions"| node_outbox
node_worker -->|"executes actions"| node_outbox
node_outbox -->|"sends or looks up"| node_receiver
node_operationspage -->|"records interventions"| node_events
node_operationspage -->|"shows workload"| node_monitor
node_operationspage -->|"controls stop"| node_emergency
node_assistant -->|"builds data queries"| node_query
node_query -->|"reads data"| node_database
node_worker -->|"persists workflow"| node_database
node_events -->|"stores events"| node_database
node_oversight -->|"checks approvers"| node_auth
node_auditpage -.->|"reads audit records"| node_database
node_workflow -.->|"records spans"| node_tracing
node_officer -->|"intervenes"| node_operationspage

click node_dashboard "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/shared.py"
click node_scorepage "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/pages/3_Score_an_applicant.py"
click node_reviewpage "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/pages/4_Officer_review_queue.py"
click node_operationspage "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/pages/6_Operations.py"
click node_auditpage "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/pages/5_Audit_log.py"
click node_bulkintake "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/bulk_tab.py"
click node_events "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/events.py"
click node_worker "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/worker.py"
click node_workflow "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/workflow.py"
click node_reader "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/document_reader.py"
click node_extraction "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/extraction.py"
click node_guard "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/guard.py"
click node_doccheck "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/doc_check.py"
click node_calculations "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/calculations.py"
click node_consistency "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/consistency.py"
click node_risk "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/risk_scorer.py"
click node_snapshot "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/snapshot.py"
click node_decision "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/decision.py"
click node_queue "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/queue_priority.py"
click node_oversight "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/oversight.py"
click node_outbox "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/outbox.py"
click node_receiver "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/receiver/client.py"
click node_emergency "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/emergency.py"
click node_assistant "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/assistant.py"
click node_query "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/query.py"
click node_monitor "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/monitor.py"
click node_database "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/db.py"
click node_auth "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/auth.py"
click node_tracing "https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/tracing.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_bulkintake,node_reader,node_extraction,node_guard,node_doccheck toneBlue
class node_workflow,node_calculations,node_consistency,node_risk,node_snapshot,node_decision toneAmber
class node_reviewpage,node_operationspage,node_queue,node_oversight,node_emergency,node_monitor,node_auth toneMint
class node_dashboard,node_scorepage,node_auditpage,node_assistant,node_query,node_tracing toneRose
class node_events,node_worker,node_outbox,node_receiver,node_database,node_officer toneIndigo
```

## Components

### Intake and documents

- [Bulk intake](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/bulk_tab.py): `app/bulk_tab.py`
- [Document reader](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/document_reader.py): `loan_system/document_reader.py`
- [Field extraction](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/extraction.py): `loan_system/extraction.py`
- [Content guard](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/guard.py): `loan_system/guard.py`
- [Document checks](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/doc_check.py): `loan_system/doc_check.py`

### Case assessment

- [Application workflow](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/workflow.py): `loan_system/workflow.py`
- [Financial calculations](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/calculations.py): `loan_system/calculations.py`
- [Consistency checks](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/consistency.py): `loan_system/consistency.py`
- [EBM risk scorer](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/risk_scorer.py): `loan_system/risk_scorer.py`
- [Input snapshot](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/snapshot.py): `loan_system/snapshot.py`
- [Kev recommendation](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/decision.py): `loan_system/decision.py`

### Human review and operations

- [Officer review](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/pages/4_Officer_review_queue.py): `app/pages/4_Officer_review_queue.py`
- [Operations monitor](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/pages/6_Operations.py): `app/pages/6_Operations.py`
- [Queue priority](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/queue_priority.py): `loan_system/queue_priority.py`
- [Approval gate](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/oversight.py): `loan_system/oversight.py`
- [Emergency stop](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/emergency.py): `loan_system/emergency.py`
- [Workload monitor](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/monitor.py): `loan_system/monitor.py`
- [Role authorization](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/auth.py): `loan_system/auth.py`

### Dashboard and data

- [Streamlit dashboard](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/shared.py): `app/shared.py`
- [Application intake](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/pages/3_Score_an_applicant.py): `app/pages/3_Score_an_applicant.py`
- [Audit log view](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/app/pages/5_Audit_log.py): `app/pages/5_Audit_log.py`
- [Data assistant](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/assistant.py): `loan_system/assistant.py`
- [Read-only data queries](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/query.py): `loan_system/query.py`
- [Optional tracing](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/tracing.py): `loan_system/tracing.py`

### Events and external actions

- [Event recording](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/events.py): `loan_system/events.py`
- [Event worker](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/worker.py): `worker.py`
- [Action outbox](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/outbox.py): `loan_system/outbox.py`
- [Simulated receiver](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/receiver/client.py): `loan_system/receiver/client.py`
- [SQLite database](https://github.com/patrick0-cpu/loan-decision-engine/blob/main/loan_system/db.py): `loan_system/db.py`

### Other components

- **Loan officer**

## Connections

- Loan officer → Streamlit dashboard: uses (evidence: `README.md`)
- Loan officer → Application intake: submits case (evidence: `README.md`)
- Streamlit dashboard → Data assistant: offers chat (evidence: `README.md`)
- Application intake → Event recording: records application
- Bulk intake → Event recording: records events (evidence: `app/bulk_tab.py`)
- Event recording → Event worker: claims events (evidence: `worker.py`)
- Event worker → Application workflow: processes case (evidence: `worker.py`)
- Application workflow → Document reader: reads documents (evidence: `loan_system/workflow.py`)
- Document reader → Field extraction: extracts fields (evidence: `loan_system/document_reader.py`)
- Application workflow → Content guard: scans content (evidence: `loan_system/guard.py`)
- Application workflow → Document checks: checks documents (evidence: `README.md`)
- Application workflow → Financial calculations: calculates metrics (evidence: `loan_system/workflow.py`)
- Application workflow → Consistency checks: checks consistency (evidence: `loan_system/workflow.py`)
- Application workflow → EBM risk scorer: scores risk (evidence: `loan_system/workflow.py`)
- Application workflow → Input snapshot: records snapshot (evidence: `loan_system/workflow.py`)
- Application workflow → Kev recommendation: requests recommendation (evidence: `loan_system/workflow.py`)
- Application workflow → Queue priority: sets priority (evidence: `loan_system/workflow.py`)
- Loan officer → Officer review: reviews case (evidence: `README.md`)
- Officer review → Event recording: records decision (evidence: `app/pages/4_Officer_review_queue.py`)
- Officer review → Queue priority: orders cases (evidence: `app/pages/4_Officer_review_queue.py`)
- Officer review → Application workflow: reruns checks (evidence: `app/pages/4_Officer_review_queue.py`)
- Event worker → Approval gate: applies decision (evidence: `README.md`)
- Approval gate → Action outbox: queues approved actions (evidence: `README.md`)
- Event worker → Action outbox: executes actions (evidence: `worker.py`)
- Action outbox → Simulated receiver: sends or looks up (evidence: `README.md`)
- Operations monitor → Event recording: records interventions (evidence: `app/pages/6_Operations.py`)
- Operations monitor → Workload monitor: shows workload (evidence: `app/pages/6_Operations.py`)
- Operations monitor → Emergency stop: controls stop (evidence: `app/pages/6_Operations.py`)
- Data assistant → Read-only data queries: builds data queries (evidence: `loan_system/assistant.py`)
- Read-only data queries → SQLite database: reads data (evidence: `loan_system/query.py`)
- Event worker → SQLite database: persists workflow (evidence: `worker.py`)
- Event recording → SQLite database: stores events (evidence: `loan_system/events.py`)
- Approval gate → Role authorization: checks approvers (evidence: `loan_system/oversight.py`)
- Audit log view → SQLite database: reads audit records
- Application workflow → Optional tracing: records spans (evidence: `loan_system/workflow.py`)
- Loan officer → Operations monitor: intervenes (evidence: `README.md`)
