# envoyx/hmm-lms architecture

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

- Interactive diagram: https://gitdiagram.com/envoyx/hmm-lms
- Repository: https://github.com/envoyx/hmm-lms

## Overview

1. **High-level shape**
   - This is a **Next.js 15 App Router** monorepo-style application with a clear split between **public-facing pages**, **authenticated member pages**, and **admin back office**.
   - Most of the UI lives in `src/app`, while shared UI, hooks, and server-side domain logic are separated into `src/components`, `src/hooks`, `src/lib`, and `src/server`.

2. **Route / shell boundaries**
   - `src/app/(external)` is the public marketing and identity site for HMM ITB, with its own layout and visual sections.
   - `src/app/(with-sidebar)` is the main authenticated student/member experience with a sidebar shell.
   - `src/app/admin` is the operational/admin console for content management, analytics, database tools, and user management.
   - Separate auth and utility routes live under `src/app/auth`, `src/app/forms`, and `src/app/s/[slug]` for sign-in, public form submission, and short links.

3. **Core business domains**
   - The application centers on several domain modules: **courses**, **events**, **announcements**, **tryouts**, **forms**, **scholarships**, **job vacancies (loker)**, **shortlinks**, **profiles/settings**, and **analytics**.
   - Each domain typically has both a user-side surface and an admin-side management surface, which is important for diagramming the system as a content platform rather than a single-purpose LMS.

4. **Backend API layer**
   - The main typed backend is **tRPC** under `src/server/api`, with routers per domain such as `announcement`, `course`, `event`, `forms`, `tryout`, `loker`, `scholarship`, `short-link`, `analytics`, `dashboard`, `database`, `notifications`, and `push`.
   - `src/server/api/root.ts` composes these routers into one API surface, and `src/trpc/*` contains the client/server helpers used by the React app.
   - There are also conventional REST routes under `src/app/api` for cases like auth callbacks, document upload/delete, video access, and notification webhook handling.

5. **Data and persistence**
   - **Prisma** is the ORM, with schema and migrations in `prisma/`.
   - The primary datastore is **PostgreSQL**; `src/server/db.ts` is the database access boundary.
   - The schema is evolved through migrations, and the repo includes a later migration for job vacancy metadata, which signals that the data model is shared across many domains and evolves with feature expansion.

6. **Authentication and authorization**
   - Authentication is handled with **NextAuth** in `src/server/auth`, exposed through the `/api/auth/[...nextauth]` route.
   - Role-based access is a major architectural boundary: the app distinguishes **students/members**, **admins**, and likely **superadmins**.
   - The presence of admin-only routes and database-management UI implies server-side authorization checks are enforced in API/router code, not just in the client shell.

7. **Media, files, and external storage**
   - File/media handling is an explicit subsystem, not incidental: documents, images, course attachments, and question assets are uploaded and served through `src/app/api/documents/*` and related helpers in `src/lib`.
   - The README and code structure point to **AWS S3** as the object storage backend.
   - `src/lib/s3-client.ts`, `src/lib/file-utils.ts`, and `src/lib/external-asset.ts` suggest a shared abstraction for stored media versus externally linked assets.

8. **Notifications and push delivery**
   - Push notifications are a standalone flow: users subscribe via `/api/notifications/subscribe`, notifications are sent via `/api/notifications/send`, tested via `/test`, and integrated with a webhook endpoint.
   - Client-side notification registration and updates are handled by components like `register-sw.tsx`, `notif-prompt-modal.tsx`, and `sw-update.tsx`.
   - `public/sw.js`, `public/worker/*`, and the `worker/` directory indicate a service-worker-based PWA notification channel.

9. **Interactive learning and assessment flows**
   - **Courses** cover enrollment, resources, learning-session tracking, testimonials, and course detail pages.
   - **Tryouts** are a more complex assessment subsystem with attempts, results, analytics, and multiple question types; admin and student attempt flows are separated.
   - **Forms** are a general-purpose builder/submission system with create/edit/preview/response pages, and some of the same patterns are reused for registrations and surveys.
   - These flows combine server-rendered pages with client-heavy components for rich editing, analytics, and multi-step interactions.

10. **Event management and calendaring**
   - Events are a major subsystem with operational modes like basic listing, RSVP, attendance tracking, and combined registration/check-in.
   - The calendar UI is supported by a dedicated component set in `src/components/event-calendar`, plus schedule utilities in `src/app/(with-sidebar)/schedule`.
   - This area also ties into notifications, attendee data, and export/integration features such as Google Sheets mentioned in the README.

