# dishit7/team-chat-app architecture

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

- Interactive diagram: https://gitdiagram.com/dishit7/team-chat-app
- Repository: https://github.com/dishit7/team-chat-app

## Overview

##### Project type and purpose
- This is a full-stack, real-time chat application built with Next.js 13+ (App Router).
- Key features: user authentication, server and channel management, direct messaging, file uploads, and real-time chat via WebSockets (Socket.IO).
- Data persistence via Prisma ORM and a relational database (PostgreSQL or similar). File storage through Uploadthing.

##### File structure
- Top-level directories:
- app/ – Next.js App Router. Contains nested layouts and route-handlers for pages under auth, invite, setup, main.
- app/api/ – Route handlers for RESTful operations (servers, channels, members, upload).
- pages/api/socket/ – Socket.IO endpoints for real-time messaging (directmessages, messages, io).
- components/ – React UI components organized by feature (chat, modals, navigation, ui primitives).
- hooks/ – Custom React hooks for sockets, queries, modals, origin.
- lib/ – Server-side utilities: Prisma client (db.ts), conversation and profile helpers, uploadthing config.
- prisma/ – Database schema and migration history.
- providers/ – React context providers: modal, React Query, socket.
- Config and build files: next.config.mjs, tsconfig.json, tailwind.config.ts, middleware.ts.

##### README
- Confirms Next.js bootstrap, development commands, font optimization.

##### Detail
- Sub-components where necessary (e.g., within Browser UI, show Providers layer and feature UIs).
- Avoid over-simplification: capture both REST and real-time flows, plus file and auth integrations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser UI
    subgraph "Browser UI"
        direction TB
        Providers["Providers\n(modal, query, socket)"]:::frontend
        AppRouter["App Router\napp/layout.tsx"]:::frontend
        UIComponents["UI Components"]:::frontend
    end

    %% Serverless Layer
    subgraph "Next.js Serverless Layer"
        direction TB

        subgraph "App Router & Routes"
            direction TB
            AuthPages["Auth Pages\napp/(auth)"]:::server
            InvitePages["Invite Pages\napp/(invite)"]:::server
            SetupPage["Setup Page\napp/(setup)/page.tsx"]:::server
            MainLayout["Main Layout\napp/(main)/layout.tsx"]:::server
            ServerLayout["Server Layout\napp/(main)/(routes)/servers/[serverId]/layout.tsx"]:::server
        end

        subgraph "REST API Routes"
            direction TB
            ServersAPI["Servers API\napp/api/servers"]:::server
            MembersAPI["Members API\napp/api/members/[memberId]/route.ts"]:::server
            UploadAPI["Upload API\napp/api/uploadthing"]:::server
        end

        subgraph "Socket.IO Endpoints"
            direction TB
            IOEndpoint["Socket.IO IO\npages/api/socket/io.ts"]:::server
            MessagesSocket["Messages Socket\npages/api/socket/messages.ts"]:::server
            DirectSocket["Direct Msg Socket\npages/api/socket/directmessages.ts"]:::server
        end
    end

    %% External Services
    AuthService["Auth Service\nmiddleware.ts"]:::external
    FileStorage["Uploadthing\nlib/uploadthing.ts"]:::external

    %% Database
    DB["Prisma DB\nprisma/schema.prisma"]:::data

    %% Connections
    AppRouter -->|"REST calls"| ServersAPI
    AppRouter -->|"REST calls"| MembersAPI
    AppRouter -->|"REST calls"| UploadAPI
    AppRouter -->|"WebSocket handshake"| IOEndpoint

    ServersAPI -->|"Prisma queries"| DB
    MembersAPI -->|"Prisma queries"| DB

    UploadAPI -->|"stores files"| FileStorage

    AuthService -->|"auth check"| ServersAPI
    AuthService -->|"auth check"| MembersAPI
    AuthService -->|"auth check"| UploadAPI
    AuthService -->|"auth check"| IOEndpoint

    %% Click Events
    click Providers "https://github.com/dishit7/team-chat-app/blob/main/providers/modal-provider.tsx"
    click Providers "https://github.com/dishit7/team-chat-app/blob/main/providers/query-provider.tsx"
    click Providers "https://github.com/dishit7/team-chat-app/blob/main/providers/socket-provider.tsx"
    click AppRouter "https://github.com/dishit7/team-chat-app/blob/main/app/layout.tsx"
    click UIComponents "https://github.com/dishit7/team-chat-app/tree/main/components/"

    click AuthPages "https://github.com/dishit7/team-chat-app/tree/main/app/(auth)"
    click InvitePages "https://github.com/dishit7/team-chat-app/tree/main/app/(invite)"
    click SetupPage "https://github.com/dishit7/team-chat-app/blob/main/app/(setup)/page.tsx"
    click MainLayout "https://github.com/dishit7/team-chat-app/blob/main/app/(main)/layout.tsx"
    click ServerLayout "https://github.com/dishit7/team-chat-app/blob/main/app/(main)/(routes)/servers/[serverId]/layout.tsx"

    click ServersAPI "https://github.com/dishit7/team-chat-app/blob/main/app/api/servers/route.ts"
    click MembersAPI "https://github.com/dishit7/team-chat-app/blob/main/app/api/members/[memberId]/route.ts"
    click UploadAPI "https://github.com/dishit7/team-chat-app/blob/main/app/api/uploadthing/route.ts"
    click UploadAPI "https://github.com/dishit7/team-chat-app/blob/main/app/api/uploadthing/core.ts"

    click IOEndpoint "https://github.com/dishit7/team-chat-app/blob/main/pages/api/socket/io.ts"
    click MessagesSocket "https://github.com/dishit7/team-chat-app/blob/main/pages/api/socket/messages.ts"
    click DirectSocket "https://github.com/dishit7/team-chat-app/blob/main/pages/api/socket/directmessages.ts"

    click AuthService "https://github.com/dishit7/team-chat-app/blob/main/middleware.ts"
    click FileStorage "https://github.com/dishit7/team-chat-app/blob/main/lib/uploadthing.ts"
    click DB "https://github.com/dishit7/team-chat-app/blob/main/prisma/schema.prisma"
    click DB "https://github.com/dishit7/team-chat-app/blob/main/lib/db.ts"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#02457A,stroke-width:1px
    classDef server fill:#E0F7E9,stroke:#027A48,stroke-width:1px
    classDef data fill:#FFE7C1,stroke:#A65E00,stroke-width:1px
    classDef external fill:#F3E5F5,stroke:#6A1B9A,stroke-width:1px
```
