# sbktckp/quero architecture

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

- Interactive diagram: https://gitdiagram.com/sbktckp/quero
- Repository: https://github.com/sbktckp/quero

## Overview

#### Purpose and Runtime
Quero is a multi-tenant NEET/JEE preparation platform for institutes: faculty manage question banks and mock tests; students join an institute, take tests, and review attempts; admins manage people and progress. It runs as a TanStack Start/React 19 application on Vite, deployed to Vercel, with Bun for development/package management. Entry/runtime points are `src/start.ts`, `src/server.ts`, and `src/router.tsx`.

#### Routing and Access Boundary
TanStack Router file-based routes separate public marketing/auth pages from authenticated product areas. The authenticated route shell establishes the protected application boundary, then routes users to student, institute, mentor, counseling, and administrative workflows. Key paths: `src/routes/__root.tsx`, `src/routes/_authenticated/route.tsx`, `src/routes/_authenticated/institute-workspace.tsx`.

#### Identity, Tenancy, and Authorization
Supabase Auth supplies identity; Supabase Postgres and RLS enforce data isolation. Institutes are top-level tenants with optional branch hierarchy; users have role-specific access, and students belong to one institute at a time. Sensitive cross-tenant actions are intended to pass through `SECURITY DEFINER` database functions rather than broad client-side table access. Relevant boundaries: `src/integrations/supabase/auth-middleware.ts`, `src/lib/auth.tsx`, `supabase/migrations/20260811100000_institute_isolation_hardening.sql`.

#### Institute Workspace and Membership
The institute workspace is the operational hub for onboarding/join approval, faculty administration, student roster visibility, and role-specific dashboards. Student join-code enrollment creates a pending relationship for institute-admin approval. Components and domain operations are centered in `src/components/institute/institute-admin-dashboard.tsx`, `src/components/institute/institute-join-card.tsx`, and `src/lib/institute.ts`.

#### Question Bank and Content Ingestion
Faculty/admins create questions in a shared taxonomy of subject, chapter, and topic. Content proceeds through draft, submitted, approved, or rejected review states; only approved content can enter usable tests. CSV/XLSX and PDF-oriented import UI feed import/domain logic that resolves taxonomy names, identifies duplicate stems, exposes unmatched data, and supports constrained undo. Key paths: `src/components/institute/question-import.tsx`, `src/components/institute/faculty-csv-import.tsx`, `src/lib/faculty-import.ts`.

#### Test Construction, Publication, and Attempts
The core pipeline is import → build → review → publish → student attempt → review. Test lifecycle transitions are draft, in progress, ready for review, published, and closed. Full NEET tests require four 45-question sections; database constraints prevent repeats and publish gating requires complete approved sections. The student-facing attempt and review routes consume the resulting assignments. Key paths: `src/components/institute/test-workbench.tsx`, `src/lib/test-builder.ts`, `src/routes/_authenticated/test.$attemptId.tsx`.

#### External Services and Auxiliary Domains
Supabase is the primary backend for database, Auth, RPC, and policy enforcement, accessed through browser/server clients and typed bindings. Razorpay supports billing/payment flows and receives a server webhook. OpenAI-compatible AI SDK features support administrative content generation; mentor and counseling domains are separate authenticated product modules. Key paths: `src/integrations/supabase/client.ts`, `src/lib/razorpay.server.ts`, `src/routes/api/razorpay-webhook.ts`.

