# ubclaunchpad/forum architecture

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

- Interactive diagram: https://gitdiagram.com/ubclaunchpad/forum
- Repository: https://github.com/ubclaunchpad/forum

## Overview

##### Project type and purpose
- This is a full-stack web and desktop application (“ForumAI”) combining a Next.js/Tauri front end, a Supabase-backed API layer (Deno Edge Functions), a Postgres database, and AI services (OpenAI + custom Deno “model” runners).
- Its purpose is to power structured academic discussion forums with AI assistance, user authentication, file storage, and real-time interactions.

##### File structure
- Top-level directories:
- frontend – Next.js (App Router) + Tauri integration for desktop builds
- server – Supabase Edge Functions written in Deno, organized by domain (courses, posts, users, documents, search, analytics, status) plus migrations/seed files for Postgres
- model – standalone Deno scripts (embed.ts, report.ts) for AI workflows (embeddings, report generation)
- shared – Deno module with shared schemas, types and utilities consumed by server & model
- Key patterns:
- Monorepo separation of concerns (frontend vs. API vs. model vs. shared code)
- BFF (Backend-For-Frontend) approach via Supabase Edge Functions
- Next.js App Router with React contexts/providers for state management
- Config & deployment files: Dockerfiles (frontend, model), deno.json/lock for server/model/shared, Supabase config.toml, migrations, GitHub workflows.

##### README
- Confirms core stack: Next.js, Supabase (Auth, Edge Functions, Storage, Postgres), Deno for tests and edge functions, OpenAI API for AI assistance
- Outlines developer setup: environment variables, Supabase CLI commands, Deno test commands

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Tier
    subgraph "Client Tier"
        style ClientTier fill:#e0f7ff,stroke:#333,stroke-width:1px
        WebApp["Next.js App"]:::frontend
        UIComponents["UI Components"]:::frontend
        Providers["Contexts & Providers"]:::frontend
        DesktopApp["Tauri Shell"]:::frontend
    end

    %% API Tier (BFF)
    subgraph "API Tier (BFF)"
        style APITier fill:#e0ffe0,stroke:#333,stroke-width:1px
        subgraph "Courses Domain"
            CI["index.ts"]:::api
            CC["controller/"]:::api
        end
        subgraph "Posts Domain"
            PI["index.ts"]:::api
            PC["controllers/"]:::api
        end
        subgraph "Users Domain"
            UI["index.ts"]:::api
            UC["controller.ts"]:::api
        end
        subgraph "Documents Domain"
            DI["index.ts"]:::api
            DC["documentController.ts"]:::api
        end
        Search["search/index.ts"]:::api
        Analytics["analytics/index.ts"]:::api
        Status["status/index.ts"]:::api
        subgraph "Shared Utilities"
            Utils["utils/"]:::api
            DBUtil["db.ts"]:::api
        end
    end

    %% Data Tier
    subgraph "Data Tier"
        style DataTier fill:#fff0e0,stroke:#333,stroke-width:1px
        Postgres[(Postgres DB)]:::data
        Auth["Supabase Auth"]:::data
        Storage["Supabase Storage"]:::data
    end

    %% AI Tier
    subgraph "AI Tier"
        style AITier fill:#f3e0ff,stroke:#333,stroke-width:1px
        OpenAI["OpenAI API"]:::external
        AIEntry["model/index.ts"]:::gray
        Embed["embed.ts"]:::gray
        Report["report.ts"]:::gray
    end

    %% Shared Libraries
    Shared["Shared Libraries"]:::gray

    %% Connections
    WebApp -->|calls| CI
    WebApp -->|calls| PI
    WebApp -->|calls| UI
    WebApp -->|calls| DI
    WebApp -->|calls| Search
    WebApp -->|calls| Analytics
    WebApp -->|calls| Status
    DesktopApp -->|calls| CI

    CI -->|uses| Postgres
    PI -->|uses| Postgres
    UI -->|uses| Postgres
    DI -->|uses| Postgres
    Search -->|uses| Postgres
    Analytics -->|uses| Postgres
    Status -->|uses| Postgres

    CI -->|uses| Auth
    PI -->|uses| Auth
    UI -->|uses| Auth
    DI -->|uses| Auth

    DI -->|uses| Storage

    CI -->|imports| Utils
    PI -->|imports| Utils
    UI -->|imports| Utils
    DI -->|imports| Utils
    Search -->|imports| Utils
    Analytics -->|imports| Utils
    Status -->|imports| Utils
    Utils -->|connects| DBUtil
    Shared -->|shared with| CI
    Shared -->|shared with| AIEntry

    CI -->|can trigger| AIEntry
    UI -->|can trigger| AIEntry
    DI -->|can trigger| AIEntry
    AIEntry -->|runs| Embed
    AIEntry -->|runs| Report
    AIEntry -->|calls| OpenAI

    %% Click Events
    click WebApp "https://github.com/ubclaunchpad/forum/tree/dev/frontend/src/app"
    click UIComponents "https://github.com/ubclaunchpad/forum/tree/dev/frontend/src/components"
    click Providers "https://github.com/ubclaunchpad/forum/tree/dev/frontend/src/providers"
    click DesktopApp "https://github.com/ubclaunchpad/forum/tree/dev/frontend/src-tauri"
    click CI "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/functions/courses/index.ts"
    click CC "https://github.com/ubclaunchpad/forum/tree/dev/server/supabase/functions/courses/controller/"
    click PI "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/functions/posts/index.ts"
    click PC "https://github.com/ubclaunchpad/forum/tree/dev/server/supabase/functions/posts/controllers/"
    click UI "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/functions/users/index.ts"
    click UC "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/functions/users/controller.ts"
    click DI "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/functions/documents/index.ts"
    click DC "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/functions/documents/documentController.ts"
    click Search "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/functions/search/index.ts"
    click Analytics "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/functions/analytics/index.ts"
    click Status "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/functions/status/index.ts"
    click Utils "https://github.com/ubclaunchpad/forum/tree/dev/server/supabase/functions/_shared/utils/"
    click DBUtil "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/functions/_shared/db.ts"
    click Postgres "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/migrations/*.sql"
    click Postgres "https://github.com/ubclaunchpad/forum/blob/dev/server/supabase/seed.sql"
    click Embed "https://github.com/ubclaunchpad/forum/blob/dev/model/runners/embed.ts"
    click Report "https://github.com/ubclaunchpad/forum/blob/dev/model/runners/report.ts"
    click AIEntry "https://github.com/ubclaunchpad/forum/blob/dev/model/index.ts"
    click Shared "https://github.com/ubclaunchpad/forum/blob/dev/shared/mod.ts"
    click Shared "https://github.com/ubclaunchpad/forum/tree/dev/shared/schema/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0366d6,stroke-width:2px
    classDef api fill:#d4f8d4,stroke:#28a745,stroke-width:2px
    classDef data fill:#ffe5b4,stroke:#fd7e14,stroke-width:2px
    classDef external fill:#e2ccff,stroke:#6f42c1,stroke-width:2px
    classDef gray fill:#f0f0f0,stroke:#6c757d,stroke-width:2px
```
