# aayush349/intelli-credit architecture

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

- Interactive diagram: https://gitdiagram.com/aayush349/intelli-credit
- Repository: https://github.com/aayush349/intelli-credit

## Overview

#### Purpose and Entry Points
Intelli-Credit V3 is a local-first Indian corporate credit-appraisal system. It accepts borrower documents, produces structured risk evidence and a lending decision, then generates a Credit Appraisal Memo (CAM). The backend entry point is `app/main.py`; the user-facing Streamlit workflow starts at `streamlit_app/app.py`. API boundary modules are `app/api/upload.py`, `app/api/status.py`, and `app/api/analysis.py`.

#### Application Lifecycle and Persistence
Upload creates and tracks a credit application and its documents through FastAPI, SQLAlchemy, and SQLite. ORM and API contracts reside in `app/models.py`, `app/database.py`, and `app/schemas.py`. Processing is dispatched through an in-process threaded queue rather than an external broker, centered on `app/tasks/task_queue.py` and `app/tasks/pipeline.py`.

#### Ingestion and Parsing Layer
The pipeline classifies documents and routes them to domain parsers for GST, bank statements, financials, auditor reports, and CIBIL reports. Parsing normalizes heterogeneous source formats into structured results, forming the transition from raw upload material to analytical inputs. Key paths: `app/parsers/doc_classifier.py`, `app/parsers/base.py`, `app/parsers/gst_parser.py`, `app/parsers/bank_parser.py`, `app/parsers/financial_parser.py`, `app/parsers/auditor_parser.py`, `app/parsers/cibil_parser.py`.

#### Graph and Risk-Signal Analysis
A NetworkX knowledge graph connects borrower, promoter/director, guarantor, and related-entity information; query logic derives graph features and pyvis can render the relationship view. Anomaly detectors independently evaluate circular trading, round trips, EMI stress, revenue inconsistencies, and auditor-derived flags. Core paths: `app/graph/builder.py`, `app/graph/queries.py`, `app/anomaly/circular_trading.py`, `app/anomaly/round_trip.py`, `app/anomaly/emi_stress.py`, `app/anomaly/revenue_triangle.py`, `app/anomaly/auditor_bridge.py`.

#### External Due Diligence Boundary
The research agent conditionally invokes public/regulatory research tools for company records, RBI status/defaults, courts/DRT, news, and RERA. It supports DEMO mode through filesystem-backed cached responses, avoiding live-service dependence for demonstrations. Core orchestration and boundaries: `app/research/agent.py`, `app/research/cache_manager.py`, `app/research/tools/mca_lookup.py`, `app/research/tools/ecourt_scraper.py`, `app/research/tools/rbi_defaulter.py`, `app/research/tools/news_search.py`. Live calls use HTTP services; LLM narration/adjustment uses OpenRouter/Gemini when configured.

#### Credit Decisioning
Scoring combines deterministic rejection gates, weighted Five-Cs assessment, optional LLM qualitative adjustment, and loan sizing. This stage consumes parsed financials, graph features, anomaly results, and research evidence to produce a decision plus explainable rationale. Core paths: `app/scoring/engine.py`, `app/scoring/hard_rules.py`, `app/scoring/five_cs.py`, `app/scoring/llm_adjuster.py`, `app/scoring/loan_sizing.py`, `app/scoring/explanation.py`.

#### CAM Generation and Delivery
CAM generation converts the consolidated decision context into a structured Word document, with LLM-assisted narrative where enabled. The Streamlit pages expose upload, due diligence, research, decision, and CAM download as sequential operator-facing stages. Key paths: `app/cam/generator.py`, `app/cam/docx_builder.py`, `app/cam/llm_narrator.py`, `streamlit_app/pages/1_Upload.py`, `streamlit_app/pages/4_Decision.py`, `streamlit_app/pages/5_Download_CAM.py`.

