# ayushptl1810/hackanovatcet-2026 architecture

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

- Interactive diagram: https://gitdiagram.com/ayushptl1810/hackanovatcet-2026
- Repository: https://github.com/ayushptl1810/hackanovatcet-2026

## Overview

#### 1. Purpose and Runtime Entry Points
Haqq is a civic-tech platform that matches Indian citizens to welfare schemes through a React web portal and Twilio phone hotline. The backend is a FastAPI application started from `backend/main.py`; the browser SPA starts at `frontend/src/main.jsx` and is composed by `frontend/src/App.jsx`.

#### 2. API and Channel Boundary
FastAPI route modules separate citizen, scheme, assistant, identity/KYC, location, and voice webhook interfaces. Web and IVR channels should converge on shared services rather than duplicate matching logic.
- `backend/routes/citizen_routes.py`
- `backend/routes/schemes_routes.py`
- `backend/routes/voice_routes.py`

The frontend API client in `frontend/src/api.js` is the browser-to-backend boundary. Major user surfaces include dashboard, scheme browsing/wizard, assistant, autofill, and face gate components.

#### 3. Identity, Authentication, and Verified Profile
Citizen/operator access uses JWT sessions and PIN-oriented authentication; security/config are centralized in core modules. KYC and DigiLocker retrieval enrich the citizen profile used by matching and application autofill.
- `backend/services/auth_service.py`
- `backend/core/security.py`
- `backend/routes/kyc_routes.py`

DigiLocker is provider-based: route code delegates through a factory/interface, allowing mock, sandbox, or MeriPehchaan implementations selected by configuration.
- `backend/services/digilocker/base.py`
- `backend/services/digilocker/factory.py`
- `backend/services/digilocker/meripehchaan_provider.py`

#### 4. Scheme Data Lifecycle
Scheme records are persisted through SQLAlchemy models and exposed through a cache-backed search/matching layer. Ingestion scrapes or imports source data, extracts/enriches eligibility rules, then scheduler-driven refreshes atomically replace cached scheme datasets.
- `backend/db/models.py`
- `backend/services/ingestion.py`
- `backend/services/scheme_cache.py`

Source-specific acquisition and repair tooling are isolated from serving paths.
- `backend/scraper/myscheme_scraper.py`
- `backend/scraper/ingest_openny_dataset.py`
- `backend/services/scheduler.py`

#### 5. Discovery, Eligibility, and AI Reasoning
The central decision pipeline accepts a citizen profile or stated need, retrieves candidate schemes via filters/semantic search, evaluates structured eligibility, resolves incompatible benefits, and returns ranked/explainable matches.
- `backend/services/semantic.py`
- `backend/services/eligibility.py`
- `backend/services/conflict_graph.py`

Unstructured scheme text is converted into rules by extraction services, while assistant endpoints use the profile and matching context for grounded conversation/explanations.
- `backend/services/rule_extractor.py`
- `backend/services/extractor.py`
- `backend/routes/assistant_routes.py`

Groq-hosted LLM capability and sentence-transformer/scikit-learn-style semantic search are material external AI dependencies.

#### 6. Voice, Messaging, and Assisted Access
Twilio Voice webhooks implement multilingual IVR: DTMF or spoken input is processed through Sarvam ASR, shared semantic/eligibility services produce results, and Sarvam/Twilio TTS responds. Registered callers can be identified from their phone number.
- `backend/routes/voice_routes.py`
- `backend/services/sarvam_service.py`
- `backend/services/scheme_matching_service.py`

The same locator service supports web and hotline CSC lookup; notification utilities integrate Twilio SMS and WhatsApp.
- `backend/services/csc_locator_service.py`
- `backend/routes/locate_routes.py`
- `backend/utils/notifications.py`

#### 7. Infrastructure and Client Experience
Backend runtime dependencies are FastAPI/Uvicorn, SQLite via SQLAlchemy, Redis cache, APScheduler, and external Twilio, Sarvam, Groq, DigiLocker/MeriPehchaan, and KYC sandbox APIs. The Vite/React 19 frontend provides localized citizen flows, including scheme discovery and assisted application generation.
- `frontend/src/components/SchemeBrowser.jsx`
- `frontend/src/components/Assistant.jsx`
- `frontend/src/components/AutofillAgent.jsx`

