# ahmadtariq1/taiyaari architecture

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

- Interactive diagram: https://gitdiagram.com/ahmadtariq1/taiyaari
- Repository: https://github.com/ahmadtariq1/taiyaari

## Overview

#### Purpose and Entry Points
Taiyaari is an MDCAT preparation platform: authenticated study dashboards, topic/full-length tests, performance tracking, notes, leaderboard, daily planning, and AI tutoring. The two deployable applications are a FastAPI backend at `backend/app/main.py` (also `backend/run.py`) and a Next.js frontend rooted at `frontend/src/app/layout.js` and `frontend/src/app/page.js`.

#### Frontend Application Shell
The frontend uses Next.js App Router with page-level routes for dashboard, test-taking/results, progress, planner, leaderboard, profile, and AI tutor. Shared dashboard composition and a floating chat wrapper establish the main learner experience.
- `frontend/src/app/dashboard/page.js`
- `frontend/src/components/dashboard/dashboard-layout.js`
- `frontend/src/components/floating-chat/ChatLayoutWrapper.js`

Authentication state is managed client-side through Firebase integration and propagated through the app context; API calls are centralized separately.
- `frontend/src/contexts/AuthContext.js`
- `frontend/src/lib/firebase.js`
- `frontend/src/lib/api.js`

#### HTTP API and Access Boundary
FastAPI organizes versioned REST endpoints under the v1 router. Endpoint modules expose the domain surface: auth/users, subjects/topics/questions, tests/full-length tests, notes, performance, leaderboard, chatbot, and fine-tuned answers. Dependencies and security form the request authentication/authorization boundary before domain work.
- `backend/app/api/v1/router.py`
- `backend/app/api/dependencies.py`
- `backend/app/core/security.py`

#### Study Content and Assessment Domain
SQLAlchemy-style model/schema layers represent the durable academic system: subject/topic hierarchy, question banks, test definitions/sources, full-length question material, and submitted results. Test UI renders question navigation and then results/review analytics; API endpoints own server-side retrieval/submission behavior.
- `backend/app/models/question.py`
- `backend/app/models/test.py`
- `backend/app/models/test_result.py`

- `frontend/src/components/test-interface/QuestionDisplay.js`
- `frontend/src/components/test-results/TestResultsContent.js`
- `backend/app/api/v1/endpoints/tests.py`

#### Learner State, Analytics, and Planning
User-specific state includes performance records, notes, and daily tasks. Performance and leaderboard endpoints convert assessment/user data into progress views; the daily-task service is the key backend planning logic consumed by dashboard and planner UI.
- `backend/app/models/performance.py`
- `backend/app/models/user_daily_task.py`
- `backend/app/services/daily_tasks.py`

- `frontend/src/components/dashboard/performance-overview.js`
- `frontend/src/components/dashboard/daily-planner.js`
- `backend/app/api/v1/endpoints/leaderboard.py`

#### AI Tutor and Retrieval-Augmented Generation
Chat and fine-tuned-answer capabilities sit behind dedicated API endpoints. The RAG pipeline loads/extracts learning content, retrieves subject-scoped context, and accesses persisted vector indexes. This is distinct from relational test/user data and is the primary AI integration boundary.
- `backend/app/api/v1/endpoints/chatbot.py`
- `backend/app/services/rag/pipeline.py`
- `backend/app/services/rag/retriever.py`

Vector data is checked into local subject-specific stores, while source textbooks/past papers are prepared in extraction notebooks and processed text/JSON assets.
- `backend/app/services/rag/vector_store.py`
- `backend/vector_db/biology/`
- `data_extraction/processed_json_files/`

#### Persistence, Imports, and Runtime Dependencies
Backend configuration and database initialization are centralized in core modules. SQLite database artifacts are present at both root and `data/`; import scripts populate question and full-length-test content. Firebase is the explicit external identity service indicated by frontend integration and setup documentation. The operational runtime is Python/FastAPI plus Node.js/Next.js; local vector indexes support AI retrieval.
- `backend/app/core/config.py`
- `backend/app/core/database.py`
- `backend/scripts/import_questions.py`

- `data/taiyaari.db`
- `backend/scripts/import_full_length_tests.py`
- `FIREBASE_SETUP.md`

