# than-sothearak/next-course-craft architecture

> Architecture diagram of the GitHub repository than-sothearak/next-course-craft, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/than-sothearak/next-course-craft
- Repository: https://github.com/than-sothearak/next-course-craft

## Overview

CourseCraft is a web-based course-authoring platform. Users authenticate, manage courses and workspaces in the dashboard, author lessons and interactive blocks, preview courses, then publish HTML or SCORM packages. Supporting product areas include AI-assisted generation, media storage, administration, and course access controls. The graph follows documented capabilities and the supplied source references; unsampled route and publishing internals are represented only where the README or tree supports them.

Main entry points: [`app/courses/[courseId]/edit/_components/editor-client.tsx`](https://github.com/than-sothearak/next-course-craft/blob/main/app/courses/%5BcourseId%5D/edit/_components/editor-client.tsx) (Course Editor), [`lib/auth/authorization.ts`](https://github.com/than-sothearak/next-course-craft/blob/main/lib/auth/authorization.ts) (Authorization), [`lib/db/mongodb.ts`](https://github.com/than-sothearak/next-course-craft/blob/main/lib/db/mongodb.ts) (MongoDB), [`app/api/courses/[courseId]/publish/route.ts`](https://github.com/than-sothearak/next-course-craft/blob/main/app/api/courses/%5BcourseId%5D/publish/route.ts) (Course Publishing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity &amp; Access"]
  node_login["Login<br/>[page.tsx]"]
  node_auth["OAuth &amp; Sessions<br/>[index.ts]"]
  node_authorization["Authorization<br/>[authorization.ts]"]
end

subgraph group_management["Course Management"]
  node_dashboard["Dashboard"]
  node_dashboard_api["Course &amp; Folder APIs<br/>[route.ts]"]
  node_dashboard_services["Dashboard Services<br/>[list.ts]"]
  node_workspaces["Workspace Services<br/>[services.ts]"]
  node_workspace_api["Workspace API<br/>[route.ts]"]
end

subgraph group_authoring["Authoring &amp; Preview"]
  node_editor["Course Editor<br/>[editor-client.tsx]"]
  node_block_editor["Block Editor"]
  node_block_schema["Content Schemas<br/>[block.ts]"]
  node_preview["Course Preview<br/>[course-preview.tsx]"]
end

subgraph group_publishing["Generation &amp; Publishing"]
  node_generation_api["Generation API<br/>[route.ts]"]
  node_generation["AI Generation"]
  node_publish["Course Publishing<br/>[route.ts]"]
  node_pdf["PDF Export<br/>[course-handout.ts]"]
  node_scorm["SCORM Packaging<br/>[package.ts]"]
  node_export_runtime["Export Runtime<br/>[main.ts]"]
end

subgraph group_platform["Platform Services"]
  node_media_admin["Media Storage Admin"]
  node_media_service["Media Service<br/>[service.ts]"]
  node_admin["Administration"]
  node_mongo[("MongoDB<br/>[mongodb.ts]")]
end

node_learner_author(("CourseCraft User"))
node_storage[("Local / S3 Storage")]
node_ai_provider["AI Provider"]
node_lms["LMS"]

node_learner_author -->|"signs in"| node_login
node_login -->|"authenticates via"| node_auth
node_auth -->|"stores identity"| node_mongo
node_dashboard -.->|"requests courses"| node_dashboard_api
node_dashboard_api -->|"lists and creates"| node_dashboard_services
node_dashboard_api -->|"connects to"| node_mongo
node_dashboard_services -->|"queries models"| node_mongo
node_dashboard_services -->|"checks access"| node_authorization
node_dashboard -->|"manages workspace"| node_workspace_api
node_workspace_api -->|"dispatches requests"| node_workspaces
node_workspaces -->|"checks permissions"| node_authorization
node_editor -->|"renders blocks"| node_block_editor
node_editor -->|"uses schemas"| node_block_schema
node_block_editor -->|"types content"| node_block_schema
node_editor -.->|"opens preview"| node_preview
node_learner_author -->|"manages courses"| node_dashboard
node_learner_author -->|"authors lessons"| node_editor
node_learner_author -->|"reviews course"| node_preview
node_generation_api -->|"runs generation"| node_generation
node_generation_api -->|"checks access"| node_authorization
node_generation -.->|"requests content"| node_ai_provider
node_publish -.->|"exports PDF"| node_pdf
node_publish -.->|"packages SCORM"| node_scorm
node_publish -.->|"publishes HTML"| node_export_runtime
node_scorm -->|"targets LMS"| node_lms
node_media_admin -.->|"configures storage"| node_media_service
node_media_service -->|"stores assets"| node_storage
node_media_service -->|"reads settings"| node_mongo
node_admin -.->|"protects access"| node_authorization

click node_login "https://github.com/than-sothearak/next-course-craft/blob/main/app/login/page.tsx"
click node_auth "https://github.com/than-sothearak/next-course-craft/blob/main/lib/auth/index.ts"
click node_authorization "https://github.com/than-sothearak/next-course-craft/blob/main/lib/auth/authorization.ts"
click node_dashboard "https://github.com/than-sothearak/next-course-craft/blob/main/app/dashboard/dashboard-client.tsx"
click node_dashboard_api "https://github.com/than-sothearak/next-course-craft/blob/main/app/api/courses/route.ts"
click node_dashboard_services "https://github.com/than-sothearak/next-course-craft/blob/main/lib/dashboard/services/list.ts"
click node_workspaces "https://github.com/than-sothearak/next-course-craft/blob/main/lib/workspaces/services.ts"
click node_workspace_api "https://github.com/than-sothearak/next-course-craft/blob/main/app/api/workspaces/route.ts"
click node_editor "https://github.com/than-sothearak/next-course-craft/blob/main/app/courses/%5BcourseId%5D/edit/_components/editor-client.tsx"
click node_block_editor "https://github.com/than-sothearak/next-course-craft/blob/main/app/courses/%5BcourseId%5D/edit/_components/(editor_client_components)/content-block-editor.tsx"
click node_block_schema "https://github.com/than-sothearak/next-course-craft/blob/main/lib/schemas/block.ts"
click node_preview "https://github.com/than-sothearak/next-course-craft/blob/main/app/courses/%5BcourseId%5D/preview/course-preview.tsx"
click node_generation_api "https://github.com/than-sothearak/next-course-craft/blob/main/app/api/courses/%5BcourseId%5D/generate/route.ts"
click node_generation "https://github.com/than-sothearak/next-course-craft/blob/main/lib/ai/course-generation.ts"
click node_publish "https://github.com/than-sothearak/next-course-craft/blob/main/app/api/courses/%5BcourseId%5D/publish/route.ts"
click node_pdf "https://github.com/than-sothearak/next-course-craft/blob/main/lib/pdf/course-handout.ts"
click node_scorm "https://github.com/than-sothearak/next-course-craft/blob/main/lib/scorm/package.ts"
click node_export_runtime "https://github.com/than-sothearak/next-course-craft/blob/main/export/src/main.ts"
click node_media_admin "https://github.com/than-sothearak/next-course-craft/blob/main/components/admin/media-storage-management.tsx"
click node_media_service "https://github.com/than-sothearak/next-course-craft/blob/main/lib/media/service.ts"
click node_admin "https://github.com/than-sothearak/next-course-craft/blob/main/components/admin/course-access-manager.tsx"
click node_mongo "https://github.com/than-sothearak/next-course-craft/blob/main/lib/db/mongodb.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_login,node_auth,node_authorization,node_learner_author toneBlue
class node_dashboard,node_dashboard_api,node_dashboard_services,node_workspaces,node_workspace_api,node_storage toneAmber
class node_editor,node_block_editor,node_block_schema,node_preview toneMint
class node_generation_api,node_generation,node_publish,node_pdf,node_scorm,node_export_runtime toneRose
class node_media_admin,node_media_service,node_admin,node_mongo,node_ai_provider,node_lms toneIndigo
```

## Components

### Identity & Access

- [Login](https://github.com/than-sothearak/next-course-craft/blob/main/app/login/page.tsx): `app/login/page.tsx`
- [OAuth & Sessions](https://github.com/than-sothearak/next-course-craft/blob/main/lib/auth/index.ts): `lib/auth/index.ts`
- [Authorization](https://github.com/than-sothearak/next-course-craft/blob/main/lib/auth/authorization.ts): `lib/auth/authorization.ts`

### Course Management

- [Dashboard](https://github.com/than-sothearak/next-course-craft/blob/main/app/dashboard/dashboard-client.tsx): `app/dashboard/dashboard-client.tsx`
- [Course & Folder APIs](https://github.com/than-sothearak/next-course-craft/blob/main/app/api/courses/route.ts): `app/api/courses/route.ts`
- [Dashboard Services](https://github.com/than-sothearak/next-course-craft/blob/main/lib/dashboard/services/list.ts): `lib/dashboard/services/list.ts`
- [Workspace Services](https://github.com/than-sothearak/next-course-craft/blob/main/lib/workspaces/services.ts): `lib/workspaces/services.ts`
- [Workspace API](https://github.com/than-sothearak/next-course-craft/blob/main/app/api/workspaces/route.ts): `app/api/workspaces/route.ts`

### Authoring & Preview

- [Course Editor](https://github.com/than-sothearak/next-course-craft/blob/main/app/courses/%5BcourseId%5D/edit/_components/editor-client.tsx): `app/courses/[courseId]/edit/_components/editor-client.tsx`
- [Block Editor](https://github.com/than-sothearak/next-course-craft/blob/main/app/courses/%5BcourseId%5D/edit/_components/(editor_client_components)/content-block-editor.tsx): `app/courses/[courseId]/edit/_components/(editor_client_components)/content-block-editor.tsx`
- [Content Schemas](https://github.com/than-sothearak/next-course-craft/blob/main/lib/schemas/block.ts): `lib/schemas/block.ts`
- [Course Preview](https://github.com/than-sothearak/next-course-craft/blob/main/app/courses/%5BcourseId%5D/preview/course-preview.tsx): `app/courses/[courseId]/preview/course-preview.tsx`

### Generation & Publishing

- [Generation API](https://github.com/than-sothearak/next-course-craft/blob/main/app/api/courses/%5BcourseId%5D/generate/route.ts): `app/api/courses/[courseId]/generate/route.ts`
- [AI Generation](https://github.com/than-sothearak/next-course-craft/blob/main/lib/ai/course-generation.ts): `lib/ai/course-generation.ts`
- [Course Publishing](https://github.com/than-sothearak/next-course-craft/blob/main/app/api/courses/%5BcourseId%5D/publish/route.ts): `app/api/courses/[courseId]/publish/route.ts`
- [PDF Export](https://github.com/than-sothearak/next-course-craft/blob/main/lib/pdf/course-handout.ts): `lib/pdf/course-handout.ts`
- [SCORM Packaging](https://github.com/than-sothearak/next-course-craft/blob/main/lib/scorm/package.ts): `lib/scorm/package.ts`
- [Export Runtime](https://github.com/than-sothearak/next-course-craft/blob/main/export/src/main.ts): `export/src/main.ts`

### Platform Services

- [Media Storage Admin](https://github.com/than-sothearak/next-course-craft/blob/main/components/admin/media-storage-management.tsx): `components/admin/media-storage-management.tsx`
- [Media Service](https://github.com/than-sothearak/next-course-craft/blob/main/lib/media/service.ts): `lib/media/service.ts`
- [Administration](https://github.com/than-sothearak/next-course-craft/blob/main/components/admin/course-access-manager.tsx): `components/admin/course-access-manager.tsx`
- [MongoDB](https://github.com/than-sothearak/next-course-craft/blob/main/lib/db/mongodb.ts): `lib/db/mongodb.ts`

### Other components

- **CourseCraft User**
- **Local / S3 Storage**
- **AI Provider**
- **LMS**

## Connections

- CourseCraft User → Login: signs in (evidence: `README.md`)
- Login → OAuth & Sessions: authenticates via (evidence: `app/login/page.tsx`)
- OAuth & Sessions → MongoDB: stores identity (evidence: `lib/auth/index.ts`)
- Dashboard → Course & Folder APIs: requests courses
- Course & Folder APIs → Dashboard Services: lists and creates (evidence: `app/api/courses/route.ts`)
- Course & Folder APIs → MongoDB: connects to (evidence: `app/api/courses/route.ts`)
- Dashboard Services → MongoDB: queries models (evidence: `lib/dashboard/services/list.ts`)
- Dashboard Services → Authorization: checks access (evidence: `lib/dashboard/services/list.ts`)
- Dashboard → Workspace API: manages workspace
- Workspace API → Workspace Services: dispatches requests (evidence: `app/api/workspaces/route.ts`)
- Workspace Services → Authorization: checks permissions (evidence: `lib/workspaces/services.ts`)
- Course Editor → Block Editor: renders blocks (evidence: `app/courses/[courseId]/edit/_components/editor-client.tsx`)
- Course Editor → Content Schemas: uses schemas (evidence: `app/courses/[courseId]/edit/_components/editor-client.tsx`)
- Block Editor → Content Schemas: types content
- Course Editor → Course Preview: opens preview
- CourseCraft User → Dashboard: manages courses (evidence: `README.md`)
- CourseCraft User → Course Editor: authors lessons (evidence: `README.md`)
- CourseCraft User → Course Preview: reviews course (evidence: `README.md`)
- Generation API → AI Generation: runs generation (evidence: `app/api/courses/[courseId]/generate/route.ts`)
- Generation API → Authorization: checks access (evidence: `app/api/courses/[courseId]/generate/route.ts`)
- AI Generation → AI Provider: requests content
- Course Publishing → PDF Export: exports PDF
- Course Publishing → SCORM Packaging: packages SCORM
- Course Publishing → Export Runtime: publishes HTML
- SCORM Packaging → LMS: targets LMS (evidence: `README.md`)
- Media Storage Admin → Media Service: configures storage
- Media Service → Local / S3 Storage: stores assets (evidence: `lib/media/service.ts`)
- Media Service → MongoDB: reads settings (evidence: `lib/media/service.ts`)
- Administration → Authorization: protects access
