# arun7296/mbbs architecture

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

- Interactive diagram: https://gitdiagram.com/arun7296/mbbs
- Repository: https://github.com/arun7296/mbbs

## Overview

1. This repository is a Next.js App Router application for medical education and assessment. The top-level product is split into two major experience areas: an auth/onboarding flow and the main learning platform.

2. The presentation layer lives under `src/app`. Routes are organized by user task, not by technical layer: `learn`, `practice`, `revise`, `progress`, `search`, `study-plan`, `clinical`, `aetcom`, and `test/mock`. Most pages are server-rendered route entries that compose reusable client components for interactive study and quiz behavior.

3. The main UI boundary is `src/components`. It is organized by domain: lesson viewers, quiz shells, revision/flashcards, clinical simulation, video playback, shared markdown/progress widgets, and a large catalog of diagram components for anatomy, physiology, pathology, pharmacology, biochemistry, and clinical topics. This suggests the UI is heavily content-driven and visualization-heavy rather than form- or transaction-heavy.

4. The backend API is implemented with tRPC under `src/server/trpc`, with one router per domain: content, curriculum, progress, search, study plan, video, visuals, clinical, clinical decision simulation, and assessment. The front end talks to these routers through the tRPC client/provider in `src/lib/trpc`, keeping type-safe RPC as the main data access path for app features.

5. Persistence is centered on Prisma. The schema and migrations in `prisma/schema.prisma` and `prisma/migrations` define the application data model, while `src/lib/db/prisma.ts` provides the database client. The database is the source of truth for curriculum structure, lessons, MCQs, cases, progress, and related learning artifacts.

6. Content population is a major subsystem and likely the most important architectural boundary in the repo. The `prisma/seeds` folder contains a large, modular seed corpus for subjects, lectures, lessons, MCQs, clinical scenarios, and “gap”/placeholder batches. Seeding is orchestrated by `prisma/seed.ts`, `prisma/run-seed.ts`, and numerous content-part files, indicating the platform’s educational library is assembled from structured seed data rather than authored directly in the app UI.

7. The curriculum model appears explicitly layered: subjects, modules, topics, lessons, questions, and scenarios. Supporting types and constants in `src/types/curriculum.ts` and `src/lib/constants/curriculum.ts` suggest the app navigates and queries content using a stable academic taxonomy, which is reflected in routes like `/learn/[subjectCode]/[moduleCode]/[topicSlug]`.

8. Clinical learning has its own subdomain. There are dedicated clinical case routes and a clinical simulator UI under `src/components/clinical-sim`, plus decision/assessment routers on the server. This is separate from standard lesson and quiz content, implying a specialized interaction model for patient case progression, findings, investigations, and feedback.

9. Assessment and practice are separate flows. Practice pages use client components like `QuizShell`, `QuestionRenderer`, and `ExplanationPanel`, while test/mock pages have their own route tree and review screens. This indicates the app distinguishes between lightweight practice quizzes and higher-stakes exam simulations.

10. Progression and personalization are first-class features. The `progress` and `study-plan` areas, plus the `progress` tRPC router and revision/flashcard components, show a loop of content consumption → performance tracking → weak-area identification → personalized study output.

11. Visual and media content is treated as its own subsystem. There are diagram libraries in `src/components/diagrams`, video components in `src/components/video`, and data utilities in `src/lib/visuals` and `src/lib/video`. The scripts under `scripts/` and seed maps for Servier/OpenStax/Wikimedia indicate external illustration and video sources are ingested, normalized, and mapped to curriculum topics.

12. Authentication and session handling are integrated at the app edge. NextAuth routes live under `src/app/api/auth/[...nextauth]`, signup has its own route, and `src/lib/auth/config.ts` plus `src/middleware.ts` define auth behavior and route protection. The `src/app/(auth)` and `src/app/(main)` route groups reflect the protected-app boundary.

13. The codebase includes several domain algorithms and utilities that support learning logic rather than UI rendering: spaced repetition, clinical scoring, video ranking, and visual generation. These live in `src/lib/algorithms`, `src/lib/utils`, `src/lib/video`, and `src/lib/visuals`, and are consumed by server routers and interactive components.

