# rakheshkrishna2005/livedocs architecture

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

- Interactive diagram: https://gitdiagram.com/rakheshkrishna2005/livedocs
- Repository: https://github.com/rakheshkrishna2005/livedocs

## Overview

##### Project Type and Purpose
- This is a full-stack, real-time collaborative document editing web application (“LiveDocs”).
- Frontend built with Next.js (React + TypeScript + TailwindCSS + shadcn/ui).
- Backend consists of an Express.js server (TypeScript) exposing both REST APIs and a Socket.IO server for live sync.
- MongoDB/Mongoose is used for persistent storage.
- Authentication via JWT in HTTP-only cookies.

##### File Structure
- **app/** – Next.js 15 app directory: page routes under `/app/api` (REST endpoints), layout, pages for login/register/dashboard/document views, public viewer.
- **components/** & **components/ui/** – React UI components (shadcn/ui wrappers).
- **context/** – React Context providers (user, document state).
- **hooks/** – Custom React hooks (mobile detection, toasts).
- **lib/** – Shared utilities: `auth.ts`, `db.ts` (MongoDB connection), Mongoose models.
- **middleware.ts** & **next.config.mjs**, **tailwind.config.ts** – Next.js middleware and configuration.
- **server/** – Standalone Express.js + Socket.IO server, its own package.json and tsconfig.
- **public/** & **styles/** – Static assets and global CSS.

##### README for Additional Insights
- Key features: real-time collaboration, markdown support with live preview, cursor tracking, auto-save, sharing.
- Tech stack: Next.js (frontend), Express.js + Socket.IO (backend), MongoDB.
- Client → Next.js middleware → Auth → Pages/API → Socket.IO → Express → MongoDB
- Real-time sync channels (update, cursor_move, user_presence)
- Public sharing path with token validation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Client["Client Browser (Next.js React App)"]:::frontend
        subgraph "Components"
            UI["UI Components (shadcn/ui Wrappers)"]:::frontend
            Core["Core React Components"]:::frontend
            Context["React Context Providers"]:::frontend
            Hooks["Custom React Hooks"]:::frontend
        end
        Client --> UI
        Client --> Core
        Client --> Context
        Client --> Hooks
    end

    %% Next.js Server Layer
    subgraph "Next.js Server (API Layer)"
        MW["Next.js Middleware"]:::api
        subgraph "API Routes"
            AuthRoutes["Auth Routes (/api/auth)"]:::api
            DocRoutes["Document Routes (/api/documents)"]:::api
            PublicAPIRoute["Public Document API (/api/documents/[id]/public)"]:::api
        end
        MW --> AuthRoutes
        MW --> DocRoutes
        MW --> PublicAPIRoute
        AuthRoutes -->|"validates JWT"| libAuth["Authentication Module"]:::api
        DocRoutes -->|"validates JWT"| libAuth
        PublicAPIRoute -->|"validates token"| libAuth
    end

    %% Real-Time Server Layer
    subgraph "Real-Time Server"
        RTS["Express + Socket.IO Server"]:::realtime
    end

    %% Database Layer
    subgraph "Database Layer"
        DBConn["Database Connection (MongoDB)"]:::db
        Models["Mongoose Models"]:::db
    end

    %% Public Viewer
    subgraph "Public Viewer"
        PublicPage["Public Viewer Page"]:::public
    end

    %% Interactions
    Client -->|"HTTP Requests"| MW
    Client -->|"Socket.IO Events (join_document, update, cursor_move)"| RTS
    AuthRoutes <-->|"CRUD Documents"| Models
    DocRoutes <-->|"CRUD Documents"| Models
    PublicAPIRoute <-->|"Fetch Document"| Models
    RTS -->|"Auto-save & share-token"| DBConn
    DBConn --> Models
    PublicPage -->|"HTTP GET /public/document/[id]"| PublicAPIRoute

    %% Click Events
    click Client "https://github.com/rakheshkrishna2005/livedocs/tree/main/app/"
    click MW "https://github.com/rakheshkrishna2005/livedocs/blob/main/middleware.ts"
    click AuthRoutes "https://github.com/rakheshkrishna2005/livedocs/tree/main/app/api/auth/"
    click DocRoutes "https://github.com/rakheshkrishna2005/livedocs/tree/main/app/api/documents/"
    click PublicAPIRoute "https://github.com/rakheshkrishna2005/livedocs/blob/main/app/api/documents/[id]/public/route.ts"
    click libAuth "https://github.com/rakheshkrishna2005/livedocs/blob/main/lib/auth.ts"
    click DBConn "https://github.com/rakheshkrishna2005/livedocs/blob/main/lib/db.ts"
    click Models "https://github.com/rakheshkrishna2005/livedocs/tree/main/lib/models/"
    click RTS "https://github.com/rakheshkrishna2005/livedocs/blob/main/server/server.ts"
    click UI "https://github.com/rakheshkrishna2005/livedocs/tree/main/components/ui/"
    click Core "https://github.com/rakheshkrishna2005/livedocs/blob/main/components/editor.tsx"
    click Core "https://github.com/rakheshkrishna2005/livedocs/blob/main/components/text-editor.tsx"
    click Core "https://github.com/rakheshkrishna2005/livedocs/blob/main/components/navbar.tsx"
    click Core "https://github.com/rakheshkrishna2005/livedocs/blob/main/components/dashboard.tsx"
    click Core "https://github.com/rakheshkrishna2005/livedocs/blob/main/components/entry-modal.tsx"
    click Core "https://github.com/rakheshkrishna2005/livedocs/blob/main/components/theme-provider.tsx"
    click Core "https://github.com/rakheshkrishna2005/livedocs/blob/main/components/user-cursor.tsx"
    click Context "https://github.com/rakheshkrishna2005/livedocs/blob/main/context/user-context.tsx"
    click Context "https://github.com/rakheshkrishna2005/livedocs/blob/main/context/document-context.tsx"
    click Hooks "https://github.com/rakheshkrishna2005/livedocs/blob/main/hooks/use-mobile.tsx"
    click Hooks "https://github.com/rakheshkrishna2005/livedocs/blob/main/hooks/use-toast.ts"
    click Utils "https://github.com/rakheshkrishna2005/livedocs/blob/main/lib/utils.ts"
    click Styles1 "https://github.com/rakheshkrishna2005/livedocs/blob/main/styles/globals.css"
    click Styles2 "https://github.com/rakheshkrishna2005/livedocs/blob/main/app/globals.css"
    click Styles3 "https://github.com/rakheshkrishna2005/livedocs/blob/main/tailwind.config.ts"
    click Styles4 "https://github.com/rakheshkrishna2005/livedocs/blob/main/next.config.mjs"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef api fill:#EAD7FF,stroke:#6f42c1,color:#6f42c1;
    classDef realtime fill:#D9F7BE,stroke:#28a745,color:#28a745;
    classDef db fill:#FFE8A1,stroke:#d68d00,color:#d68d00;
    classDef public fill:#FFF5BA,stroke:#ffb700,color:#ffb700;
    classDef Utils fill:#F0F0F0,stroke:#888888,color:#333333;
    class Client,UI,Core,Context,Hooks frontend
    class MW,AuthRoutes,DocRoutes,PublicAPIRoute,libAuth api
    class RTS realtime
    class DBConn,Models db
    class PublicPage public
    class Utils,Styles1,Styles2,Styles3,Styles4 Utils
```