Main entry points: [`backend/main.py`](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/main.py) (FastAPI runtime), [`backend/services/scheme_matching_service.py`](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/scheme_matching_service.py) (Scheme matching), [`backend/routes/voice_routes.py`](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/routes/voice_routes.py) (Twilio voice webhook), [`backend/services/scheme_cache.py`](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/scheme_cache.py) (Scheme cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web client"]
  node_spa_entry["React SPA<br/>frontend entry<br/>[main.jsx]"]
  node_app["App composition<br/>React shell<br/>[App.jsx]"]
  node_web_surfaces["Citizen flows<br/>React components<br/>[SchemeBrowser.jsx]"]
  node_api_client["API client<br/>browser boundary<br/>[api.js]"]
end

subgraph group_api["Backend API"]
  node_fastapi["FastAPI runtime<br/>API entry<br/>[main.py]"]
  node_citizen_routes["Citizen and scheme APIs<br/>route modules<br/>[citizen_routes.py]"]
  node_assistant_routes["Assistant API<br/>route module"]
  node_kyc_routes["KYC API<br/>route module<br/>[kyc_routes.py]"]
  node_voice_routes["Twilio voice webhook<br/>route module<br/>[voice_routes.py]"]
  node_auth["Auth and JWT/PIN<br/>identity service<br/>[auth_service.py]"]
  node_digilocker["DigiLocker providers<br/>provider factory<br/>[factory.py]"]
end

subgraph group_decision["Matching and data"]
  node_matching{{"Scheme matching<br/>decision service"}}
  node_semantic["Semantic retrieval<br/>search service<br/>[semantic.py]"]
  node_eligibility["Eligibility and conflicts<br/>rules engine<br/>[eligibility.py]"]
  node_scheme_cache[("Scheme cache<br/>cache-backed dataset<br/>[scheme_cache.py]")]
  node_scheme_db[("Scheme database<br/>SQLAlchemy models<br/>[models.py]")]
  node_ingestion["Ingestion and refresh<br/>data pipeline<br/>[ingestion.py]"]
  node_scheduler["Refresh scheduler<br/>scheduled jobs<br/>[scheduler.py]"]
end

subgraph group_providers["External providers"]
  node_sarvam(("Sarvam ASR/TTS<br/>voice AI provider"))
  node_twilio(("Twilio Voice/SMS<br/>communications provider"))
  node_ai_providers(("Groq and embedding models<br/>AI providers"))
  node_digilocker_ext(("DigiLocker/MeriPehchaan<br/>identity provider"))
end

node_spa_entry --> node_app
node_app --> node_web_surfaces
node_web_surfaces -->|"requests"| node_api_client
node_api_client -->|"HTTP"| node_fastapi
node_fastapi --> node_citizen_routes
node_fastapi --> node_assistant_routes
node_fastapi --> node_kyc_routes
node_fastapi -->|"webhook"| node_voice_routes
node_citizen_routes -->|"sessions"| node_auth
node_citizen_routes -->|"discover"| node_matching
node_assistant_routes -->|"grounded context"| node_matching
node_kyc_routes -->|"profile enrichment"| node_digilocker
node_digilocker -->|"retrieve documents"| node_digilocker_ext
node_voice_routes -->|"speech input/output"| node_sarvam
node_voice_routes -->|"shared matching"| node_matching
node_voice_routes -->|"IVR response"| node_twilio
node_matching -->|"retrieve candidates"| node_semantic
node_matching -->|"evaluate and rank"| node_eligibility
node_semantic -->|"search dataset"| node_scheme_cache
node_eligibility -->|"scheme rules"| node_scheme_cache
node_scheme_cache -->|"persisted records"| node_scheme_db
node_ingestion -->|"upsert schemes"| node_scheme_db
node_ingestion -->|"atomic refresh"| node_scheme_cache
node_scheduler -->|"scheduled refresh"| node_ingestion
node_semantic -->|"embeddings"| node_ai_providers
node_assistant_routes -->|"LLM reasoning"| node_ai_providers

click node_spa_entry "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/frontend/src/main.jsx"
click node_app "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/frontend/src/App.jsx"
click node_web_surfaces "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/frontend/src/components/SchemeBrowser.jsx"
click node_api_client "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/frontend/src/api.js"
click node_fastapi "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/main.py"
click node_citizen_routes "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/routes/citizen_routes.py"
click node_assistant_routes "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/routes/assistant_routes.py"
click node_kyc_routes "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/routes/kyc_routes.py"
click node_voice_routes "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/routes/voice_routes.py"
click node_auth "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/auth_service.py"
click node_digilocker "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/digilocker/factory.py"
click node_matching "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/scheme_matching_service.py"
click node_semantic "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/semantic.py"
click node_eligibility "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/eligibility.py"
click node_scheme_cache "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/scheme_cache.py"
click node_scheme_db "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/db/models.py"
click node_ingestion "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/ingestion.py"
click node_scheduler "https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/scheduler.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_spa_entry,node_app,node_web_surfaces,node_api_client toneBlue
class node_fastapi,node_citizen_routes,node_assistant_routes,node_kyc_routes,node_voice_routes,node_auth,node_digilocker toneAmber
class node_matching,node_semantic,node_eligibility,node_scheme_cache,node_scheme_db,node_ingestion,node_scheduler toneMint
class node_sarvam,node_twilio,node_ai_providers,node_digilocker_ext toneRose
```

## Components

### Web client

- [React SPA](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/frontend/src/main.jsx): frontend entry · `frontend/src/main.jsx`
- [App composition](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/frontend/src/App.jsx): React shell · `frontend/src/App.jsx`
- [Citizen flows](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/frontend/src/components/SchemeBrowser.jsx): React components · Discovery, assistant, and autofill surfaces. · `frontend/src/components/SchemeBrowser.jsx`
- [API client](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/frontend/src/api.js): browser boundary · `frontend/src/api.js`

### Backend API

- [FastAPI runtime](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/main.py): API entry · `backend/main.py`
- [Citizen and scheme APIs](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/routes/citizen_routes.py): route modules · `backend/routes/citizen_routes.py`
- [Assistant API](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/routes/assistant_routes.py): route module · `backend/routes/assistant_routes.py`
- [KYC API](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/routes/kyc_routes.py): route module · `backend/routes/kyc_routes.py`
- [Twilio voice webhook](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/routes/voice_routes.py): route module · `backend/routes/voice_routes.py`
- [Auth and JWT/PIN](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/auth_service.py): identity service · `backend/services/auth_service.py`
- [DigiLocker providers](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/digilocker/factory.py): provider factory · Selects mock, sandbox, or MeriPehchaan retrieval. · `backend/services/digilocker/factory.py`

### Matching and data

- [Scheme matching](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/scheme_matching_service.py): decision service · Shared profile/need-to-ranked-schemes pipeline. · `backend/services/scheme_matching_service.py`
- [Semantic retrieval](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/semantic.py): search service · `backend/services/semantic.py`
- [Eligibility and conflicts](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/eligibility.py): rules engine · `backend/services/eligibility.py`
- [Scheme cache](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/scheme_cache.py): cache-backed dataset · `backend/services/scheme_cache.py`
- [Scheme database](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/db/models.py): SQLAlchemy models · `backend/db/models.py`
- [Ingestion and refresh](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/ingestion.py): data pipeline · Imports, extracts rules, and refreshes serving data. · `backend/services/ingestion.py`
- [Refresh scheduler](https://github.com/ayushptl1810/hackanovatcet-2026/blob/main/backend/services/scheduler.py): scheduled jobs · `backend/services/scheduler.py`

### External providers

- **Sarvam ASR/TTS**: voice AI provider
- **Twilio Voice/SMS**: communications provider
- **Groq and embedding models**: AI providers
- **DigiLocker/MeriPehchaan**: identity provider

## Connections

- React SPA → App composition
- App composition → Citizen flows
- Citizen flows → API client: requests
- API client → FastAPI runtime: HTTP
- FastAPI runtime → Citizen and scheme APIs
- FastAPI runtime → Assistant API
- FastAPI runtime → KYC API
- FastAPI runtime → Twilio voice webhook: webhook
- Citizen and scheme APIs → Auth and JWT/PIN: sessions
- Citizen and scheme APIs → Scheme matching: discover
- Assistant API → Scheme matching: grounded context
- KYC API → DigiLocker providers: profile enrichment
- DigiLocker providers → DigiLocker/MeriPehchaan: retrieve documents
- Twilio voice webhook → Sarvam ASR/TTS: speech input/output
- Twilio voice webhook → Scheme matching: shared matching
- Twilio voice webhook → Twilio Voice/SMS: IVR response
- Scheme matching → Semantic retrieval: retrieve candidates
- Scheme matching → Eligibility and conflicts: evaluate and rank
- Semantic retrieval → Scheme cache: search dataset
- Eligibility and conflicts → Scheme cache: scheme rules
- Scheme cache → Scheme database: persisted records
- Ingestion and refresh → Scheme database: upsert schemes
- Ingestion and refresh → Scheme cache: atomic refresh
- Refresh scheduler → Ingestion and refresh: scheduled refresh
- Semantic retrieval → Groq and embedding models: embeddings
- Assistant API → Groq and embedding models: LLM reasoning