11. **Admin operations and analytics**
   - The admin area is not a thin wrapper; it includes analytics dashboards, content CRUD, course membership management, tryout authoring, user management, database admin tooling, and shortlink creation.
   - `src/app/admin/database` is especially notable because it exposes table browsing, create/edit/delete dialogs, pagination, refresh, and export functionality—effectively an internal data console.
   - Analytics components are shared across admin domains, implying a common reporting layer over the main business tables.

12. **Public content / brand site**
   - `src/app/(external)` is a separate public-facing experience for HMM identity, about/mission/vision content, and organogram presentation.
   - It uses its own layout, navigation, and visual treatment, backed by static assets in `public/` and custom typography in `src/fonts/`.
   - This is a good boundary to draw separately from the authenticated LMS, since it represents institutional branding rather than operational workflow.

13. **Shared UI and client-side infrastructure**
   - `src/components/ui` is a reusable design-system layer built around shadcn/ui-style primitives.
   - Higher-level shared widgets include navbar/sidebar/header components, breadcrumbs, charts, dialogs, media viewers, uploaders, and theme controls.
   - Hooks in `src/hooks` handle cross-cutting client behavior such as time indicators, file uploads, notifications, mobile detection, and local storage.

14. **Operational/tooling concerns**
   - The repo uses **Bun** for package/runtime workflows, **ESLint** and **Prettier** for quality, and **Vitest** for tests.
   - A GitHub Actions workflow (`.github/workflows/quality-gates.yml`) indicates automated quality checks in CI.
   - `public/manifest.json`, service workers, and install prompts show that the app is intentionally shipped as a **PWA**, not just a traditional website.

15. **How data flows through the system**
   - Typical flow: browser page or client component → tRPC or REST API route → server router/service → Prisma → PostgreSQL, with optional S3 interaction for media and push/notification side effects.
   - For public forms, sign-in, and short links, the flow is simplified but still lands in the same shared backend/data model.
   - For notifications and announcements, the flow often fans out from a content mutation into notification-trigger services plus service-worker delivery to end users.

