# mohamedhabibfrigui/slack-clone architecture

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

- Interactive diagram: https://gitdiagram.com/mohamedhabibfrigui/slack-clone
- Repository: https://github.com/mohamedhabibfrigui/slack-clone

## Overview

##### Project Type and Purpose
- This is a full-stack, serverless web application built on Next.js (App Router) with Convex providing backend logic and data storage.
- It implements a real-time chat/workspace system: user authentication, workspaces, channels, direct conversations, messages, reactions, file uploads.

##### File Structure Analysis
- Top-level:
– next.config.mjs, postcss.config.mjs, tailwind.config.ts, tsconfig.json, package.json: build & toolchain config for Next.js, Tailwind CSS, TypeScript.
– convex/ directory: contains generated API types, data model, server functions (channels.ts, messages.ts, etc.), authentication config, HTTP endpoints, upload handlers.
– public/: static assets.
– sampleData.jsonl: seed data for development.
- src/ directory follows a “feature-sliced” pattern:
– src/app/: Next.js App Router pages, layouts, global styles, workspace and join flows.
– src/components/: generic UI components and providers (ConvexClientProvider, JotaiProvider).
– src/features/: feature modules by domain (auth, channels, conversations, members, messages, reaction, upload, workspaces). Each has api hooks, UI components, and local store.
– src/hooks/: custom React hooks for URL params and UI state.
– src/lib/: utility functions.
– middleware.ts: Next.js middleware for auth redirects, etc.

##### Key Insights from README
- Standard Next.js “create-next-app” bootstrap.

