# krishnnavarun/ai-government-schema-eligibility-checker architecture

> Architecture diagram of the GitHub repository krishnnavarun/ai-government-schema-eligibility-checker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/krishnnavarun/ai-government-schema-eligibility-checker
- Repository: https://github.com/krishnnavarun/ai-government-schema-eligibility-checker

## Overview

#### Purpose and Runtime
This is a single Next.js application for discovering government schemes, checking eligibility, applying/saving schemes, and receiving scheme-oriented chat assistance. It combines React UI pages with Next.js route handlers and a Prisma-backed database. Primary app entry/layout: `client/app/layout.tsx`, `client/app/page.tsx`.

#### Authentication Boundary
Authentication is implemented as API endpoints for registration, login, and current-user lookup. Shared cryptographic, JWT, and Prisma access code forms the server-side security/data boundary.
- `client/app/api/auth/register/route.ts`
- `client/app/api/auth/login/route.ts`
- `client/app/api/auth/me/route.ts`
- `client/app/lib/crypto.ts`
- `client/app/lib/jwt.ts`
- `client/app/context/AuthContext.tsx`

#### Scheme Catalog and User Actions
Scheme APIs provide the central domain operations: list schemes, submit applications, and retrieve saved schemes. These route handlers likely mediate persistence through Prisma and are consumed by scheme-facing pages/context.
- `client/app/api/schemes/route.ts`
- `client/app/api/schemes/apply/route.ts`
- `client/app/api/schemes/saved/route.ts`
- `client/app/schemes/page.tsx`
- `client/app/context/SchemeContext.tsx`

#### Eligibility Flow
Eligibility is a dedicated user journey: users navigate to an ID-specific eligibility page, which calls the eligibility API to evaluate a scheme against profile or supplied criteria. Profile collection is a key input boundary.
- `client/app/eligibility/[id]/page.tsx`
- `client/app/api/schemes/eligibility/route.ts`
- `client/app/components/ProfileForm.tsx`

#### Conversational Assistance
A separate chat page invokes the scheme chat API. This is the likely integration boundary for any conversational or AI-backed scheme guidance; the file tree does not identify the external provider.
- `client/app/chat/page.tsx`
- `client/app/api/schemes/chat/route.ts`

#### Persistence Model
Prisma defines the authoritative relational data model and migration history, with a seed script for initial data. All server-side database access should converge through the shared Prisma client rather than be instantiated in route handlers.
- `client/prisma/schema.prisma`
- `client/prisma/migrations/20260612163359_init/migration.sql`
- `client/prisma/seed.js`
- `client/app/lib/prisma.ts`

#### Presentation and State Flow
React pages represent public/authenticated journeys; reusable cards render scheme records, while context providers distribute auth and scheme state through the client tree. Typical control flow is page/component → context or API route → auth/JWT validation and Prisma persistence → rendered scheme/profile result.
- `client/app/components/SchemeCard.tsx`
- `client/app/login/page.tsx`
- `client/app/register/page.tsx`
- `client/app/globals.css`

