# pegak/nauc-me-it architecture

> Architecture diagram of the GitHub repository pegak/nauc-me-it, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pegak/nauc-me-it
- Repository: https://github.com/pegak/nauc-me-it

## Overview

##### Project Type and Purpose
- This is an Nx-managed TypeScript monorepo containing:
- A Node-based backend (“apps/backend”)
- Two web frontends (“apps/coursition” built with Modern.js; “apps/legacy_nmit” built with Next.js)
- Shared libraries under “libs/” (e.g., api, auth, db, ai, env, ui/design-system, utils)
- The purpose is to host multiple deployable apps sharing code and infrastructure in one repository.

##### High-Level Architectural Components
a. Monorepo Shell
- Nx orchestrator, PNPM workspaces, Proto tool management
b. Applications
- Backend API (apps/backend)
- Frontend “Coursition” (Real-time editor/video player)
- Frontend “Legacy NMIT” (Next.js website/CMS)
c. Shared Libraries
- libs/api – API route definitions and HTTP clients
- libs/auth – Authentication logic and types
- libs/db – Prisma client & schema
- libs/env – Environment/secrets management (Infisical)
- libs/ai – AI utilities (document processing, media, generation)
- libs/utils – General utilities (media, date, string, subtitles)
- libs/ui/design-system – Shared React components/styles
d. External Services
- Relational database (Prisma / Supabase)
- Supabase config (apps/legacy_nmit/supabase)
- Stripe (payment via utils/stripe.ts)
- Liveblocks (real-time collaboration)
- Transcription/Media services
- CI/CD (GitHub Actions, zerops)

##### Interactions & Data Flows
- Frontends → Backend API via HTTP/REST (libs/api)
- Backend → Database via Prisma client (libs/db)
- Auth flows managed by libs/auth and NextAuth (legacy_nmit)
- Secrets injected at runtime via libs/env (Infisical)
- AI-driven features call libs/ai in backend or serverless functions
- Real-time editing uses Liveblocks in coursition frontend
- Payments routed from frontends/backends to Stripe via libs/utils/stripe.ts
- Assets and static content served from CDN or host (e.g., Next.js `public/`, coursition `src/static`)

##### Architectural Patterns & Principles
- Monorepo modularization by application and shared libraries
- Clear separation: UI apps, API layer, business logic (libs), data access (Prisma)
- Code reuse via Nx library boundaries
- Dependency inversion: frontends depend on shared libs, not on each other
- Environment-agnostic config with libs/env
- CI/CD configured per-app with GitHub workflows and zerops

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Monorepo Tools
    subgraph "Monorepo Tools"
        direction TB
        Nx["Nx Orchestrator"]:::tools
        Pnpm["PNPM Workspaces"]:::tools
        Proto["Proto Tools"]:::tools
    end

    %% Applications
    subgraph "Applications"
        direction TB
        Backend["Backend API\n(apps/backend)"]:::app
        Coursition["Coursition Frontend\n(apps/coursition)"]:::app
        Legacy["Legacy NMIT Frontend\n(apps/legacy_nmit)"]:::app
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        direction TB
        libsAPI["libs/api\n(API routes & clients)"]:::lib
        libsAuth["libs/auth\n(Auth logic & types)"]:::lib
        libsDB["libs/db\n(Prisma client & schema)"]:::lib
        libsEnv["libs/env\n(Env & secrets)"]:::lib
        libsAI["libs/ai\n(AI utilities)"]:::lib
        libsUtils["libs/utils\n(General utilities)"]:::lib
        libsUI["libs/ui/design-system\n(UI components)"]:::lib
    end

    %% External Services
    subgraph "External Services"
        direction TB
        RelDB["Relational DB\n(Prisma/Supabase)"]:::external
        SupabaseCfg["Supabase Config\n(legacy_nmit)"]:::external
        Stripe["Stripe Payment"]:::external
        Liveblocks["Liveblocks\n(Real-time)"]:::external
        Transcription["Transcription & Media"]:::external
    end

    %% CI/CD
    subgraph "CI/CD"
        direction TB
        GH["GitHub Actions"]:::cicd
        ZOps["Zerops"]:::cicd
    end

    %% Relationships
    Coursition -->|"REST v1"| Backend
    Legacy -->|"REST v1"| Backend

    Backend -->|"HTTP routing"| libsAPI
    Backend -->|"Auth flows"| libsAuth
    Backend -->|"Prisma ORM"| RelDB
    Backend -->|"AI workflows"| libsAI
    Backend -->|"Uses env"| libsEnv

    libsEnv -->|"Secrets at runtime"| Backend

    Coursition <-->|"WebSocket"| Liveblocks

    Coursition -->|"Stripe API"| Stripe
    Legacy -->|"Stripe API"| Stripe

    GH -->|"runs builds/tests"| Nx
    GH -->|"runs builds/tests"| Pnpm
    GH -->|"runs builds/tests"| Proto

    ZOps -->|"deploys"| Backend
    ZOps -->|"deploys"| Coursition
    ZOps -->|"deploys"| Legacy

    %% Click Events
    click Nx "https://github.com/pegak/nauc-me-it/blob/master/nx.json"
    click Pnpm "https://github.com/pegak/nauc-me-it/blob/master/pnpm-workspace.yaml"
    click Proto "https://github.com/pegak/nauc-me-it/blob/master/.prototools"
    click Backend "https://github.com/pegak/nauc-me-it/blob/master/apps/backend/src/index.ts"
    click Coursition "https://github.com/pegak/nauc-me-it/tree/master/apps/coursition"
    click Legacy "https://github.com/pegak/nauc-me-it/tree/master/apps/legacy_nmit"
    click SupabaseCfg "https://github.com/pegak/nauc-me-it/blob/master/apps/legacy_nmit/supabase/config.toml"
    click Stripe "https://github.com/pegak/nauc-me-it/blob/master/apps/legacy_nmit/utils/stripe.ts"
    click libsAPI "https://github.com/pegak/nauc-me-it/tree/master/libs/api"
    click libsAuth "https://github.com/pegak/nauc-me-it/tree/master/libs/auth"
    click libsDB "https://github.com/pegak/nauc-me-it/tree/master/libs/db/src"
    click libsEnv "https://github.com/pegak/nauc-me-it/tree/master/libs/env"
    click libsAI "https://github.com/pegak/nauc-me-it/tree/master/libs/ai"
    click libsUtils "https://github.com/pegak/nauc-me-it/tree/master/libs/utils"
    click libsUI "https://github.com/pegak/nauc-me-it/tree/master/libs/ui/design-system"
    click Liveblocks "https://github.com/pegak/nauc-me-it/blob/master/apps/coursition/src/liveblocks.config.ts"
    click GH "https://github.com/pegak/nauc-me-it/tree/master/apps/legacy_nmit/.github/workflows"
    click ZOps "https://github.com/pegak/nauc-me-it/blob/master/zerops.yml"

    %% Styles
    classDef tools fill:#cccccc,stroke:#666,stroke-width:2px
    classDef app fill:#8ecae6,stroke:#025047,stroke-width:2px
    classDef lib fill:#a8e6cf,stroke:#056676,stroke-width:2px
    classDef external fill:#ffd6a5,stroke:#aa5500,stroke-width:2px
    classDef cicd fill:#ffadad,stroke:#a60000,stroke-width:2px
```
