# prem8123/schemeai architecture

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

- Interactive diagram: https://gitdiagram.com/prem8123/schemeai
- Repository: https://github.com/prem8123/schemeai

## Overview

SchemeAI matches student profiles against education schemes using deterministic eligibility rules, while retrieving provenance-backed evidence and optionally generating a grounded answer. Students submit a profile and question through either frontend; the API returns ranked eligibility results, evidence, freshness, and localized response data. The graph includes official-source ingestion, record validation, retrieval, and freshness capabilities documented in the README. The API implementation and several modules were not excerpted, so connections involving them are marked unverified rather than inferred as confirmed calls.

Main entry points: [`app/main.py`](https://github.com/prem8123/schemeai/blob/main/app/main.py) (REST API), [`app/data.py`](https://github.com/prem8123/schemeai/blob/main/app/data.py) (Scheme loader), [`app/agents.py`](https://github.com/prem8123/schemeai/blob/main/app/agents.py) (Planner), [`app/rag.py`](https://github.com/prem8123/schemeai/blob/main/app/rag.py) (Evidence retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Student interfaces"]
  node_streamlit["Streamlit UI<br/>[streamlit_app.py]"]
  node_web["Web UI<br/>[app.js]"]
end

subgraph group_service["API orchestration"]
  node_api["REST API<br/>[main.py]"]
  node_orchestrator["Planner<br/>[agents.py]"]
  node_language["Language detection<br/>[language.py]"]
  node_translations["Translations<br/>[translations.py]"]
  node_auth["API key protection<br/>[auth.py]"]
  node_security["Input security<br/>[security.py]"]
end

subgraph group_matching["Matching and evidence"]
  node_eligibility["Eligibility engine<br/>[eligibility.py]"]
  node_retrieval["Evidence retrieval<br/>[rag.py]"]
  node_llm["Grounded answer<br/>[llm.py]"]
  node_freshness["Freshness status<br/>[freshness.py]"]
end

subgraph group_records["Scheme records"]
  node_schemes[("Scheme loader<br/>[data.py]")]
  node_models["Domain models<br/>[models.py]"]
  node_schema["Provenance schemas<br/>[schema.py]"]
end

subgraph group_sources["Source ingestion"]
  node_ingestion["Document ingestion<br/>[ingestion.py]"]
  node_officialdata[("Official scheme records<br/>[schemes.jsonl]")]
  node_demodata[("Demo scheme records<br/>[schemes.jsonl]")]
  node_ingestcli["Official ingest command<br/>[ingest_official.py]"]
end

node_student(("Student"))

node_student -->|"enters profile"| node_streamlit
node_student -->|"enters profile"| node_web
node_streamlit -->|"posts recommendation"| node_api
node_web -->|"posts recommendation"| node_api
node_api -.->|"dispatches request"| node_orchestrator
node_orchestrator -->|"retrieves evidence"| node_retrieval
node_orchestrator -->|"ranks schemes"| node_eligibility
node_orchestrator -->|"reads schemes"| node_schemes
node_orchestrator -->|"requests answer"| node_llm
node_api -.->|"detects language"| node_language
node_api -.->|"localizes response"| node_translations
node_api -.->|"checks API key"| node_auth
node_api -.->|"sanitizes input"| node_security
node_retrieval -->|"loads schemes"| node_schemes
node_retrieval -->|"builds evidence"| node_schema
node_schemes -->|"validates clauses"| node_schema
node_schemes -->|"creates schemes"| node_models
node_eligibility -->|"evaluates profiles"| node_models
node_freshness -->|"reads freshness"| node_schemes
node_ingestcli -->|"ingests source"| node_ingestion
node_ingestion -.->|"validates records"| node_schema
node_ingestion -.->|"writes records"| node_officialdata
node_schemes -->|"loads official records"| node_officialdata
node_schemes -->|"loads demo records"| node_demodata

click node_streamlit "https://github.com/prem8123/schemeai/blob/main/frontend/streamlit_app.py"
click node_web "https://github.com/prem8123/schemeai/blob/main/web/app.js"
click node_api "https://github.com/prem8123/schemeai/blob/main/app/main.py"
click node_orchestrator "https://github.com/prem8123/schemeai/blob/main/app/agents.py"
click node_language "https://github.com/prem8123/schemeai/blob/main/app/language.py"
click node_translations "https://github.com/prem8123/schemeai/blob/main/app/translations.py"
click node_auth "https://github.com/prem8123/schemeai/blob/main/app/auth.py"
click node_security "https://github.com/prem8123/schemeai/blob/main/app/security.py"
click node_eligibility "https://github.com/prem8123/schemeai/blob/main/app/eligibility.py"
click node_retrieval "https://github.com/prem8123/schemeai/blob/main/app/rag.py"
click node_llm "https://github.com/prem8123/schemeai/blob/main/app/llm.py"
click node_freshness "https://github.com/prem8123/schemeai/blob/main/app/freshness.py"
click node_schemes "https://github.com/prem8123/schemeai/blob/main/app/data.py"
click node_models "https://github.com/prem8123/schemeai/blob/main/app/models.py"
click node_schema "https://github.com/prem8123/schemeai/blob/main/app/schema.py"
click node_ingestion "https://github.com/prem8123/schemeai/blob/main/app/ingestion.py"
click node_officialdata "https://github.com/prem8123/schemeai/blob/main/data/official/schemes.jsonl"
click node_demodata "https://github.com/prem8123/schemeai/blob/main/data/demo/schemes.jsonl"
click node_ingestcli "https://github.com/prem8123/schemeai/blob/main/scripts/ingest_official.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_web toneBlue
class node_api,node_orchestrator,node_language,node_translations,node_auth,node_security toneAmber
class node_eligibility,node_retrieval,node_llm,node_freshness toneMint
class node_schemes,node_models,node_schema toneRose
class node_ingestion,node_officialdata,node_demodata,node_ingestcli,node_student toneIndigo
```

## Components

### Student interfaces

- [Streamlit UI](https://github.com/prem8123/schemeai/blob/main/frontend/streamlit_app.py): `frontend/streamlit_app.py`
- [Web UI](https://github.com/prem8123/schemeai/blob/main/web/app.js): `web/app.js`

### API orchestration

- [REST API](https://github.com/prem8123/schemeai/blob/main/app/main.py): `app/main.py`
- [Planner](https://github.com/prem8123/schemeai/blob/main/app/agents.py): `app/agents.py`
- [Language detection](https://github.com/prem8123/schemeai/blob/main/app/language.py): `app/language.py`
- [Translations](https://github.com/prem8123/schemeai/blob/main/app/translations.py): `app/translations.py`
- [API key protection](https://github.com/prem8123/schemeai/blob/main/app/auth.py): `app/auth.py`
- [Input security](https://github.com/prem8123/schemeai/blob/main/app/security.py): `app/security.py`

### Matching and evidence

- [Eligibility engine](https://github.com/prem8123/schemeai/blob/main/app/eligibility.py): `app/eligibility.py`
- [Evidence retrieval](https://github.com/prem8123/schemeai/blob/main/app/rag.py): `app/rag.py`
- [Grounded answer](https://github.com/prem8123/schemeai/blob/main/app/llm.py): `app/llm.py`
- [Freshness status](https://github.com/prem8123/schemeai/blob/main/app/freshness.py): `app/freshness.py`

### Scheme records

- [Scheme loader](https://github.com/prem8123/schemeai/blob/main/app/data.py): `app/data.py`
- [Domain models](https://github.com/prem8123/schemeai/blob/main/app/models.py): `app/models.py`
- [Provenance schemas](https://github.com/prem8123/schemeai/blob/main/app/schema.py): `app/schema.py`

### Source ingestion

- [Document ingestion](https://github.com/prem8123/schemeai/blob/main/app/ingestion.py): `app/ingestion.py`
- [Official scheme records](https://github.com/prem8123/schemeai/blob/main/data/official/schemes.jsonl): `data/official/schemes.jsonl`
- [Demo scheme records](https://github.com/prem8123/schemeai/blob/main/data/demo/schemes.jsonl): `data/demo/schemes.jsonl`
- [Official ingest command](https://github.com/prem8123/schemeai/blob/main/scripts/ingest_official.py): `scripts/ingest_official.py`

### Other components

- **Student**

## Connections

- Student → Streamlit UI: enters profile (evidence: `frontend/streamlit_app.py`)
- Student → Web UI: enters profile (evidence: `web/app.js`)
- Streamlit UI → REST API: posts recommendation (evidence: `frontend/streamlit_app.py`)
- Web UI → REST API: posts recommendation (evidence: `web/app.js`)
- REST API → Planner: dispatches request
- Planner → Evidence retrieval: retrieves evidence (evidence: `app/agents.py`)
- Planner → Eligibility engine: ranks schemes (evidence: `app/agents.py`)
- Planner → Scheme loader: reads schemes (evidence: `app/agents.py`)
- Planner → Grounded answer: requests answer (evidence: `app/agents.py`)
- REST API → Language detection: detects language
- REST API → Translations: localizes response
- REST API → API key protection: checks API key
- REST API → Input security: sanitizes input
- Evidence retrieval → Scheme loader: loads schemes (evidence: `app/rag.py`)
- Evidence retrieval → Provenance schemas: builds evidence (evidence: `app/rag.py`)
- Scheme loader → Provenance schemas: validates clauses (evidence: `app/data.py`)
- Scheme loader → Domain models: creates schemes (evidence: `app/data.py`)
- Eligibility engine → Domain models: evaluates profiles (evidence: `app/eligibility.py`)
- Freshness status → Scheme loader: reads freshness (evidence: `app/freshness.py`)
- Official ingest command → Document ingestion: ingests source (evidence: `scripts/ingest_official.py`)
- Document ingestion → Provenance schemas: validates records
- Document ingestion → Official scheme records: writes records
- Scheme loader → Official scheme records: loads official records (evidence: `app/data.py`)
- Scheme loader → Demo scheme records: loads demo records (evidence: `app/data.py`)