Main entry points: [`src/integrations/supabase/client.ts`](https://github.com/sbktckp/quero/blob/main/src/integrations/supabase/client.ts) (Supabase backend), [`src/routes/_authenticated/route.tsx`](https://github.com/sbktckp/quero/blob/main/src/routes/_authenticated/route.tsx) (Authenticated shell), [`src/router.tsx`](https://github.com/sbktckp/quero/blob/main/src/router.tsx) (File-based router), [`src/components/institute/institute-admin-dashboard.tsx`](https://github.com/sbktckp/quero/blob/main/src/components/institute/institute-admin-dashboard.tsx) (Institute operations hub)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_runtime{{"Start/Vite runtime<br/>application runtime<br/>[start.ts]"}}
  node_server["Server entry<br/>[server.ts]"]
  node_router["File-based router<br/>routing<br/>[router.tsx]"]
  node_public_routes["Public marketing and auth<br/>route area<br/>[__root.tsx]"]
  node_authenticated_shell["Authenticated shell<br/>access boundary<br/>[route.tsx]"]
end

subgraph group_institute["Institute Operations"]
  node_workspace_route["Institute workspace route"]
  node_workspace["Institute operations hub<br/>dashboard"]
  node_join_enrollment["Join-code enrollment<br/>membership workflow"]
  node_institute_domain["Institute domain operations<br/>domain logic<br/>[institute.ts]"]
  node_content_import["Question import UI<br/>content ingestion"]
  node_faculty_import["Faculty CSV import<br/>content ingestion"]
  node_import_logic["Import resolution<br/>domain logic<br/>[faculty-import.ts]"]
  node_test_workbench["Test workbench<br/>test authoring<br/>[test-workbench.tsx]"]
  node_test_builder["Test lifecycle rules<br/>domain logic<br/>[test-builder.ts]"]
  node_student_attempt["Student attempt and review<br/>assessment route"]
end

subgraph group_backend["Backend Boundaries"]
  node_supabase_auth["Supabase Auth middleware<br/>identity boundary<br/>[auth-middleware.ts]"]
  node_auth_context["Client auth context<br/>identity client<br/>[auth.tsx]"]
  node_supabase[("Supabase backend<br/>Auth, Postgres, RPC, RLS<br/>[client.ts]")]
  node_tenant_rls["Tenant isolation policy<br/>RLS and definer functions"]
end

subgraph group_external["External Services"]
  node_razorpay["Razorpay billing<br/>payment integration<br/>[razorpay.server.ts]"]
  node_payment_webhook["Payment webhook<br/>API route"]
end

node_runtime -->|"boots server"| node_server
node_runtime -->|"renders routes"| node_router
node_router -->|"public area"| node_public_routes
node_router -->|"protected area"| node_authenticated_shell
node_authenticated_shell -->|"workspace access"| node_workspace_route
node_authenticated_shell -->|"student assessment"| node_student_attempt
node_authenticated_shell -->|"validates identity"| node_supabase_auth
node_auth_context -->|"uses auth session"| node_supabase
node_workspace_route -->|"hosts"| node_workspace
node_workspace -->|"approves enrollment"| node_join_enrollment
node_workspace -->|"uses"| node_institute_domain
node_join_enrollment -->|"creates pending membership"| node_institute_domain
node_institute_domain -->|"persists tenant data"| node_supabase
node_content_import -->|"submits imports"| node_import_logic
node_faculty_import -->|"submits CSV"| node_import_logic
node_import_logic -->|"stores reviewed questions"| node_supabase
node_test_workbench -->|"applies build rules"| node_test_builder
node_test_builder -->|"reads approved content"| node_supabase
node_test_builder -->|"publishes assignments"| node_student_attempt
node_student_attempt -->|"records attempts"| node_supabase
node_supabase -->|"enforces policies"| node_tenant_rls
node_payment_webhook -->|"receives events"| node_razorpay
node_payment_webhook -->|"updates billing state"| node_supabase

click node_runtime "https://github.com/sbktckp/quero/blob/main/src/start.ts"
click node_server "https://github.com/sbktckp/quero/blob/main/src/server.ts"
click node_router "https://github.com/sbktckp/quero/blob/main/src/router.tsx"
click node_public_routes "https://github.com/sbktckp/quero/blob/main/src/routes/__root.tsx"
click node_authenticated_shell "https://github.com/sbktckp/quero/blob/main/src/routes/_authenticated/route.tsx"
click node_workspace_route "https://github.com/sbktckp/quero/blob/main/src/routes/_authenticated/institute-workspace.tsx"
click node_workspace "https://github.com/sbktckp/quero/blob/main/src/components/institute/institute-admin-dashboard.tsx"
click node_join_enrollment "https://github.com/sbktckp/quero/blob/main/src/components/institute/institute-join-card.tsx"
click node_institute_domain "https://github.com/sbktckp/quero/blob/main/src/lib/institute.ts"
click node_content_import "https://github.com/sbktckp/quero/blob/main/src/components/institute/question-import.tsx"
click node_faculty_import "https://github.com/sbktckp/quero/blob/main/src/components/institute/faculty-csv-import.tsx"
click node_import_logic "https://github.com/sbktckp/quero/blob/main/src/lib/faculty-import.ts"
click node_test_workbench "https://github.com/sbktckp/quero/blob/main/src/components/institute/test-workbench.tsx"
click node_test_builder "https://github.com/sbktckp/quero/blob/main/src/lib/test-builder.ts"
click node_student_attempt "https://github.com/sbktckp/quero/blob/main/src/routes/_authenticated/test.%24attemptId.tsx"
click node_supabase_auth "https://github.com/sbktckp/quero/blob/main/src/integrations/supabase/auth-middleware.ts"
click node_auth_context "https://github.com/sbktckp/quero/blob/main/src/lib/auth.tsx"
click node_supabase "https://github.com/sbktckp/quero/blob/main/src/integrations/supabase/client.ts"
click node_tenant_rls "https://github.com/sbktckp/quero/blob/main/supabase/migrations/20260811100000_institute_isolation_hardening.sql"
click node_razorpay "https://github.com/sbktckp/quero/blob/main/src/lib/razorpay.server.ts"
click node_payment_webhook "https://github.com/sbktckp/quero/blob/main/src/routes/api/razorpay-webhook.ts"

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_runtime,node_server,node_router,node_public_routes,node_authenticated_shell toneBlue
class node_workspace_route,node_workspace,node_join_enrollment,node_institute_domain,node_content_import,node_faculty_import,node_import_logic,node_test_workbench,node_test_builder,node_student_attempt toneAmber
class node_supabase_auth,node_auth_context,node_supabase,node_tenant_rls toneMint
class node_razorpay,node_payment_webhook toneRose
```

## Components

### Application

TanStack Start React product runtime.

- [Start/Vite runtime](https://github.com/sbktckp/quero/blob/main/src/start.ts): application runtime · Bun-managed TanStack Start application deployed to Vercel. · `src/start.ts`
- [Server entry](https://github.com/sbktckp/quero/blob/main/src/server.ts): server entry · `src/server.ts`
- [File-based router](https://github.com/sbktckp/quero/blob/main/src/router.tsx): routing · `src/router.tsx`
- [Public marketing and auth](https://github.com/sbktckp/quero/blob/main/src/routes/__root.tsx): route area · `src/routes/__root.tsx`
- [Authenticated shell](https://github.com/sbktckp/quero/blob/main/src/routes/_authenticated/route.tsx): access boundary · Protects product routes and directs role-specific workflows. · `src/routes/_authenticated/route.tsx`

### Institute Operations

Tenant membership, content, and testing workflows.

- [Institute workspace route](https://github.com/sbktckp/quero/blob/main/src/routes/_authenticated/institute-workspace.tsx): workspace route · `src/routes/_authenticated/institute-workspace.tsx`
- [Institute operations hub](https://github.com/sbktckp/quero/blob/main/src/components/institute/institute-admin-dashboard.tsx): dashboard · Runs join approval, faculty administration, roster visibility, and role dashboards. · `src/components/institute/institute-admin-dashboard.tsx`
- [Join-code enrollment](https://github.com/sbktckp/quero/blob/main/src/components/institute/institute-join-card.tsx): membership workflow · Creates a pending student-institute relationship for admin approval. · `src/components/institute/institute-join-card.tsx`
- [Institute domain operations](https://github.com/sbktckp/quero/blob/main/src/lib/institute.ts): domain logic · `src/lib/institute.ts`
- [Question import UI](https://github.com/sbktckp/quero/blob/main/src/components/institute/question-import.tsx): content ingestion · CSV/XLSX and PDF-oriented import surfaces. · `src/components/institute/question-import.tsx`
- [Faculty CSV import](https://github.com/sbktckp/quero/blob/main/src/components/institute/faculty-csv-import.tsx): content ingestion · `src/components/institute/faculty-csv-import.tsx`
- [Import resolution](https://github.com/sbktckp/quero/blob/main/src/lib/faculty-import.ts): domain logic · Resolves taxonomy, duplicate stems, unmatched data, and constrained undo. · `src/lib/faculty-import.ts`
- [Test workbench](https://github.com/sbktckp/quero/blob/main/src/components/institute/test-workbench.tsx): test authoring · Builds, reviews, and publishes tests from approved questions. · `src/components/institute/test-workbench.tsx`
- [Test lifecycle rules](https://github.com/sbktckp/quero/blob/main/src/lib/test-builder.ts): domain logic · Applies section completeness and publication gates. · `src/lib/test-builder.ts`
- [Student attempt and review](https://github.com/sbktckp/quero/blob/main/src/routes/_authenticated/test.%24attemptId.tsx): assessment route · `src/routes/_authenticated/test.$attemptId.tsx`

### Backend Boundaries

Supabase-enforced identity, data, and tenant isolation.

- [Supabase Auth middleware](https://github.com/sbktckp/quero/blob/main/src/integrations/supabase/auth-middleware.ts): identity boundary · `src/integrations/supabase/auth-middleware.ts`
- [Client auth context](https://github.com/sbktckp/quero/blob/main/src/lib/auth.tsx): identity client · `src/lib/auth.tsx`
- [Supabase backend](https://github.com/sbktckp/quero/blob/main/src/integrations/supabase/client.ts): Auth, Postgres, RPC, RLS · Primary backend for typed data access and policy enforcement. · `src/integrations/supabase/client.ts`
- [Tenant isolation policy](https://github.com/sbktckp/quero/blob/main/supabase/migrations/20260811100000_institute_isolation_hardening.sql): RLS and definer functions · Restricts tenants and routes sensitive cross-tenant actions through database functions. · `supabase/migrations/20260811100000_institute_isolation_hardening.sql`

### External Services

- [Razorpay billing](https://github.com/sbktckp/quero/blob/main/src/lib/razorpay.server.ts): payment integration · `src/lib/razorpay.server.ts`
- [Payment webhook](https://github.com/sbktckp/quero/blob/main/src/routes/api/razorpay-webhook.ts): API route · `src/routes/api/razorpay-webhook.ts`

## Connections

- Start/Vite runtime → Server entry: boots server
- Start/Vite runtime → File-based router: renders routes
- File-based router → Public marketing and auth: public area
- File-based router → Authenticated shell: protected area
- Authenticated shell → Institute workspace route: workspace access
- Authenticated shell → Student attempt and review: student assessment
- Authenticated shell → Supabase Auth middleware: validates identity
- Client auth context → Supabase backend: uses auth session
- Institute workspace route → Institute operations hub: hosts
- Institute operations hub → Join-code enrollment: approves enrollment
- Institute operations hub → Institute domain operations: uses
- Join-code enrollment → Institute domain operations: creates pending membership
- Institute domain operations → Supabase backend: persists tenant data
- Question import UI → Import resolution: submits imports
- Faculty CSV import → Import resolution: submits CSV
- Import resolution → Supabase backend: stores reviewed questions
- Test workbench → Test lifecycle rules: applies build rules
- Test lifecycle rules → Supabase backend: reads approved content
- Test lifecycle rules → Student attempt and review: publishes assignments
- Student attempt and review → Supabase backend: records attempts
- Supabase backend → Tenant isolation policy: enforces policies
- Payment webhook → Razorpay billing: receives events
- Payment webhook → Supabase backend: updates billing state