Main entry points: [`client/app/lib/prisma.ts`](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/lib/prisma.ts) (Prisma client), [`client/app/context/AuthContext.tsx`](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/context/AuthContext.tsx) (Auth state), [`client/app/context/SchemeContext.tsx`](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/context/SchemeContext.tsx) (Scheme state), [`client/app/layout.tsx`](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/layout.tsx) (App layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["React UI"]
  node_layout["App layout<br/>Next.js layout<br/>[layout.tsx]"]
  node_home["Scheme discovery<br/>page<br/>[page.tsx]"]
  node_auth_pages["Login &amp; registration<br/>pages"]
  node_scheme_page["Schemes page<br/>[page.tsx]"]
  node_eligibility_page["Eligibility journey<br/>dynamic page<br/>[page.tsx]"]
  node_chat_page["Scheme chat<br/>page<br/>[page.tsx]"]
  node_scheme_card["Scheme card<br/>[SchemeCard.tsx]"]
  node_profile_form["Profile form<br/>[ProfileForm.tsx]"]
  node_auth_context["Auth state<br/>React context<br/>[AuthContext.tsx]"]
  node_scheme_context["Scheme state<br/>React context<br/>[SchemeContext.tsx]"]
end

subgraph group_api["Server APIs"]
  node_auth_api{{"Authentication API<br/>route handlers"}}
  node_scheme_api{{"Scheme actions API<br/>route handlers"}}
  node_eligibility_api{{"Eligibility API<br/>route handler<br/>[route.ts]"}}
  node_chat_api{{"Scheme chat API<br/>route handler<br/>[route.ts]"}}
end

subgraph group_data["Data &amp; security"]
  node_crypto["Password crypto<br/>security utility<br/>[crypto.ts]"]
  node_jwt["JWT utility<br/>security utility<br/>[jwt.ts]"]
  node_prisma_client["Prisma client<br/>data access<br/>[prisma.ts]"]
  node_database[("Relational database<br/>Prisma model<br/>[schema.prisma]")]
end

node_layout -->|"provides"| node_auth_context
node_layout -->|"provides"| node_scheme_context
node_home -->|"renders"| node_scheme_card
node_scheme_page -->|"uses"| node_scheme_context
node_scheme_context -->|"fetches actions"| node_scheme_api
node_scheme_page -->|"renders"| node_scheme_card
node_auth_pages -->|"uses"| node_auth_context
node_auth_context -->|"auth requests"| node_auth_api
node_eligibility_page -->|"collects inputs"| node_profile_form
node_eligibility_page -->|"evaluates scheme"| node_eligibility_api
node_chat_page -->|"sends messages"| node_chat_api
node_auth_api -->|"hashes passwords"| node_crypto
node_auth_api -->|"issues and validates"| node_jwt
node_auth_api -->|"reads and writes users"| node_prisma_client
node_scheme_api -->|"reads and writes"| node_prisma_client
node_eligibility_api -->|"reads scheme/profile data"| node_prisma_client
node_chat_api -->|"reads scheme data"| node_prisma_client
node_prisma_client -->|"persists through"| node_database

click node_layout "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/layout.tsx"
click node_home "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/page.tsx"
click node_scheme_page "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/schemes/page.tsx"
click node_eligibility_page "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/eligibility/%5Bid%5D/page.tsx"
click node_chat_page "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/chat/page.tsx"
click node_scheme_card "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/components/SchemeCard.tsx"
click node_profile_form "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/components/ProfileForm.tsx"
click node_auth_context "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/context/AuthContext.tsx"
click node_scheme_context "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/context/SchemeContext.tsx"
click node_eligibility_api "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/api/schemes/eligibility/route.ts"
click node_chat_api "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/api/schemes/chat/route.ts"
click node_crypto "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/lib/crypto.ts"
click node_jwt "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/lib/jwt.ts"
click node_prisma_client "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/lib/prisma.ts"
click node_database "https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/prisma/schema.prisma"

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_layout,node_home,node_auth_pages,node_scheme_page,node_eligibility_page,node_chat_page,node_scheme_card,node_profile_form,node_auth_context,node_scheme_context toneBlue
class node_auth_api,node_scheme_api,node_eligibility_api,node_chat_api toneAmber
class node_crypto,node_jwt,node_prisma_client,node_database toneMint
```

## Components

### React UI

Next.js pages, components, and client state.

- [App layout](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/layout.tsx): Next.js layout · `client/app/layout.tsx`
- [Scheme discovery](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/page.tsx): page · `client/app/page.tsx`
- **Login & registration**: pages
- [Schemes page](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/schemes/page.tsx): page · `client/app/schemes/page.tsx`
- [Eligibility journey](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/eligibility/%5Bid%5D/page.tsx): dynamic page · `client/app/eligibility/[id]/page.tsx`
- [Scheme chat](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/chat/page.tsx): page · `client/app/chat/page.tsx`
- [Scheme card](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/components/SchemeCard.tsx): `client/app/components/SchemeCard.tsx`
- [Profile form](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/components/ProfileForm.tsx): Collects eligibility inputs. · `client/app/components/ProfileForm.tsx`
- [Auth state](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/context/AuthContext.tsx): React context · `client/app/context/AuthContext.tsx`
- [Scheme state](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/context/SchemeContext.tsx): React context · `client/app/context/SchemeContext.tsx`

### Server APIs

Route handlers for domain operations.

- **Authentication API**: route handlers · Registration, login, and current-user endpoints.
- **Scheme actions API**: route handlers · Lists schemes, submits applications, and returns saved schemes.
- [Eligibility API](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/api/schemes/eligibility/route.ts): route handler · `client/app/api/schemes/eligibility/route.ts`
- [Scheme chat API](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/api/schemes/chat/route.ts): route handler · Conversational guidance integration boundary. · `client/app/api/schemes/chat/route.ts`

### Data & security

Shared authentication and Prisma persistence boundary.

- [Password crypto](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/lib/crypto.ts): security utility · `client/app/lib/crypto.ts`
- [JWT utility](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/lib/jwt.ts): security utility · `client/app/lib/jwt.ts`
- [Prisma client](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/app/lib/prisma.ts): data access · Shared server-side database client. · `client/app/lib/prisma.ts`
- [Relational database](https://github.com/krishnnavarun/ai-government-schema-eligibility-checker/blob/main/client/prisma/schema.prisma): Prisma model · Schema, migrations, and seed data define the authoritative catalog and user data. · `client/prisma/schema.prisma`

## Connections

- App layout → Auth state: provides
- App layout → Scheme state: provides
- Scheme discovery → Scheme card: renders
- Schemes page → Scheme state: uses
- Scheme state → Scheme actions API: fetches actions
- Schemes page → Scheme card: renders
- Login & registration → Auth state: uses
- Auth state → Authentication API: auth requests
- Eligibility journey → Profile form: collects inputs
- Eligibility journey → Eligibility API: evaluates scheme
- Scheme chat → Scheme chat API: sends messages
- Authentication API → Password crypto: hashes passwords
- Authentication API → JWT utility: issues and validates
- Authentication API → Prisma client: reads and writes users
- Scheme actions API → Prisma client: reads and writes
- Eligibility API → Prisma client: reads scheme/profile data
- Scheme chat API → Prisma client: reads scheme data
- Prisma client → Relational database: persists through