##### Components
- Frontend (Browser):
– Next.js App Router (pages under src/app) with server-side rendering and client components.
– UI Component Library (src/components/ui).
– ConvexClientProvider + JotaiProvider: global context for data fetching and state.
– Feature modules: auth, workspaces, channels, conversations, members, messages, reactions, upload.
- API Layer:
– Convex client SDK in browser talking to Convex HTTP endpoints.
- Backend (Serverless):
– Convex server functions (convex/*.ts): business logic and data access (CRUD for users, messages, workspaces, etc.).
– Convex HTTP endpoints (convex/http.ts) for file uploads or custom REST usage.
- Data Storage:
– Convex’s managed database (documents/collections defined in convex/schema.ts).
- External Services:
– Vercel (hosting) or any CDN.
– Cloud storage or S3 for uploads (if configured).
– Authentication provider (if external OAuth is used, configured in auth.config.ts).

##### Relationships and Data Flows
- User Browser → Next.js (SSR + SPA hydration).
- Next.js Client Components → ConvexClientProvider → Convex HTTP endpoints.
- Convex Functions → Data Model → Convex Database.
- Upload Flow: Client requests upload URL from convex/upload.ts → Uploads file to storage → Convex records metadata.
- Authentication Flow: Next.js Middleware → Convex auth.ts flows → Session tokens.

##### Architectural Patterns and Design Principles
- Feature-centric module organization for scale and clarity.
- Separation of concerns:
– Presentation (components, pages).
– State & data fetching (Convex hooks, Jotai stores).
– Business logic & data access (Convex server functions).
- Serverless functions eliminate custom backend server maintenance.
- Next.js App Router enables SSR/SSG and API routes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    Browser["Browser"]:::frontend

    subgraph "Next.js Application" 
        direction TB
        NextjsApp["Next.js App Router\n(src/app/)"]:::frontend
        UI["UI Component Library\n(src/components/ui/)"]:::frontend
        ConvexClientProvider["ConvexClientProvider"]:::frontend
        JotaiProvider["JotaiProvider"]:::frontend
        subgraph "Feature Modules"
            direction TB
            AuthFeature["Auth Feature\n(src/features/auth/)"]:::frontend
            WorkspacesFeature["Workspaces Feature\n(src/features/workspaces/)"]:::frontend
            ChannelsFeature["Channels Feature\n(src/features/channels/)"]:::frontend
            ConversationsFeature["Conversations Feature\n(src/features/conversations/)"]:::frontend
            MembersFeature["Members Feature\n(src/features/members/)"]:::frontend
            MessagesFeature["Messages Feature\n(src/features/messages/)"]:::frontend
            ReactionFeature["Reaction Feature\n(src/features/reaction/)"]:::frontend
            UploadFeature["Upload Feature\n(src/features/upload/)"]:::frontend
        end
        Hooks["Custom React Hooks\n(src/hooks/)"]:::frontend
        Utils["Utility Functions\n(src/lib/utils.ts)"]:::frontend
        Middleware["Next.js Middleware\n(src/middleware.ts)"]:::frontend
    end

    %% API Layer
    ConvexClientSDK["Convex Client SDK"]:::frontend

    %% Backend Layer
    subgraph "Convex Serverless Functions" 
        direction TB
        Schema["Data Model Schema\n(convex/schema.ts)"]:::backend
        AuthConfig["Auth Config\n(convex/auth.config.ts)"]:::backend
        AuthLogic["Authentication Logic\n(convex/auth.ts)"]:::backend
        HTTPEndpoints["HTTP Endpoints\n(convex/http.ts)"]:::backend
        subgraph "Server Functions"
            direction TB
            UsersFunc["Users\n(convex/users.ts)"]:::backend
            WorkspacesFunc["Workspaces\n(convex/workspaces.ts)"]:::backend
            ChannelsFunc["Channels\n(convex/channels.ts)"]:::backend
            ConversationsFunc["Conversations\n(convex/conversations.ts)"]:::backend
            MembersFunc["Members\n(convex/members.ts)"]:::backend
            MessagesFunc["Messages\n(convex/messages.ts)"]:::backend
            ReactionsFunc["Reactions\n(convex/reactions.ts)"]:::backend
            UploadFunc["File Uploads\n(convex/upload.ts)"]:::backend
        end
        GeneratedAPI["API Types\n(convex/_generated/api.d.ts)"]:::backend
        GeneratedServer["Server Definitions\n(convex/_generated/server.d.ts)"]:::backend
    end

    %% Persistence Layer
    Database["Convex Database"]:::persistence

    %% External Services
    Vercel["Vercel / CDN"]:::external
    Storage["External Storage (S3)"]:::external

    %% Connections
    Browser -->|"HTTPS"| NextjsApp
    NextjsApp --> UI
    NextjsApp --> ConvexClientProvider
    NextjsApp --> JotaiProvider
    NextjsApp --> AuthFeature
    NextjsApp --> WorkspacesFeature
    NextjsApp --> ChannelsFeature
    NextjsApp --> ConversationsFeature
    NextjsApp --> MembersFeature
    NextjsApp --> MessagesFeature
    NextjsApp --> ReactionFeature
    NextjsApp --> UploadFeature
    NextjsApp --> Hooks
    NextjsApp --> Utils
    NextjsApp --> Middleware
    NextjsApp --> Vercel

    ConvexClientProvider --> ConvexClientSDK
    JotaiProvider --> ConvexClientSDK
    ConvexClientSDK -->|"convex.query / mutation"| UsersFunc
    ConvexClientSDK -->|"convex.query / mutation"| WorkspacesFunc
    ConvexClientSDK -->|"convex.query / mutation"| ChannelsFunc
    ConvexClientSDK -->|"convex.query / mutation"| ConversationsFunc
    ConvexClientSDK -->|"convex.query / mutation"| MembersFunc
    ConvexClientSDK -->|"convex.query / mutation"| MessagesFunc
    ConvexClientSDK -->|"convex.query / mutation"| ReactionsFunc
    ConvexClientSDK -->|"convex.http POST"| UploadFunc
    ConvexClientSDK -->|"auth flow"| AuthLogic

    UsersFunc --> Database
    WorkspacesFunc --> Database
    ChannelsFunc --> Database
    ConversationsFunc --> Database
    MembersFunc --> Database
    MessagesFunc --> Database
    ReactionsFunc --> Database
    UploadFunc --> Database
    HTTPEndpoints --> Database
    AuthLogic --> Database

    UploadFunc -->|"direct upload"| Storage

    Middleware --> AuthLogic
    Middleware --> AuthConfig

    %% Click Events
    click NextjsApp "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/app/"
    click UI "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/components/ui/"
    click ConvexClientProvider "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/src/components/ConvexClientProvider.tsx"
    click JotaiProvider "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/src/components/JotaiProvider.tsx"
    click AuthFeature "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/features/auth/"
    click WorkspacesFeature "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/features/workspaces/"
    click ChannelsFeature "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/features/channels/"
    click ConversationsFeature "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/features/conversations/"
    click MembersFeature "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/features/members/"
    click MessagesFeature "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/features/messages/"
    click ReactionFeature "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/features/reaction/"
    click UploadFeature "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/features/upload/"
    click Hooks "https://github.com/mohamedhabibfrigui/slack-clone/tree/main/src/hooks/"
    click Utils "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/src/lib/utils.ts"
    click Middleware "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/src/middleware.ts"
    click Schema "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/schema.ts"
    click AuthConfig "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/auth.config.ts"
    click AuthLogic "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/auth.ts"
    click HTTPEndpoints "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/http.ts"
    click UsersFunc "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/users.ts"
    click WorkspacesFunc "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/workspaces.ts"
    click ChannelsFunc "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/channels.ts"
    click ConversationsFunc "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/conversations.ts"
    click MembersFunc "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/members.ts"
    click MessagesFunc "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/messages.ts"
    click ReactionsFunc "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/reactions.ts"
    click UploadFunc "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/upload.ts"
    click GeneratedAPI "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/_generated/api.d.ts"
    click GeneratedServer "https://github.com/mohamedhabibfrigui/slack-clone/blob/main/convex/_generated/server.d.ts"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0275d8,stroke-width:1px;
    classDef backend fill:#DFF5D0,stroke:#5cb85c,stroke-width:1px;
    classDef persistence fill:#FFE8B3,stroke:#f0ad4e,stroke-width:1px;
    classDef external fill:#E0E0E0,stroke:#6c757d,stroke-width:1px;
```
