# stradi/bforum architecture

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

- Interactive diagram: https://gitdiagram.com/stradi/bforum
- Repository: https://github.com/stradi/bforum

## Overview

##### Main Components

A. Frontend Layer (Next.js Application):
- Client-side Components (/apps/frontend/src/components)
- App Routes (/apps/frontend/src/app)
- API Integration Layer (/apps/frontend/src/lib/api)
- Authentication System
- Admin Interface (/apps/frontend/src/app/admin)

B. Backend Layer (Node.js/Bun Application):
- API Controllers (/apps/backend/src/modules)
- Database Layer (/apps/backend/src/database)
- Authentication Service
- Middleware Stack (/apps/backend/src/middlewares)

C. Database Layer:
- SQL Database (indicated by Drizzle ORM usage)
- Schema Components:
- Accounts
- Groups
- Permissions
- Nodes
- Threads
- Replies

**┌─ Client Layer ─────────────────────┐**
- ┌─ Next.js Frontend ────────────┐  │
- Public Routes              │  │
- Protected Routes           │  │
- Admin Dashboard            │  │
- Authentication UI          │  │
- ┘  │
- ┬──────────────────┘

**┌──────────────▼──────────────────┐**
- ┌─ API Layer ─────────────────┐ │
- Auth Middleware          │ │
- API Routes              │ │
- Request Validation      │ │
- ┬─────────────┘ │

- ┌─────────────▼─────────────┐ │
- Module Controllers        │ │
- Accounts               │ │
- Groups                 │ │
- Nodes                  │ │
- Threads                │ │
- Replies                │ │
- ┬─────────────┘ │
- ┼───────────────┘

**┌───────────────▼───────────────┐**
- ┌─ Database Layer ──────────┐ │
- Drizzle ORM           │ │
- SQL Database          │ │
- Migrations           │ │
- ┘ │
- ┘

##### Important Relationships to Highlight

- Authentication flow between frontend and backend
- Data flow from client through API to database
- Admin dashboard interactions with backend services
- Middleware chain in the backend
- Permission system integration across layers

##### Additional Elements

Specific architectural patterns:
- Module-based architecture in backend
- Route grouping in frontend
- Middleware pipeline
- Authentication boundaries
- API client abstraction layer

##### Technical Details to Note

- Next.js frontend with app router
- Backend API with modular structure
- Drizzle ORM for database operations
- JWT authentication (based on types)
- Role-based access control (Groups and Permissions)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef auth fill:#e74c3c,stroke:#c0392b,color:white
    classDef api fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Frontend Layer
    subgraph Frontend
        FComponents["Frontend Components"]
        FRoutes["Public Routes"]
        FAdmin["Admin Interface"]
        FAuth["Authentication UI"]
        FAPI["API Integration"]
    end

    %% Backend Layer
    subgraph Backend
        BControllers["Controllers"]
        BAuth["Authentication Service"]
        BMiddleware["Middleware Stack"]
        
        subgraph Modules
            MAccounts["Account Module"]
            MGroups["Groups Module"]
            MNodes["Nodes Module"]
            MThreads["Threads Module"]
            MReplies["Replies Module"]
            MPerms["Permissions Module"]
        end
    end

    %% Database Layer
    subgraph Database
        DBLayer["Database Layer"]
        DBSchemas["Schemas"]
        DBMigrations["Migrations"]
        
        subgraph Tables
            TAccounts["Accounts"]
            TGroups["Groups"]
            TNodes["Nodes"]
            TThreads["Threads"]
            TReplies["Replies"]
            TPerms["Permissions"]
        end
    end

    %% Relationships
    FComponents --> FAPI
    FRoutes --> FAPI
    FAdmin --> FAPI
    FAuth --> FAPI
    
    FAPI --> BMiddleware
    BMiddleware --> BControllers
    BMiddleware --> BAuth
    
    BControllers --> MAccounts
    BControllers --> MGroups
    BControllers --> MNodes
    BControllers --> MThreads
    BControllers --> MReplies
    BControllers --> MPerms
    
    MAccounts --> DBLayer
    MGroups --> DBLayer
    MNodes --> DBLayer
    MThreads --> DBLayer
    MReplies --> DBLayer
    MPerms --> DBLayer
    
    DBLayer --> DBSchemas
    DBLayer --> DBMigrations
    
    DBSchemas --> Tables
    
    %% Styling
    class FComponents,FRoutes,FAdmin,FAuth,FAPI frontend
    class BControllers,BMiddleware,MAccounts,MGroups,MNodes,MThreads,MReplies,MPerms backend
    class DBLayer,DBSchemas,DBMigrations,TAccounts,TGroups,TNodes,TThreads,TReplies,TPerms database
    class BAuth,FAuth auth
    class FAPI api

    %% Click Events
    click FComponents "https://github.com/Stradi/bforum/tree/main/apps/frontend/src/components"
    click FRoutes "https://github.com/Stradi/bforum/tree/main/apps/frontend/src/app"
    click FAdmin "https://github.com/Stradi/bforum/tree/main/apps/frontend/src/app/admin"
    click FAuth "https://github.com/Stradi/bforum/tree/main/apps/frontend/src/app/(auth)"
    click FAPI "https://github.com/Stradi/bforum/tree/main/apps/frontend/src/lib/api"
    click BControllers "https://github.com/Stradi/bforum/tree/main/apps/backend/src/modules"
    click BAuth "https://github.com/Stradi/bforum/tree/main/apps/backend/src/modules/auth"
    click BMiddleware "https://github.com/Stradi/bforum/tree/main/apps/backend/src/middlewares"
    click DBLayer "https://github.com/Stradi/bforum/tree/main/apps/backend/src/database"
    click DBSchemas "https://github.com/Stradi/bforum/tree/main/apps/backend/src/database/schemas"
    click DBMigrations "https://github.com/Stradi/bforum/tree/main/apps/backend/drizzle"
    click MAccounts "https://github.com/Stradi/bforum/tree/main/apps/backend/src/modules/accounts"
    click MThreads "https://github.com/Stradi/bforum/tree/main/apps/backend/src/modules/threads"
    click MNodes "https://github.com/Stradi/bforum/tree/main/apps/backend/src/modules/nodes"
    click MPerms "https://github.com/Stradi/bforum/tree/main/apps/backend/src/modules/permissions"
    click MReplies "https://github.com/Stradi/bforum/tree/main/apps/backend/src/modules/replies"
```
