# rohanshrma222/scalable-chat-app architecture

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

- Interactive diagram: https://gitdiagram.com/rohanshrma222/scalable-chat-app
- Repository: https://github.com/rohanshrma222/scalable-chat-app

## Overview

##### Project type and purpose
- This is a monorepo (Turborepo) hosting a full-stack TypeScript application.
- It comprises two primary “apps” under `apps/`:
- **server**: a Node/TypeScript backend, using Kafka for messaging and WebSockets for real-time communication.
- **web**: a Next.js frontend.
- It also includes shared “packages” under `packages/` for database access (`db` with Prisma), UI components (`ui`), ESLint configs, and TypeScript configs.

##### File structure
- Top level:
- `docker-compose.yml` for orchestrating local services (Postgres, Kafka, etc.)
- `pnpm-workspace.yaml` & `turbo.json` for Turborepo configuration
- apps/server:
- `src/index.ts`—entry point for HTTP/WebSocket server
- `src/services/kafka.ts`—Kafka producer/consumer setup
- `src/services/socket.ts`—WebSocket server logic
- apps/web:
- Next.js app in `app/` folder with React components and global styles
- `context/SocketProvider.tsx`—wraps app with WebSocket client logic
- packages/db:
- Prisma schema & generated client for database ORM
- packages/ui:
- Reusable React components (Button, Card, Code)
- packages/eslint-config & packages/typescript-config:
- Centralized linting and TS compiler settings

##### Key architecture insights from README & files
- Monorepo using Turborepo’s task pipeline and caching
- Shared code is pulled via workspace imports (e.g., `@repo/ui`, `@repo/db`)
- Docker Compose bootstraps supporting services (Postgres, Kafka) for both apps

##### Detail
- Package directory as a component if it contains runtime logic (e.g., `packages/db` → representing Prisma).
- How `docker-compose.yml` ties the services together in local dev.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend" 
        direction TB
        NextApp["Next.js App"]:::frontend
        Layout["Layout & Pages"]:::frontend
        SocketProv["WebSocket Client (SocketProvider)"]:::frontend
        ConfigFE["Next.js & ESLint Config"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        direction TB
        Entry["Server Entry Point"]:::backend
        KafkaSvc["Kafka Service"]:::backend
        SocketSvc["WebSocket Service"]:::backend
        TSConfigBE["TypeScript Config"]:::backend
    end

    %% Shared Packages
    subgraph "Shared Packages"
        direction TB
        DBPkg["DB (Prisma Client)"]:::shared
        PrismaSchema["Prisma Schema & Migrations"]:::shared
        PrismaGen["Generated Prisma Client"]:::shared
        UIPkg["UI Component Library"]:::shared
        UIConfig["UI Package Config"]:::shared
        ESLintPkg["ESLint Shared Configs"]:::shared
        TSPkg["TypeScript Shared Configs"]:::shared
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        Postgres["PostgreSQL"]:::infra
        KafkaBroker["Kafka Broker"]:::infra
        DockerCompose["Docker Compose"]:::infra
        TurborepoCfg["Turborepo & Workspace Config"]:::infra
        RootPkg["Root package.json"]:::infra
    end

    %% User Interaction
    User["User Browser"]:::external

    %% Connections
    User -->|"HTTPS"| NextApp
    User -->|"WebSocket Handshake"| SocketProv

    NextApp -->|"HTTP REST/GraphQL"| Entry
    NextApp -->|"WebSocket"| SocketSvc

    Entry -->|"Prisma Client"| DBPkg
    DBPkg -->|"SQL"| Postgres

    Entry <-->|"Kafka Produce/Consume"| KafkaBroker
    KafkaSvc -->|uses| KafkaBroker

    %% Shared Imports
    NextApp -->|imports| UIPkg
    NextApp -->|imports| ESLintPkg
    NextApp -->|imports| TSPkg

    Entry -->|imports| DBPkg
    Entry -->|imports| ESLintPkg
    Entry -->|imports| TSPkg

    %% Docker Compose ties services
    DockerCompose --> Postgres
    DockerCompose --> KafkaBroker

    %% Monorepo config
    TurborepoCfg --> NextApp
    TurborepoCfg --> Entry
    TurborepoCfg --> DBPkg
    TurborepoCfg --> UIPkg

    RootPkg -->|defines dependencies| NextApp
    RootPkg -->|defines dependencies| Entry
    RootPkg -->|defines workspaces| DBPkg
    RootPkg -->|defines workspaces| UIPkg

    %% Click Events
    click NextApp "https://github.com/rohanshrma222/scalable-chat-app/tree/main/apps/web"
    click Layout "https://github.com/rohanshrma222/scalable-chat-app/blob/main/apps/web/app/layout.tsx"
    click SocketProv "https://github.com/rohanshrma222/scalable-chat-app/blob/main/apps/web/context/SocketProvider.tsx"
    click ConfigFE "https://github.com/rohanshrma222/scalable-chat-app/blob/main/apps/web/next.config.js"
    click ConfigFE "https://github.com/rohanshrma222/scalable-chat-app/blob/main/apps/web/eslint.config.js"
    click Entry "https://github.com/rohanshrma222/scalable-chat-app/blob/main/apps/server/src/index.ts"
    click KafkaSvc "https://github.com/rohanshrma222/scalable-chat-app/blob/main/apps/server/src/services/kafka.ts"
    click SocketSvc "https://github.com/rohanshrma222/scalable-chat-app/blob/main/apps/server/src/services/socket.ts"
    click TSConfigBE "https://github.com/rohanshrma222/scalable-chat-app/blob/main/apps/server/tsconfig.json"
    click DBPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/db/src/index.ts"
    click PrismaSchema "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/db/prisma/schema.prisma"
    click PrismaSchema "https://github.com/rohanshrma222/scalable-chat-app/tree/main/packages/db/prisma/migrations"
    click PrismaGen "https://github.com/rohanshrma222/scalable-chat-app/tree/main/packages/db/generated/prisma"
    click UIPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/ui/src/button.tsx"
    click UIPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/ui/src/card.tsx"
    click UIPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/ui/src/code.tsx"
    click UIConfig "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/ui/package.json"
    click UIConfig "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/ui/tsconfig.json"
    click ESLintPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/eslint-config/base.js"
    click ESLintPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/eslint-config/next.js"
    click ESLintPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/eslint-config/react-internal.js"
    click TSPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/typescript-config/base.json"
    click TSPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/typescript-config/nextjs.json"
    click TSPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/packages/typescript-config/react-library.json"
    click DockerCompose "https://github.com/rohanshrma222/scalable-chat-app/blob/main/docker-compose.yml"
    click TurborepoCfg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/turbo.json"
    click TurborepoCfg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/pnpm-workspace.yaml"
    click RootPkg "https://github.com/rohanshrma222/scalable-chat-app/blob/main/package.json"

    %% Styles
    classDef frontend fill:#cbeafe,stroke:#1e40af,color:#1e40af
    classDef backend fill:#dcfce7,stroke:#166534,color:#166534
    classDef shared fill:#f3e8ff,stroke:#6b21a8,color:#6b21a8
    classDef infra fill:#fee2e2,stroke:#991b1b,color:#991b1b
    classDef external fill:#e0f2fe,stroke:#0369a1,color:#0369a1
```