14. Tooling and maintenance scripts are significant because they support content ops at scale. The `scripts/` directory contains utilities for building image catalogues, seeding visuals/videos, matching external image sources to topics, fixing URLs, and creating demo users. This repository behaves like a content platform with a strong data pipeline, not just a conventional app.

15. In architecture-diagram terms, the key flows are: curriculum content is seeded into Prisma → tRPC routers expose typed read/write APIs → Next.js pages and client components render lessons, quizzes, cases, and progress views → user actions update persisted progress and feed personalized study/revision features. The critical boundary is between the content/database layer and the interactive learning UI.

Main entry points: [`src/app/(main)/layout.tsx`](https://github.com/arun7296/mbbs/blob/main/src/app/(main)/layout.tsx) (Main shell), [`src/server/trpc/routers`](https://github.com/arun7296/mbbs/tree/main/src/server/trpc/routers) (Domain routers), [`src/components/lesson`](https://github.com/arun7296/mbbs/tree/main/src/components/lesson) (Lesson UI), [`scripts`](https://github.com/arun7296/mbbs/tree/main/scripts) (Ops scripts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_auth["Auth edge"]
  node_node_auth["Auth flow<br/>App routes"]
  node_node_auth_config["Auth config<br/>Session policy<br/>[config.ts]"]
end

subgraph group_grp_app["Next.js app"]
  node_node_main_layout["Main shell<br/>App shell<br/>[layout.tsx]"]
  node_node_learn_routes["Learn routes<br/>Curriculum routes"]
  node_node_practice_routes["Practice flow<br/>Quiz routes"]
  node_node_test_routes["Mock tests<br/>Exam routes"]
  node_node_clinical_routes["Clinical cases<br/>Case routes"]
  node_node_progress_routes["Progress views<br/>Tracking routes"]
  node_node_studyplan_routes["Study plan<br/>Personalization routes"]
end

subgraph group_grp_ui["Interactive UI"]
  node_node_components_lesson["Lesson UI<br/>Lesson components"]
  node_node_components_quiz["Quiz UI<br/>Assessment components"]
  node_node_components_revise["Revision UI<br/>Flashcard components"]
  node_node_components_clinical["Clinical UI<br/>Case player components"]
  node_node_components_sim["Sim steps<br/>Clinical sim components"]
  node_node_components_diagrams["Diagram library<br/>Visualization components"]
  node_node_components_video["Video UI<br/>Video components"]
  node_node_components_shared["Shared widgets<br/>Common UI"]
end

subgraph group_grp_api["Server API"]
  node_node_trpc_root["tRPC root<br/>RPC composition<br/>[root.ts]"]
  node_node_trpc_routers["Domain routers<br/>tRPC routers"]
  node_node_trpc_client["tRPC client<br/>[client.ts]"]
end

subgraph group_grp_data["Data & content"]
  node_node_prisma[("Prisma schema<br/>Database model<br/>[schema.prisma]")]
  node_node_seed_runner["Seed runner<br/>Seeding entrypoint<br/>[seed.ts]"]
  node_node_seed_corpus["Content seeds<br/>Structured content"]
end

subgraph group_grp_lib["Core logic"]
  node_node_curriculum_types["Curriculum model<br/>Taxonomy types<br/>[curriculum.ts]"]
  node_node_curriculum_consts["Curriculum constants<br/>Navigation config<br/>[curriculum.ts]"]
  node_node_algorithms["Learning logic<br/>Algorithms"]
  node_node_video_logic["Video logic<br/>Media ranking<br/>[video-ranker.ts]"]
  node_node_visual_logic["Visual logic<br/>Image mapping<br/>[svg-generator.ts]"]
end

subgraph group_grp_scripts["Content ops"]
  node_node_scripts["Ops scripts<br/>Content pipeline"]
end

node_node_root["MBBS platform<br/>Next.js medical learning app"]

node_node_root -->|"entry"| node_node_auth
node_node_root -->|"shell"| node_node_main_layout
node_node_main_layout -->|"hosts"| node_node_learn_routes
node_node_main_layout -->|"hosts"| node_node_practice_routes
node_node_main_layout -->|"hosts"| node_node_test_routes
node_node_main_layout -->|"hosts"| node_node_clinical_routes
node_node_main_layout -->|"hosts"| node_node_progress_routes
node_node_main_layout -->|"hosts"| node_node_studyplan_routes
node_node_learn_routes -->|"renders"| node_node_components_lesson
node_node_practice_routes -->|"renders"| node_node_components_quiz
node_node_test_routes -->|"renders"| node_node_components_quiz
node_node_test_routes -->|"reviews"| node_node_components_revise
node_node_clinical_routes -->|"renders"| node_node_components_clinical
node_node_clinical_routes -->|"simulates"| node_node_components_sim
node_node_progress_routes -->|"shows"| node_node_components_shared
node_node_studyplan_routes -->|"personalizes"| node_node_components_revise
node_node_components_lesson -->|"embeds"| node_node_components_diagrams
node_node_components_lesson -->|"embeds"| node_node_components_video
node_node_components_lesson -->|"uses"| node_node_components_shared
node_node_components_clinical -->|"extends"| node_node_components_sim
node_node_trpc_root -->|"composes"| node_node_trpc_routers
node_node_trpc_client -->|"calls"| node_node_trpc_root
node_node_trpc_routers -->|"queries"| node_node_prisma
node_node_trpc_routers -->|"applies"| node_node_algorithms
node_node_trpc_routers -->|"applies"| node_node_video_logic
node_node_trpc_routers -->|"applies"| node_node_visual_logic
node_node_seed_runner -->|"loads"| node_node_seed_corpus
node_node_seed_runner -->|"writes"| node_node_prisma
node_node_seed_corpus -->|"shaped by"| node_node_curriculum_types
node_node_curriculum_types -->|"aligned with"| node_node_curriculum_consts
node_node_scripts -->|"maintains"| node_node_seed_corpus
node_node_scripts -->|"feeds"| node_node_visual_logic
node_node_scripts -->|"feeds"| node_node_video_logic

click node_node_auth "https://github.com/arun7296/mbbs/tree/main/src/app/(auth)"
click node_node_auth_config "https://github.com/arun7296/mbbs/blob/main/src/lib/auth/config.ts"
click node_node_main_layout "https://github.com/arun7296/mbbs/blob/main/src/app/(main)/layout.tsx"
click node_node_learn_routes "https://github.com/arun7296/mbbs/tree/main/src/app/(main)/learn"
click node_node_practice_routes "https://github.com/arun7296/mbbs/tree/main/src/app/(main)/practice"
click node_node_test_routes "https://github.com/arun7296/mbbs/tree/main/src/app/(main)/test/mock"
click node_node_clinical_routes "https://github.com/arun7296/mbbs/tree/main/src/app/(main)/clinical"
click node_node_progress_routes "https://github.com/arun7296/mbbs/tree/main/src/app/(main)/progress"
click node_node_studyplan_routes "https://github.com/arun7296/mbbs/tree/main/src/app/(main)/study-plan"
click node_node_components_lesson "https://github.com/arun7296/mbbs/tree/main/src/components/lesson"
click node_node_components_quiz "https://github.com/arun7296/mbbs/tree/main/src/components/quiz"
click node_node_components_revise "https://github.com/arun7296/mbbs/tree/main/src/components/revise"
click node_node_components_clinical "https://github.com/arun7296/mbbs/tree/main/src/components/clinical"
click node_node_components_sim "https://github.com/arun7296/mbbs/tree/main/src/components/clinical-sim"
click node_node_components_diagrams "https://github.com/arun7296/mbbs/tree/main/src/components/diagrams"
click node_node_components_video "https://github.com/arun7296/mbbs/tree/main/src/components/video"
click node_node_components_shared "https://github.com/arun7296/mbbs/tree/main/src/components/shared"
click node_node_trpc_root "https://github.com/arun7296/mbbs/blob/main/src/server/trpc/root.ts"
click node_node_trpc_routers "https://github.com/arun7296/mbbs/tree/main/src/server/trpc/routers"
click node_node_trpc_client "https://github.com/arun7296/mbbs/blob/main/src/lib/trpc/client.ts"
click node_node_prisma "https://github.com/arun7296/mbbs/blob/main/prisma/schema.prisma"
click node_node_seed_runner "https://github.com/arun7296/mbbs/blob/main/prisma/seed.ts"
click node_node_seed_corpus "https://github.com/arun7296/mbbs/tree/main/prisma/seeds"
click node_node_curriculum_types "https://github.com/arun7296/mbbs/blob/main/src/types/curriculum.ts"
click node_node_curriculum_consts "https://github.com/arun7296/mbbs/blob/main/src/lib/constants/curriculum.ts"
click node_node_algorithms "https://github.com/arun7296/mbbs/blob/main/src/lib/algorithms/clinical-scoring.ts"
click node_node_video_logic "https://github.com/arun7296/mbbs/blob/main/src/lib/video/video-ranker.ts"
click node_node_visual_logic "https://github.com/arun7296/mbbs/blob/main/src/lib/visuals/svg-generator.ts"
click node_node_scripts "https://github.com/arun7296/mbbs/tree/main/scripts"

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_node_auth,node_node_auth_config,node_node_scripts toneBlue
class node_node_main_layout,node_node_learn_routes,node_node_practice_routes,node_node_test_routes,node_node_clinical_routes,node_node_progress_routes,node_node_studyplan_routes toneAmber
class node_node_components_lesson,node_node_components_quiz,node_node_components_revise,node_node_components_clinical,node_node_components_sim,node_node_components_diagrams,node_node_components_video,node_node_components_shared toneMint
class node_node_trpc_root,node_node_trpc_routers,node_node_trpc_client toneRose
class node_node_prisma,node_node_seed_runner,node_node_seed_corpus toneIndigo
class node_node_curriculum_types,node_node_curriculum_consts,node_node_algorithms,node_node_video_logic,node_node_visual_logic toneTeal
class node_node_root toneNeutral
```

## Components

### Auth edge

Authentication routes, session config, and route protection.

- [Auth flow](https://github.com/arun7296/mbbs/tree/main/src/app/(auth)): App routes · Login, signup, and onboarding entrypoints before the main app. · `src/app/(auth)`
- [Auth config](https://github.com/arun7296/mbbs/blob/main/src/lib/auth/config.ts): Session policy · NextAuth configuration and middleware-based route protection. · `src/lib/auth/config.ts`

### Next.js app

Route groups and page entrypoints for the user-facing product.

- [Main shell](https://github.com/arun7296/mbbs/blob/main/src/app/(main)/layout.tsx): App shell · Protected application layout and shared loading/error boundaries. · `src/app/(main)/layout.tsx`
- [Learn routes](https://github.com/arun7296/mbbs/tree/main/src/app/(main)/learn): Curriculum routes · Subject → module → topic navigation for structured lesson browsing. · `src/app/(main)/learn`
- [Practice flow](https://github.com/arun7296/mbbs/tree/main/src/app/(main)/practice): Quiz routes · Interactive quiz shell, question experience, and result review. · `src/app/(main)/practice`
- [Mock tests](https://github.com/arun7296/mbbs/tree/main/src/app/(main)/test/mock): Exam routes · Higher-stakes exam simulation and review screens. · `src/app/(main)/test/mock`
- [Clinical cases](https://github.com/arun7296/mbbs/tree/main/src/app/(main)/clinical): Case routes · Clinical case browser, case detail, and review pages. · `src/app/(main)/clinical`
- [Progress views](https://github.com/arun7296/mbbs/tree/main/src/app/(main)/progress): Tracking routes · Progress dashboards by subject and overall learning status. · `src/app/(main)/progress`
- [Study plan](https://github.com/arun7296/mbbs/tree/main/src/app/(main)/study-plan): Personalization routes · Personalized study-plan entrypoint for weak-area driven learning. · `src/app/(main)/study-plan`

### Interactive UI

Reusable client components that implement lessons, quizzes, revision, clinical flow, diagrams, and media.

- [Lesson UI](https://github.com/arun7296/mbbs/tree/main/src/components/lesson): Lesson components · Lesson viewer, key points, mnemonics, and embedded clinical decision/visual layers. · `src/components/lesson`
- [Quiz UI](https://github.com/arun7296/mbbs/tree/main/src/components/quiz): Assessment components · Question rendering, explanations, and quiz shell coordination. · `src/components/quiz`
- [Revision UI](https://github.com/arun7296/mbbs/tree/main/src/components/revise): Flashcard components · Weak-area cards and flashcard review for spaced repetition loops. · `src/components/revise`
- [Clinical UI](https://github.com/arun7296/mbbs/tree/main/src/components/clinical): Case player components · Patient card, timeline, findings, and action selection for case progression. · `src/components/clinical`
- [Sim steps](https://github.com/arun7296/mbbs/tree/main/src/components/clinical-sim): Clinical sim components · Stepwise clinical simulation screens for history, exam, diagnosis, treatment, and feedback. · `src/components/clinical-sim`
- [Diagram library](https://github.com/arun7296/mbbs/tree/main/src/components/diagrams): Visualization components · Reusable diagram system spanning anatomy, biochemistry, pathology, pharmacology, physiology, and clinical visualizations. · `src/components/diagrams`
- [Video UI](https://github.com/arun7296/mbbs/tree/main/src/components/video): Video components · Video list and playback UI for hosted or sourced educational media. · `src/components/video`
- [Shared widgets](https://github.com/arun7296/mbbs/tree/main/src/components/shared): Common UI · Markdown rendering and progress indicators shared across routes. · `src/components/shared`

### Server API

tRPC routers and adapters that expose typed domain services.

- [tRPC root](https://github.com/arun7296/mbbs/blob/main/src/server/trpc/root.ts): RPC composition · Top-level tRPC router composition and server context. · `src/server/trpc/root.ts`
- [Domain routers](https://github.com/arun7296/mbbs/tree/main/src/server/trpc/routers): tRPC routers · Content, curriculum, progress, search, study plan, video, visual, clinical, clinical decision, and assessment routers. · `src/server/trpc/routers`
- [tRPC client](https://github.com/arun7296/mbbs/blob/main/src/lib/trpc/client.ts): RPC client · Typed client and provider used by the app to call server routers. · `src/lib/trpc/client.ts`

### Data & content

Prisma model, migrations, and structured seed corpus that populate the learning platform.

- [Prisma schema](https://github.com/arun7296/mbbs/blob/main/prisma/schema.prisma): Database model · Application data model and migrations for lessons, MCQs, cases, progress, and related learning artifacts. · `prisma/schema.prisma`
- [Seed runner](https://github.com/arun7296/mbbs/blob/main/prisma/seed.ts): Seeding entrypoint · Orchestrates database population from the modular content corpus. · `prisma/seed.ts`
- [Content seeds](https://github.com/arun7296/mbbs/tree/main/prisma/seeds): Structured content · Large subject- and artifact-specific seed corpus for lectures, lessons, MCQs, cases, and gaps. · `prisma/seeds`

### Core logic

Shared algorithms and domain utilities used by routers and UI.

- [Curriculum model](https://github.com/arun7296/mbbs/blob/main/src/types/curriculum.ts): Taxonomy types · Subject, module, topic, lesson, question, and scenario definitions used across the app. · `src/types/curriculum.ts`
- [Curriculum constants](https://github.com/arun7296/mbbs/blob/main/src/lib/constants/curriculum.ts): Navigation config · Stable curriculum metadata and subject mapping constants. · `src/lib/constants/curriculum.ts`
- [Learning logic](https://github.com/arun7296/mbbs/blob/main/src/lib/algorithms/clinical-scoring.ts): Algorithms · Spaced repetition, clinical scoring, and other learning-domain algorithms. · `src/lib/algorithms/clinical-scoring.ts`
- [Video logic](https://github.com/arun7296/mbbs/blob/main/src/lib/video/video-ranker.ts): Media ranking · Video search and ranking utilities used to select relevant educational media. · `src/lib/video/video-ranker.ts`
- [Visual logic](https://github.com/arun7296/mbbs/blob/main/src/lib/visuals/svg-generator.ts): Image mapping · Visual sourcing, SVG generation, and topic-to-image matching utilities. · `src/lib/visuals/svg-generator.ts`

### Content ops

Maintenance scripts for seeding, cataloging, and media/content synchronization.

- [Ops scripts](https://github.com/arun7296/mbbs/tree/main/scripts): Content pipeline · Cataloging, seeding, matching, and repair scripts for large-scale content operations. · `scripts`

### Other components

- **MBBS platform**: Next.js medical learning app · Protected learning platform with seeded curriculum, practice, clinical simulation, progress tracking, and personalization.

## Connections

- MBBS platform → Auth flow: entry · Auth and onboarding are the pre-app boundary.
- MBBS platform → Main shell: shell · The protected product renders inside the main app shell.
- Main shell → Learn routes: hosts · Main shell serves the curriculum browsing routes.
- Main shell → Practice flow: hosts · Main shell serves practice quizzes.
- Main shell → Mock tests: hosts · Main shell serves mock exam flows.
- Main shell → Clinical cases: hosts · Main shell serves clinical case workflows.
- Main shell → Progress views: hosts · Main shell serves progress tracking pages.
- Main shell → Study plan: hosts · Main shell serves personalization/study-plan pages.
- Learn routes → Lesson UI: renders · Lesson pages compose the lesson UI boundary.
- Practice flow → Quiz UI: renders · Practice pages use the quiz shell and question renderer.
- Mock tests → Quiz UI: renders · Mock exam pages reuse the assessment UI stack.
- Mock tests → Revision UI: reviews · Exam review flows feed revision-oriented components.
- Clinical cases → Clinical UI: renders · Clinical pages use patient/case interaction components.
- Clinical cases → Sim steps: simulates · Clinical case progression can enter the simulation stepper.
- Progress views → Shared widgets: shows · Progress pages use shared widgets and indicators.
- Study plan → Revision UI: personalizes · Study plans are fed by weak-area and flashcard views.
- Lesson UI → Diagram library: embeds · Lessons frequently include medical diagrams and visual theory layers.
- Lesson UI → Video UI: embeds · Lessons can incorporate video playback and lists.
- Lesson UI → Shared widgets: uses · Lesson rendering relies on shared markdown/progress widgets.
- Clinical UI → Sim steps: extends · Clinical case UI connects to stepwise simulation interactions.
- tRPC root → Domain routers: composes · The root tRPC layer aggregates domain routers.
- tRPC client → tRPC root: calls · The UI talks to the server through the typed RPC boundary.
- Domain routers → Prisma schema: queries · Routers read/write persisted curriculum and learner state.
- Domain routers → Learning logic: applies · Routers invoke domain logic for scoring and study planning.
- Domain routers → Video logic: applies · Video router logic selects and ranks media.
- Domain routers → Visual logic: applies · Visual router logic serves image and SVG assets.
- Seed runner → Content seeds: loads · The seed runner assembles structured content batches.
- Seed runner → Prisma schema: writes · Seed execution populates the database schema.
- Content seeds → Curriculum model: shaped by · Seed data follows the shared curriculum taxonomy.
- Curriculum model → Curriculum constants: aligned with · Navigation and subject codes are stabilized by constants.
- Ops scripts → Content seeds: maintains · Scripts catalog, fix, and normalize seed-driven content.
- Ops scripts → Visual logic: feeds · Content ops ingest and map external image sources.
- Ops scripts → Video logic: feeds · Content ops also seed and rank educational video assets.
