# thefznkhan/next-docs architecture

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

- Interactive diagram: https://gitdiagram.com/thefznkhan/next-docs
- Repository: https://github.com/thefznkhan/next-docs

## Overview

##### Main Components

A. Frontend Layer:
- Next.js Application (Client-Side)
- Auth Routes (/sign-in, /sign-up)
- Document Routes (/documents, /documents/[id])
- Real-time Collaboration UI Components
- UI Components Layer
- Editor Components
- Collaboration Components (ActiveCollaborators, Comments)
- Modal Components (ShareModal, DeleteModal)

B. Backend Layer:
- Next.js API Routes
- Authentication Endpoints
- Liveblocks Integration
- Middleware Layer
- Authentication/Authorization
- API Route Protection

C. External Services:
- Liveblocks Service
- Real-time Collaboration
- Presence Management
- Document Synchronization

##### Component Relationships

- Client → API Routes (HTTP/API calls)
- Client → Liveblocks (WebSocket connections)
- API Routes → Liveblocks (Authentication/Authorization)
- Editor → Real-time Collaboration System

##### Specific Implementation Details

Technical aspects:
- Authentication Flow
- Sign-in/Sign-up Process
- Session Management
- Document Collaboration
- Real-time Updates
- Presence Awareness
- Comments System

##### Key Architectural Patterns to Highlight

- Next.js App Router Architecture
- Real-time Collaboration Pattern
- Component-based UI Architecture
- Server/Client Components Separation

Create distinct sections for:
a. User Interface Layer
- Auth Components
- Document Editor
- Collaboration Features

b. Application Layer
- Next.js Routes
- API Endpoints
- Action Handlers

c. External Services Layer
- Liveblocks Integration
- Authentication Services

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend Layer"
        UI["UI Components"]
        AuthRoutes["Authentication Routes"]:::auth
        DocRoutes["Document Routes"]:::docs
        Editor["Editor Components"]:::editor
        RTC["Real-time Collaboration UI"]:::rtc
        Modals["Modal Components"]:::modals
        Providers["Application Providers"]:::providers
        Theme["Theme/Styling"]:::theme
    end

    subgraph "Backend Layer"
        API["API Routes"]:::api
        Middleware["Middleware Layer"]:::middleware
        Actions["Action Handlers"]:::actions
    end

    subgraph "External Services"
        Liveblocks["Liveblocks Service"]:::liveblocks
    end

    %% Relationships
    UI --> AuthRoutes
    UI --> DocRoutes
    UI --> Editor
    UI --> RTC
    UI --> Modals
    
    AuthRoutes -.-> API
    DocRoutes -.-> API
    Editor -.-> API
    
    API --> Middleware
    Middleware --> Liveblocks
    
    Editor -. "Real-time Updates" .-> Liveblocks
    RTC -. "WebSocket" .-> Liveblocks
    
    Actions --> API
    Providers --> UI

    %% Click Events
    click AuthRoutes "https://github.com/THEFZNKHAN/next-docs/blob/main/app/(auth)/sign-in/[[...sign-in]]/page.tsx"
    click DocRoutes "https://github.com/THEFZNKHAN/next-docs/blob/main/app/(root)/documents/[id]/page.tsx"
    click Editor "https://github.com/THEFZNKHAN/next-docs/blob/main/components/editor/Editor.tsx"
    click RTC "https://github.com/THEFZNKHAN/next-docs/blob/main/components/CollaborativeRoom.tsx"
    click Modals "https://github.com/THEFZNKHAN/next-docs/blob/main/components/ShareModal.tsx"
    click API "https://github.com/THEFZNKHAN/next-docs/blob/main/app/api/liveblocks-auth/route.ts"
    click Middleware "https://github.com/THEFZNKHAN/next-docs/blob/main/middleware.ts"
    click Liveblocks "https://github.com/THEFZNKHAN/next-docs/blob/main/lib/liveblocks.ts"
    click Actions "https://github.com/THEFZNKHAN/next-docs/blob/main/lib/actions/room.actions.ts"
    click Providers "https://github.com/THEFZNKHAN/next-docs/blob/main/app/Provider.tsx"
    click Theme "https://github.com/THEFZNKHAN/next-docs/blob/main/styles/dark-theme.css"

    %% Styling
    classDef frontend fill:#2196F3,color:white
    classDef backend fill:#4CAF50,color:white
    classDef external fill:#9C27B0,color:white
    classDef auth fill:#1976D2,color:white
    classDef docs fill:#1976D2,color:white
    classDef editor fill:#1976D2,color:white
    classDef rtc fill:#1976D2,color:white
    classDef modals fill:#1976D2,color:white
    classDef api fill:#388E3C,color:white
    classDef middleware fill:#388E3C,color:white
    classDef actions fill:#388E3C,color:white
    classDef liveblocks fill:#7B1FA2,color:white
    classDef providers fill:#1976D2,color:white
    classDef theme fill:#1976D2,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        External["External Service"]:::external
        direction TB
    end
```
