# reda-trouki/chat-app architecture

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

- Interactive diagram: https://gitdiagram.com/reda-trouki/chat-app
- Repository: https://github.com/reda-trouki/chat-app

## Overview

##### Project type and purpose
- This is a full-stack real-time chat application built with Next.js (App Router) on the front end and Convex as a backend-as-a-service (data store + serverless functions).
- The README confirms it’s a Next.js project; the `convex/` folder contains all backend logic (data schema, API functions, authentication config).

##### File structure
- Top-level directories:
- `app/` – Next.js App Router routes and layouts
- `components/` – Shared UI building blocks
- `convex/` – Backend functions, schema, generated API
- `public/` – Static assets
- `src/hooks`, `src/lib`, `src/providers` – Client-side logic, utilities, and context providers
- Key config files:
- `next.config.mjs`, `postcss.config.mjs`, `tailwind.config.ts` – Build & styling
- `tsconfig.json`, `.eslintrc.json` – TypeScript and linting
- Patterns & frameworks: React component hierarchy, custom hooks, Convex’s data-model plus query/mutation functions.

##### README for additional insights
- Confirms basic Next.js setup & dev workflow.

##### Detailed guidance
- Global layout & navigation (sidebar, header)
- Conversations list and conversation detail view
- Chat input and message list components
- Inside the backend segment, show how each Convex function maps to a use-case:
- `conversations.ts` ↔ fetch or create conversation
- `messages.ts` ↔ send & fetch messages
- `friends.ts` / `requests.ts` ↔ friend management
- Shared utilities (e.g., `src/lib/utils.ts`, `src/hooks/useNavigation`) if they coordinate cross-component logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Infrastructure
    subgraph "External Infrastructure"
        Vercel("Vercel CDN"):::external
        GoogleFonts("Google Fonts CDN"):::external
    end

    %% Frontend Layer
    subgraph "Frontend: Client & Next.js"
        direction TB
        AppRouter["Next.js App Router"]:::frontend
        Layout["Global Layout & Navigation"]:::frontend
        Provider["ConvexClientProvider"]:::frontend

        subgraph "Pages"
            direction TB
            ConversationsList["Conversations List Page"]:::frontend
            ConversationDetail["Conversation Detail Page"]:::frontend
            FriendsList["Friends List Page"]:::frontend
        end

        subgraph "Components"
            direction TB
            Sidebar["Sidebar Navigation UI"]:::frontend
            DMItem["DM Conversation Item"]:::frontend
            GroupItem["Group Conversation Item"]:::frontend
            Header["Conversation Header Component"]:::frontend
            Body["Message List Body"]:::frontend
            Message["Individual Message"]:::frontend
            ChatInput["Chat Input"]:::frontend
            AddFriendDialog["Add Friend Dialog"]:::frontend
            FriendRequest["Friend Request Item"]:::frontend
        end

        subgraph "Hooks & Utilities"
            direction TB
            useConv["useConversation Hook"]:::frontend
            useMut["useMutationState Hook"]:::frontend
            useNav["useNavigation Hook"]:::frontend
            Utils["Utility Functions"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend: Convex BaaS"
        direction TB
        Schema["Schema Definition"]:::backend
        AuthCfg["Auth Configuration"]:::backend

        subgraph "Server Functions"
            direction TB
            convs["conversations.ts"]:::backend
            conv["conversation.ts"]:::backend
            msgs["messages.ts"]:::backend
            msg["message.ts"]:::backend
            friendsFns["friends.ts"]:::backend
            friendFn["friend.ts"]:::backend
            requestsFns["requests.ts"]:::backend
            requestFn["request.ts"]:::backend
            userFn["user.ts"]:::backend
        end

        subgraph "Generated API & Models"
            direction TB
            APIClient["API Client Definitions"]:::backend
            DataModel["Data Model Types"]:::backend
        end

        HTTPUtil["HTTP Utilities"]:::backend
        DB["Convex Database"]:::database
    end

    %% Connections
    Vercel --> AppRouter
    GoogleFonts -.-> Sidebar
    AppRouter --> Layout
    Layout --> Sidebar
    Layout --> Provider
    Provider --> ConversationsList
    Provider --> ConversationDetail
    Provider --> FriendsList

    ConversationsList --> DMItem
    ConversationsList --> GroupItem
    ConversationDetail --> Header
    ConversationDetail --> Body
    Body --> Message
    ConversationDetail --> ChatInput
    FriendsList --> AddFriendDialog
    FriendsList --> FriendRequest

    ConversationsList --> useConv
    ConversationDetail --> useConv
    ChatInput --> useMut
    Layout --> useNav
    Layout --> Utils

    Provider --> HTTPUtil
    HTTPUtil --> APIClient
    APIClient --> convs
    APIClient --> msgs
    APIClient --> friendsFns
    APIClient --> requestsFns
    convs --> DB
    conv --> DB
    msgs --> DB
    msg --> DB
    friendsFns --> DB
    friendFn --> DB
    requestsFns --> DB
    requestFn --> DB
    userFn --> DB

    DB -->|real-time update| useConv
    useConv --> ConversationDetail

    %% Click Events
    click AppRouter "https://github.com/reda-trouki/chat-app/tree/main/src/app"
    click Layout "https://github.com/reda-trouki/chat-app/blob/main/src/app/layout.tsx"
    click ConversationsList "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/conversations/page.tsx"
    click ConversationDetail "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/conversations/[conversationId]/page.tsx"
    click Header "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/conversations/[conversationId]/_components/Header.tsx"
    click Body "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/conversations/[conversationId]/_components/body/Body.tsx"
    click Message "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/conversations/[conversationId]/_components/body/Message.tsx"
    click ChatInput "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/conversations/[conversationId]/_components/input/ChatInput.tsx"
    click DMItem "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/conversations/_components/DMConversationItem.tsx"
    click GroupItem "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/conversations/_components/GroupConversationItem.tsx"
    click FriendsList "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/friends/page.tsx"
    click AddFriendDialog "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/friends/_components/AddFriendDialog.tsx"
    click FriendRequest "https://github.com/reda-trouki/chat-app/blob/main/src/app/(root)/friends/_components/Request.tsx"
    click Sidebar "https://github.com/reda-trouki/chat-app/tree/main/src/components/shared/sidebar/nav"
    click Utils "https://github.com/reda-trouki/chat-app/blob/main/src/lib/utils.ts"
    click useConv "https://github.com/reda-trouki/chat-app/blob/main/src/hooks/useConversation.tsx"
    click useMut "https://github.com/reda-trouki/chat-app/blob/main/src/hooks/useMutationState.tsx"
    click useNav "https://github.com/reda-trouki/chat-app/blob/main/src/hooks/useNavigation.tsx"
    click Provider "https://github.com/reda-trouki/chat-app/blob/main/src/providers/ConvexClientProvider.tsx"
    click Schema "https://github.com/reda-trouki/chat-app/blob/main/convex/schema.ts"
    click AuthCfg "https://github.com/reda-trouki/chat-app/blob/main/convex/auth.config.ts"
    click convs "https://github.com/reda-trouki/chat-app/blob/main/convex/conversations.ts"
    click conv "https://github.com/reda-trouki/chat-app/blob/main/convex/conversation.ts"
    click msgs "https://github.com/reda-trouki/chat-app/blob/main/convex/messages.ts"
    click msg "https://github.com/reda-trouki/chat-app/blob/main/convex/message.ts"
    click friendsFns "https://github.com/reda-trouki/chat-app/blob/main/convex/friends.ts"
    click friendFn "https://github.com/reda-trouki/chat-app/blob/main/convex/friend.ts"
    click requestsFns "https://github.com/reda-trouki/chat-app/blob/main/convex/requests.ts"
    click requestFn "https://github.com/reda-trouki/chat-app/blob/main/convex/request.ts"
    click userFn "https://github.com/reda-trouki/chat-app/blob/main/convex/user.ts"
    click APIClient "https://github.com/reda-trouki/chat-app/blob/main/convex/_generated/api.js"
    click DataModel "https://github.com/reda-trouki/chat-app/blob/main/convex/_generated/dataModel.d.ts"
    click HTTPUtil "https://github.com/reda-trouki/chat-app/blob/main/convex/http.ts"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#3498DB,stroke-width:1px
    classDef backend fill:#FDEBD0,stroke:#E67E22,stroke-width:1px
    classDef database fill:#D5F5E3,stroke:#27AE60,stroke-width:1px
    classDef external fill:#F5B7B1,stroke:#C0392B,stroke-width:1px
```