#### Runtime and Data Boundaries
The deployment is containerizable via `Dockerfile` and `docker-compose.yml`; `render.yaml` indicates a Render deployment target. Data follows bronze/silver/gold-style filesystem stages plus research cache; the present tree explicitly contains `data/cache/`. Material libraries include FastAPI, Streamlit, SQLAlchemy/SQLite, NetworkX/pyvis, pandas/numpy/scipy, document/OCR parsers, and python-docx/pdf tooling. Configuration and service-mode/API-key control are centralized in `app/config.py`.

Main entry points: [`app/scoring/engine.py`](https://github.com/aayush349/intelli-credit/blob/main/app/scoring/engine.py) (Credit scoring engine), [`app/research/agent.py`](https://github.com/aayush349/intelli-credit/blob/main/app/research/agent.py) (Due-diligence agent), [`app/api/upload.py`](https://github.com/aayush349/intelli-credit/blob/main/app/api/upload.py) (Upload, status & analysis APIs), [`app/scoring/explanation.py`](https://github.com/aayush349/intelli-credit/blob/main/app/scoring/explanation.py) (Decision & rationale)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User &amp; API"]
  node_streamlit["Streamlit operator workflow<br/>Streamlit UI<br/>[app.py]"]
  node_api["FastAPI application<br/>API service<br/>[main.py]"]
  node_api_routes["Upload, status &amp; analysis APIs<br/>API routes<br/>[upload.py]"]
end

subgraph group_workflow["Application Workflow"]
  node_application_store[("Applications &amp; documents<br/>SQLAlchemy / SQLite<br/>[database.py]")]
  node_task_queue["In-process task queue<br/>threaded queue<br/>[task_queue.py]"]
  node_processing_pipeline["Document processing pipeline<br/>pipeline orchestrator<br/>[pipeline.py]"]
  node_document_classifier["Document classifier<br/>ingestion router<br/>[doc_classifier.py]"]
  node_domain_parsers["Domain parsers<br/>[base.py]"]
  node_structured_evidence["Structured evidence<br/>analytical inputs"]
end

subgraph group_analysis["Risk Analysis"]
  node_knowledge_graph{{"Borrower relationship graph<br/>NetworkX graph<br/>[builder.py]"}}
  node_graph_features["Relationship features<br/>graph queries<br/>[queries.py]"]
  node_anomaly_detection["Anomaly detectors<br/>risk signals"]
  node_research_agent["Due-diligence agent<br/>research orchestration<br/>[agent.py]"]
  node_research_cache[("Demo research cache<br/>filesystem cache<br/>[cache_manager.py]")]
  node_external_research(("Public &amp; regulatory services<br/>HTTP / LLM boundary<br/>[mca_lookup.py]"))
end

subgraph group_delivery["Decision &amp; Delivery"]
  node_scoring_engine["Credit scoring engine<br/>decision engine<br/>[engine.py]"]
  node_credit_decision["Decision &amp; rationale<br/>lending outcome<br/>[explanation.py]"]
  node_cam_generator["CAM generator<br/>Word document generation<br/>[generator.py]"]
end

node_streamlit -->|"submits workflow actions"| node_api
node_api -->|"serves"| node_api_routes
node_api_routes -->|"creates and tracks"| node_application_store
node_api_routes -->|"enqueues processing"| node_task_queue
node_task_queue -->|"runs"| node_processing_pipeline
node_processing_pipeline -->|"classifies uploads"| node_document_classifier
node_document_classifier -->|"routes by document type"| node_domain_parsers
node_domain_parsers -->|"normalizes"| node_structured_evidence
node_structured_evidence -->|"builds entities and links"| node_knowledge_graph
node_knowledge_graph -->|"derives features"| node_graph_features
node_structured_evidence -->|"evaluates risk signals"| node_anomaly_detection
node_structured_evidence -->|"supplies company context"| node_research_agent
node_research_agent -.->|"reads cached demo evidence"| node_research_cache
node_research_agent -.->|"queries when live"| node_external_research
node_structured_evidence -->|"financial and credit inputs"| node_scoring_engine
node_graph_features -->|"relationship risk"| node_scoring_engine
node_anomaly_detection -->|"anomaly flags"| node_scoring_engine
node_research_agent -->|"due-diligence evidence"| node_scoring_engine
node_scoring_engine -->|"produces"| node_credit_decision
node_credit_decision -->|"provides decision context"| node_cam_generator
node_cam_generator -->|"CAM download"| node_streamlit
node_credit_decision -->|"persists outcome"| node_application_store

click node_streamlit "https://github.com/aayush349/intelli-credit/blob/main/streamlit_app/app.py"
click node_api "https://github.com/aayush349/intelli-credit/blob/main/app/main.py"
click node_api_routes "https://github.com/aayush349/intelli-credit/blob/main/app/api/upload.py"
click node_application_store "https://github.com/aayush349/intelli-credit/blob/main/app/database.py"
click node_task_queue "https://github.com/aayush349/intelli-credit/blob/main/app/tasks/task_queue.py"
click node_processing_pipeline "https://github.com/aayush349/intelli-credit/blob/main/app/tasks/pipeline.py"
click node_document_classifier "https://github.com/aayush349/intelli-credit/blob/main/app/parsers/doc_classifier.py"
click node_domain_parsers "https://github.com/aayush349/intelli-credit/blob/main/app/parsers/base.py"
click node_knowledge_graph "https://github.com/aayush349/intelli-credit/blob/main/app/graph/builder.py"
click node_graph_features "https://github.com/aayush349/intelli-credit/blob/main/app/graph/queries.py"
click node_anomaly_detection "https://github.com/aayush349/intelli-credit/blob/main/app/anomaly/circular_trading.py"
click node_research_agent "https://github.com/aayush349/intelli-credit/blob/main/app/research/agent.py"
click node_research_cache "https://github.com/aayush349/intelli-credit/blob/main/app/research/cache_manager.py"
click node_external_research "https://github.com/aayush349/intelli-credit/blob/main/app/research/tools/mca_lookup.py"
click node_scoring_engine "https://github.com/aayush349/intelli-credit/blob/main/app/scoring/engine.py"
click node_credit_decision "https://github.com/aayush349/intelli-credit/blob/main/app/scoring/explanation.py"
click node_cam_generator "https://github.com/aayush349/intelli-credit/blob/main/app/cam/generator.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_streamlit,node_api,node_api_routes toneBlue
class node_application_store,node_task_queue,node_processing_pipeline,node_document_classifier,node_domain_parsers,node_structured_evidence toneAmber
class node_knowledge_graph,node_graph_features,node_anomaly_detection,node_research_agent,node_research_cache,node_external_research toneMint
class node_scoring_engine,node_credit_decision,node_cam_generator toneRose
```

## Components

### User & API

- [Streamlit operator workflow](https://github.com/aayush349/intelli-credit/blob/main/streamlit_app/app.py): Streamlit UI · Sequential upload-to-CAM operator experience. · `streamlit_app/app.py`
- [FastAPI application](https://github.com/aayush349/intelli-credit/blob/main/app/main.py): API service · `app/main.py`
- [Upload, status & analysis APIs](https://github.com/aayush349/intelli-credit/blob/main/app/api/upload.py): API routes · `app/api/upload.py`

### Application Workflow

- [Applications & documents](https://github.com/aayush349/intelli-credit/blob/main/app/database.py): SQLAlchemy / SQLite · Persists application lifecycle and document state. · `app/database.py`
- [In-process task queue](https://github.com/aayush349/intelli-credit/blob/main/app/tasks/task_queue.py): threaded queue · Dispatches processing without an external broker. · `app/tasks/task_queue.py`
- [Document processing pipeline](https://github.com/aayush349/intelli-credit/blob/main/app/tasks/pipeline.py): pipeline orchestrator · `app/tasks/pipeline.py`
- [Document classifier](https://github.com/aayush349/intelli-credit/blob/main/app/parsers/doc_classifier.py): ingestion router · `app/parsers/doc_classifier.py`
- [Domain parsers](https://github.com/aayush349/intelli-credit/blob/main/app/parsers/base.py): GST, bank, financial, audit & CIBIL · Normalizes heterogeneous borrower documents into structured inputs. · `app/parsers/base.py`
- **Structured evidence**: analytical inputs · Normalized financial, transaction, audit, and credit-report evidence.

### Risk Analysis

- [Borrower relationship graph](https://github.com/aayush349/intelli-credit/blob/main/app/graph/builder.py): NetworkX graph · Connects borrower, promoters, guarantors, and related entities. · `app/graph/builder.py`
- [Relationship features](https://github.com/aayush349/intelli-credit/blob/main/app/graph/queries.py): graph queries · `app/graph/queries.py`
- [Anomaly detectors](https://github.com/aayush349/intelli-credit/blob/main/app/anomaly/circular_trading.py): risk signals · Detects circular trading, round trips, EMI stress, revenue and audit flags. · `app/anomaly/circular_trading.py`
- [Due-diligence agent](https://github.com/aayush349/intelli-credit/blob/main/app/research/agent.py): research orchestration · Conditionally gathers company, RBI, court, news, and RERA evidence. · `app/research/agent.py`
- [Demo research cache](https://github.com/aayush349/intelli-credit/blob/main/app/research/cache_manager.py): filesystem cache · Filesystem-backed responses support offline demonstrations. · `app/research/cache_manager.py`
- [Public & regulatory services](https://github.com/aayush349/intelli-credit/blob/main/app/research/tools/mca_lookup.py): HTTP / LLM boundary · Live records, defaults, courts, news, and optional OpenRouter/Gemini calls. · `app/research/tools/mca_lookup.py`

### Decision & Delivery

- [Credit scoring engine](https://github.com/aayush349/intelli-credit/blob/main/app/scoring/engine.py): decision engine · Combines gates, Five-Cs, qualitative adjustment, and loan sizing. · `app/scoring/engine.py`
- [Decision & rationale](https://github.com/aayush349/intelli-credit/blob/main/app/scoring/explanation.py): lending outcome · Explainable approval, rejection, or conditional lending result. · `app/scoring/explanation.py`
- [CAM generator](https://github.com/aayush349/intelli-credit/blob/main/app/cam/generator.py): Word document generation · Builds the Credit Appraisal Memo with optional LLM narrative. · `app/cam/generator.py`

## Connections

- Streamlit operator workflow → FastAPI application: submits workflow actions
- FastAPI application → Upload, status & analysis APIs: serves
- Upload, status & analysis APIs → Applications & documents: creates and tracks
- Upload, status & analysis APIs → In-process task queue: enqueues processing
- In-process task queue → Document processing pipeline: runs
- Document processing pipeline → Document classifier: classifies uploads
- Document classifier → Domain parsers: routes by document type
- Domain parsers → Structured evidence: normalizes
- Structured evidence → Borrower relationship graph: builds entities and links
- Borrower relationship graph → Relationship features: derives features
- Structured evidence → Anomaly detectors: evaluates risk signals
- Structured evidence → Due-diligence agent: supplies company context
- Due-diligence agent → Demo research cache: reads cached demo evidence
- Due-diligence agent → Public & regulatory services: queries when live
- Structured evidence → Credit scoring engine: financial and credit inputs
- Relationship features → Credit scoring engine: relationship risk
- Anomaly detectors → Credit scoring engine: anomaly flags
- Due-diligence agent → Credit scoring engine: due-diligence evidence
- Credit scoring engine → Decision & rationale: produces
- Decision & rationale → CAM generator: provides decision context
- CAM generator → Streamlit operator workflow: CAM download
- Decision & rationale → Applications & documents: persists outcome