Main entry points: [`src/components/ui`](https://github.com/envoyx/hmm-lms/tree/main/src/components/ui) (UI system), [`src/server/api/routers`](https://github.com/envoyx/hmm-lms/tree/main/src/server/api/routers) (Domain routers), [`src/app/api/trpc/[trpc]`](https://github.com/envoyx/hmm-lms/tree/main/src/app/api/trpc/[trpc]) (tRPC route), [`src/app/(with-sidebar)`](https://github.com/envoyx/hmm-lms/tree/main/src/app/(with-sidebar)) (Member shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public_site["Public site"]
  node_app_external["External site<br/>Next.js app"]
end

subgraph group_member_app["Member app"]
  node_app_with_sidebar["Member shell<br/>Next.js app"]
  node_app_auth_forms["Auth & forms<br/>Next.js routes"]
  node_app_shortlinks["Short links<br/>Next.js route"]
end

subgraph group_admin_console["Admin console"]
  node_app_admin["Admin shell<br/>Next.js app"]
end

subgraph group_backend["Backend"]
  node_app_api_trpc["tRPC route<br/>API route"]
  node_app_api_auth["Auth callback<br/>API route<br/>[[...nextauth]]"]
  node_app_api_media["Media API<br/>REST routes"]
  node_app_api_notifications["Notification API<br/>REST routes"]
  node_app_api_videos["Video API<br/>REST route"]
  node_api_root["API root<br/>tRPC composition<br/>[root.ts]"]
  node_api_routers["Domain routers<br/>tRPC routers"]
  node_auth_server["Auth server<br/>NextAuth config"]
  node_db[("Database<br/>Prisma/Postgres<br/>[db.ts]")]
  node_storage[("S3 storage<br/>object storage<br/>[s3-client.ts]")]
  node_notifications["Notifications<br/>push subsystem"]
end

subgraph group_shared_client["Shared client"]
  node_shared_ui["UI system<br/>component library"]
  node_shared_hooks["Client hooks"]
  node_shared_lib["Shared lib<br/>utilities"]
  node_pwa["PWA worker<br/>service worker<br/>[sw.js]"]
end

node_app_external -->|"uses"| node_shared_ui
node_app_with_sidebar -->|"uses"| node_shared_ui
node_app_admin -->|"uses"| node_shared_ui
node_app_auth_forms -->|"uses"| node_shared_ui
node_app_shortlinks -->|"reads"| node_api_root
node_app_with_sidebar -->|"calls"| node_app_api_trpc
node_app_admin -->|"calls"| node_app_api_trpc
node_app_auth_forms -->|"auth"| node_app_api_auth
node_app_auth_forms -->|"submits"| node_app_api_trpc
node_app_api_trpc -->|"routes"| node_api_root
node_api_root -->|"composes"| node_api_routers
node_api_routers -->|"queries"| node_db
node_api_routers -->|"stores"| node_storage
node_api_routers -->|"triggers"| node_notifications
node_app_api_media -->|"uploads"| node_storage
node_app_api_notifications -->|"delivers"| node_notifications
node_app_api_auth -->|"authenticates"| node_auth_server
node_auth_server -->|"persists"| node_db
node_shared_hooks -->|"relies on"| node_shared_lib
node_shared_ui -->|"relies on"| node_shared_lib
node_notifications -->|"pushes"| node_pwa
node_app_with_sidebar -->|"registers"| node_pwa
node_app_admin -->|"administers"| node_db
node_app_external -->|"content"| node_shared_lib

click node_app_external "https://github.com/envoyx/hmm-lms/tree/main/src/app/(external)"
click node_app_with_sidebar "https://github.com/envoyx/hmm-lms/tree/main/src/app/(with-sidebar)"
click node_app_admin "https://github.com/envoyx/hmm-lms/tree/main/src/app/admin"
click node_app_auth_forms "https://github.com/envoyx/hmm-lms/tree/main/src/app/auth"
click node_app_shortlinks "https://github.com/envoyx/hmm-lms/tree/main/src/app/s/[slug]"
click node_app_api_trpc "https://github.com/envoyx/hmm-lms/tree/main/src/app/api/trpc/[trpc]"
click node_app_api_auth "https://github.com/envoyx/hmm-lms/blob/main/src/app/api/auth/[...nextauth]"
click node_app_api_media "https://github.com/envoyx/hmm-lms/tree/main/src/app/api/documents"
click node_app_api_notifications "https://github.com/envoyx/hmm-lms/tree/main/src/app/api/notifications"
click node_app_api_videos "https://github.com/envoyx/hmm-lms/tree/main/src/app/api/videos"
click node_api_root "https://github.com/envoyx/hmm-lms/blob/main/src/server/api/root.ts"
click node_api_routers "https://github.com/envoyx/hmm-lms/tree/main/src/server/api/routers"
click node_auth_server "https://github.com/envoyx/hmm-lms/tree/main/src/server/auth"
click node_db "https://github.com/envoyx/hmm-lms/blob/main/src/server/db.ts"
click node_storage "https://github.com/envoyx/hmm-lms/blob/main/src/lib/s3-client.ts"
click node_notifications "https://github.com/envoyx/hmm-lms/blob/main/src/server/services/notification-triggers.ts"
click node_shared_ui "https://github.com/envoyx/hmm-lms/tree/main/src/components/ui"
click node_shared_hooks "https://github.com/envoyx/hmm-lms/tree/main/src/hooks"
click node_shared_lib "https://github.com/envoyx/hmm-lms/tree/main/src/lib"
click node_pwa "https://github.com/envoyx/hmm-lms/blob/main/public/sw.js"

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_app_external toneBlue
class node_app_with_sidebar,node_app_auth_forms,node_app_shortlinks toneAmber
class node_app_admin toneMint
class node_app_api_trpc,node_app_api_auth,node_app_api_media,node_app_api_notifications,node_app_api_videos,node_api_root,node_api_routers,node_auth_server,node_db,node_storage,node_notifications toneRose
class node_shared_ui,node_shared_hooks,node_shared_lib,node_pwa toneIndigo
```

## Components

### Public site

External brand and identity experience.

- [External site](https://github.com/envoyx/hmm-lms/tree/main/src/app/(external)): Next.js app · Public-facing HMM landing pages, about content, and organogram. · `src/app/(external)`

### Member app

Authenticated student/member experience with sidebar shell.

- [Member shell](https://github.com/envoyx/hmm-lms/tree/main/src/app/(with-sidebar)): Next.js app · Authenticated app with sidebar navigation and member workflows. · `src/app/(with-sidebar)`
- [Auth & forms](https://github.com/envoyx/hmm-lms/tree/main/src/app/auth): Next.js routes · Sign-in/sign-up pages, public form submission, and form result views. · `src/app/auth`
- [Short links](https://github.com/envoyx/hmm-lms/tree/main/src/app/s/[slug]): Next.js route · Public slug-based redirect and landing route. · `src/app/s/[slug]`

### Admin console

Operational back office for content, analytics, and data management.

- [Admin shell](https://github.com/envoyx/hmm-lms/tree/main/src/app/admin): Next.js app · Administrative console for management, analytics, and operations. · `src/app/admin`

### Backend

API, auth, persistence, and service-layer logic.

- [tRPC route](https://github.com/envoyx/hmm-lms/tree/main/src/app/api/trpc/[trpc]): API route · Single typed RPC entrypoint for application data access. · `src/app/api/trpc/[trpc]`
- [Auth callback](https://github.com/envoyx/hmm-lms/blob/main/src/app/api/auth/[...nextauth]): API route · NextAuth callback and session route. · `src/app/api/auth/[...nextauth]`
- [Media API](https://github.com/envoyx/hmm-lms/tree/main/src/app/api/documents): REST routes · Document upload, delete, and video access endpoints. · `src/app/api/documents`
- [Notification API](https://github.com/envoyx/hmm-lms/tree/main/src/app/api/notifications): REST routes · Subscription, send, test, and webhook endpoints for notifications. · `src/app/api/notifications`
- [Video API](https://github.com/envoyx/hmm-lms/tree/main/src/app/api/videos): REST route · Video retrieval endpoint. · `src/app/api/videos`
- [API root](https://github.com/envoyx/hmm-lms/blob/main/src/server/api/root.ts): tRPC composition · Composes domain routers into the main typed backend surface. · `src/server/api/root.ts`
- [Domain routers](https://github.com/envoyx/hmm-lms/tree/main/src/server/api/routers): tRPC routers · Domain-specific routers for announcements, courses, events, forms, tryouts, loker, scholarships, analytics, dashboard, database, notifications, push, and more. · `src/server/api/routers`
- [Auth server](https://github.com/envoyx/hmm-lms/tree/main/src/server/auth): NextAuth config · Server-side authentication and authorization setup. · `src/server/auth`
- [Database](https://github.com/envoyx/hmm-lms/blob/main/src/server/db.ts): Prisma/Postgres · Prisma schema and database access boundary over PostgreSQL. · `src/server/db.ts`
- [S3 storage](https://github.com/envoyx/hmm-lms/blob/main/src/lib/s3-client.ts): object storage · Shared file and media storage abstraction for uploads and assets. · `src/lib/s3-client.ts`
- [Notifications](https://github.com/envoyx/hmm-lms/blob/main/src/server/services/notification-triggers.ts): push subsystem · Push subscription, service-worker delivery, and notification triggers. · `src/server/services/notification-triggers.ts`

### Shared client

Reusable UI, hooks, and client-side infrastructure.

- [UI system](https://github.com/envoyx/hmm-lms/tree/main/src/components/ui): component library · Reusable design-system primitives and app-level shared widgets. · `src/components/ui`
- [Client hooks](https://github.com/envoyx/hmm-lms/tree/main/src/hooks): hooks · Cross-cutting client behavior for uploads, notifications, mobile, time, and storage. · `src/hooks`
- [Shared lib](https://github.com/envoyx/hmm-lms/tree/main/src/lib): utilities · Schemas, file helpers, exports, theme color, and typed shared utilities. · `src/lib`
- [PWA worker](https://github.com/envoyx/hmm-lms/blob/main/public/sw.js): service worker · Service worker and worker assets for offline/PWA and push delivery. · `public/sw.js`

## Connections

- External site → UI system: uses · Public pages render with shared UI primitives and widgets.
- Member shell → UI system: uses · Member pages build on reusable UI components and shells.
- Admin shell → UI system: uses · Admin console uses shared UI and admin widgets.
- Auth & forms → UI system: uses · Auth and form pages use common UI controls.
- Short links → API root: reads · Short-link resolution depends on backend data.
- Member shell → tRPC route: calls · Member UI fetches domain data through tRPC.
- Admin shell → tRPC route: calls · Admin UI drives CRUD and analytics through tRPC.
- Auth & forms → Auth callback: auth · Sign-in and sign-up flows use auth callbacks.
- Auth & forms → tRPC route: submits · Public forms and results interact with typed backend endpoints.
- tRPC route → API root: routes · The app RPC entrypoint forwards to the composed API surface.
- API root → Domain routers: composes · Root API aggregates all domain routers.
- Domain routers → Database: queries · Domain routers persist and read data through Prisma.
- Domain routers → S3 storage: stores · Routers handling documents and media use object storage.
- Domain routers → Notifications: triggers · Content and event mutations can fan out into notification delivery.
- Media API → S3 storage: uploads · Document endpoints proxy file upload and deletion to storage.
- Notification API → Notifications: delivers · Notification endpoints drive subscription and send flows.
- Auth callback → Auth server: authenticates · NextAuth route is backed by server auth configuration.
- Auth server → Database: persists · Authentication and user state depend on the database.
- Client hooks → Shared lib: relies on · Hooks use shared utilities and typed schemas.
- UI system → Shared lib: relies on · Shared widgets depend on common helpers and schemas.
- Notifications → PWA worker: pushes · Push delivery uses service-worker and worker assets.
- Member shell → PWA worker: registers · Member experience registers the service worker and install flow.
- Admin shell → Database: administers · Admin database tools operate directly over persisted data.
- External site → Shared lib: content · Public brand pages use shared content and asset helpers.