Main entry points: [`frontend/src/app/layout.js`](https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/app/layout.js) (App shell and routes), [`backend/app/api/v1/router.py`](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/v1/router.py) (Versioned REST API), [`frontend/src/lib/api.js`](https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/lib/api.js) (API client), [`backend/app/models/test_result.py`](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/models/test_result.py) (Study models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Next.js learner app"]
  node_next_shell["App shell and routes<br/>Next.js App Router<br/>[layout.js]"]
  node_dashboard["Dashboard composition<br/>shared UI"]
  node_test_ui["Test and results UI<br/>assessment UI<br/>[QuestionDisplay.js]"]
  node_learner_widgets["Performance and planner UI<br/>dashboard widgets"]
  node_chat_ui["Floating tutor chat<br/>chat UI"]
  node_auth_context["Client auth state<br/>React context<br/>[AuthContext.js]"]
  node_api_client["API client<br/>frontend integration<br/>[api.js]"]
end

subgraph group_api["FastAPI application"]
  node_fastapi["FastAPI entrypoint<br/>backend runtime<br/>[main.py]"]
  node_v1_router["Versioned REST API<br/>API router<br/>[router.py]"]
  node_security["Request access boundary<br/>dependencies and security<br/>[dependencies.py]"]
end

subgraph group_study["Study and learner domain"]
  node_assessment_api["Assessment endpoints<br/>test API<br/>[tests.py]"]
  node_study_models["Study models<br/>SQLAlchemy models<br/>[test_result.py]"]
  node_learner_models["Learner state models<br/>SQLAlchemy models<br/>[performance.py]"]
  node_daily_tasks["Daily task service<br/>planning service<br/>[daily_tasks.py]"]
  node_leaderboard_api["Leaderboard analytics<br/>analytics endpoint<br/>[leaderboard.py]"]
  node_content_import["Question import<br/>content ingestion"]
end

subgraph group_rag["AI retrieval pipeline"]
  node_chatbot_api["Tutor and answer API<br/>AI endpoint<br/>[chatbot.py]"]
  node_rag_pipeline["RAG pipeline<br/>retrieval orchestration<br/>[pipeline.py]"]
  node_retriever["Subject context retriever<br/>RAG retrieval<br/>[retriever.py]"]
  node_vector_store[("Local vector indexes<br/>vector persistence")]
  node_source_assets["Processed learning assets<br/>prepared content"]
end

node_firebase{{"Firebase identity<br/>external auth service<br/>[firebase.js]"}}
node_database[("SQLite academic data<br/>relational database<br/>[taiyaari.db]")]

node_next_shell -->|"composes"| node_dashboard
node_next_shell -->|"renders"| node_test_ui
node_next_shell -->|"renders"| node_learner_widgets
node_next_shell -->|"hosts"| node_chat_ui
node_auth_context -->|"authenticates with"| node_firebase
node_next_shell -->|"uses"| node_auth_context
node_dashboard -->|"loads learner data"| node_api_client
node_test_ui -->|"loads and submits"| node_api_client
node_chat_ui -->|"sends prompts"| node_api_client
node_api_client -->|"HTTP requests"| node_fastapi
node_fastapi -->|"mounts"| node_v1_router
node_v1_router -->|"enforces access"| node_security
node_v1_router -->|"routes"| node_assessment_api
node_v1_router -->|"routes"| node_leaderboard_api
node_v1_router -->|"routes"| node_chatbot_api
node_assessment_api -->|"reads and writes"| node_study_models
node_leaderboard_api -->|"aggregates"| node_learner_models
node_daily_tasks -->|"manages"| node_learner_models
node_study_models -->|"persists in"| node_database
node_learner_models -->|"persists in"| node_database
node_content_import -->|"populates"| node_study_models
node_chatbot_api -->|"invokes"| node_rag_pipeline
node_rag_pipeline -->|"retrieves context"| node_retriever
node_retriever -->|"searches"| node_vector_store
node_source_assets -.->|"supplies indexed content"| node_vector_store

click node_next_shell "https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/app/layout.js"
click node_dashboard "https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/components/dashboard/dashboard-layout.js"
click node_test_ui "https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/components/test-interface/QuestionDisplay.js"
click node_learner_widgets "https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/components/dashboard/performance-overview.js"
click node_chat_ui "https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/components/floating-chat/ChatLayoutWrapper.js"
click node_auth_context "https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/contexts/AuthContext.js"
click node_firebase "https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/lib/firebase.js"
click node_api_client "https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/lib/api.js"
click node_fastapi "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/main.py"
click node_v1_router "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/v1/router.py"
click node_security "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/dependencies.py"
click node_assessment_api "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/v1/endpoints/tests.py"
click node_study_models "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/models/test_result.py"
click node_learner_models "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/models/performance.py"
click node_daily_tasks "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/services/daily_tasks.py"
click node_leaderboard_api "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/v1/endpoints/leaderboard.py"
click node_chatbot_api "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/v1/endpoints/chatbot.py"
click node_rag_pipeline "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/services/rag/pipeline.py"
click node_retriever "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/services/rag/retriever.py"
click node_database "https://github.com/ahmadtariq1/taiyaari/blob/main/data/taiyaari.db"
click node_content_import "https://github.com/ahmadtariq1/taiyaari/blob/main/backend/scripts/import_questions.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_next_shell,node_dashboard,node_test_ui,node_learner_widgets,node_chat_ui,node_auth_context,node_api_client toneBlue
class node_fastapi,node_v1_router,node_security toneAmber
class node_assessment_api,node_study_models,node_learner_models,node_daily_tasks,node_leaderboard_api,node_content_import toneMint
class node_chatbot_api,node_rag_pipeline,node_retriever,node_vector_store,node_source_assets toneRose
class node_firebase,node_database toneNeutral
```

## Components

### Next.js learner app

- [App shell and routes](https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/app/layout.js): Next.js App Router · Dashboard, tests, progress, planner, leaderboard, profile, and tutor routes. · `frontend/src/app/layout.js`
- [Dashboard composition](https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/components/dashboard/dashboard-layout.js): shared UI · `frontend/src/components/dashboard/dashboard-layout.js`
- [Test and results UI](https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/components/test-interface/QuestionDisplay.js): assessment UI · `frontend/src/components/test-interface/QuestionDisplay.js`
- [Performance and planner UI](https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/components/dashboard/performance-overview.js): dashboard widgets · `frontend/src/components/dashboard/performance-overview.js`
- [Floating tutor chat](https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/components/floating-chat/ChatLayoutWrapper.js): chat UI · `frontend/src/components/floating-chat/ChatLayoutWrapper.js`
- [Client auth state](https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/contexts/AuthContext.js): React context · `frontend/src/contexts/AuthContext.js`
- [API client](https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/lib/api.js): frontend integration · `frontend/src/lib/api.js`

### FastAPI application

- [FastAPI entrypoint](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/main.py): backend runtime · `backend/app/main.py`
- [Versioned REST API](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/v1/router.py): API router · Exposes auth, content, tests, learner state, leaderboard, and AI endpoints. · `backend/app/api/v1/router.py`
- [Request access boundary](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/dependencies.py): dependencies and security · `backend/app/api/dependencies.py`

### Study and learner domain

- [Assessment endpoints](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/v1/endpoints/tests.py): test API · Retrieves tests and accepts submissions. · `backend/app/api/v1/endpoints/tests.py`
- [Study models](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/models/test_result.py): SQLAlchemy models · Questions, tests, and submitted results. · `backend/app/models/test_result.py`
- [Learner state models](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/models/performance.py): SQLAlchemy models · Performance, notes, and daily tasks. · `backend/app/models/performance.py`
- [Daily task service](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/services/daily_tasks.py): planning service · `backend/app/services/daily_tasks.py`
- [Leaderboard analytics](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/v1/endpoints/leaderboard.py): analytics endpoint · `backend/app/api/v1/endpoints/leaderboard.py`
- [Question import](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/scripts/import_questions.py): content ingestion · `backend/scripts/import_questions.py`

### AI retrieval pipeline

- [Tutor and answer API](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/api/v1/endpoints/chatbot.py): AI endpoint · `backend/app/api/v1/endpoints/chatbot.py`
- [RAG pipeline](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/services/rag/pipeline.py): retrieval orchestration · `backend/app/services/rag/pipeline.py`
- [Subject context retriever](https://github.com/ahmadtariq1/taiyaari/blob/main/backend/app/services/rag/retriever.py): RAG retrieval · `backend/app/services/rag/retriever.py`
- **Local vector indexes**: vector persistence · Subject-specific retrieval indexes.
- **Processed learning assets**: prepared content

### Other components

- [Firebase identity](https://github.com/ahmadtariq1/taiyaari/blob/main/frontend/src/lib/firebase.js): external auth service · `frontend/src/lib/firebase.js`
- [SQLite academic data](https://github.com/ahmadtariq1/taiyaari/blob/main/data/taiyaari.db): relational database · `data/taiyaari.db`

## Connections

- App shell and routes → Dashboard composition: composes
- App shell and routes → Test and results UI: renders
- App shell and routes → Performance and planner UI: renders
- App shell and routes → Floating tutor chat: hosts
- Client auth state → Firebase identity: authenticates with
- App shell and routes → Client auth state: uses
- Dashboard composition → API client: loads learner data
- Test and results UI → API client: loads and submits
- Floating tutor chat → API client: sends prompts
- API client → FastAPI entrypoint: HTTP requests
- FastAPI entrypoint → Versioned REST API: mounts
- Versioned REST API → Request access boundary: enforces access
- Versioned REST API → Assessment endpoints: routes
- Versioned REST API → Leaderboard analytics: routes
- Versioned REST API → Tutor and answer API: routes
- Assessment endpoints → Study models: reads and writes
- Leaderboard analytics → Learner state models: aggregates
- Daily task service → Learner state models: manages
- Study models → SQLite academic data: persists in
- Learner state models → SQLite academic data: persists in
- Question import → Study models: populates
- Tutor and answer API → RAG pipeline: invokes
- RAG pipeline → Subject context retriever: retrieves context
- Subject context retriever → Local vector indexes: searches
- Processed learning assets → Local vector indexes: supplies indexed content
