# codercastor/chat-app architecture

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

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

## Overview

##### Project Type and Purpose
- Full-stack web application for authenticated group chats and a user dashboard.
- Frontend: Next.js 13 (app directory), React components, NextAuth.js for authentication.
- Backend: Node.js with Express‐style routing, Prisma ORM, migrations for Users and ChatGroups.

##### File Structure
Top‐Level Directories:
- front/ – Next.js app, assets, UI components, API routes under app/api/auth.
- server/ – REST API, Prisma migrations, controllers, middleware, database config.
Key Patterns and Configs:
- front/app – React pages (page.tsx), layout, global styles, dashboard under app/dashboard.
- front/components – Organized by feature (auth, dashboard, groupChat) and UI primitives.
- server/src/controllers & routes – MVC‐style controllers for Auth and ChatGroup.
- server/src/Middlewares – JWT/session auth enforcement.
- server/prisma/schema.prisma + migrations → relational DB (e.g., PostgreSQL).

##### README for Additional Context
- The README is minimal (“codercastor”), implying the architecture isn’t documented yet. Use the file layout to infer responsibilities.

##### Main Components & Their Interactions
a. Frontend (Next.js App)
– Pages: Landing, Login (via NextAuth), Dashboard, GroupChat management.
– Components: UI library (buttons, dialogs), feature components (CreateChat, GroupChatCard).
– API Routes: /api/auth/[...nextauth] → NextAuth adapter for session tokens.
b. Backend (Express‐style API)
– AuthController → login, signup, token issuance.
– ChatGroupController → CRUD endpoints for chat groups.
– Middlewares → Securing routes, parsing JWT or session.
c. Database
– Managed via Prisma ORM; schema defines User and ChatGroup tables.
– Migrations folder documents evolution of schema.
d. External Services
– OAuth providers (GitHub/Google) proxied through NextAuth.
– Potential hosting/CDN for static assets (Vercel/Netlify).

##### Relationships & Data Flows
- Browser ↔ Next.js Server (SSR/data fetching on page load).
- Frontend API calls (fetch/groupFetch.ts) → Backend REST endpoints (e.g., POST /chatgroups).
- Backend ORM (Prisma) → Database for reads/writes.
- NextAuth session cookie or JWT stored in browser, passed with each request to secure routes.

##### Architectural Patterns & Design Principles
- Separation of Concerns: UI, business logic (controllers), and data layer (Prisma).
- MVC‐style on backend; feature‐based component organization on frontend.
- API Layer: clear boundary between frontend and backend via REST.

##### Detail
- Don’t omit the API‐layer or Prisma sub‐layer.
- Middleware as part of the request pipeline.
- Environment/config files (e.g., .env for DB credentials, next.config.ts).
- SSR/data‐fetch path in Next.js (page.tsx → getServerSideProps or fetch in React).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Next.js Frontend"
        direction TB
        FrontApp["App Directory"]:::frontend
        AuthRoute["NextAuth API Route"]:::frontend
        PagesLanding["Landing & Main Pages"]:::frontend
        LayoutStyles["Global Layout & Styles"]:::frontend
        DashboardPage["Dashboard Page"]:::frontend
        NextAuthTypes["NextAuth Types Config"]:::frontend
        SessionProvider["Session Provider"]:::frontend
        AuthComponents["Auth Components"]:::frontend
        BaseUI["Base UI Components"]:::frontend
        DashboardUI["Dashboard UI Component"]:::frontend
        GroupChatComponents["Group Chat Components"]:::frontend
        CommonUI["Common & UI Primitives"]:::frontend
        FetchModule["Client-side Fetch Module"]:::frontend
        APIEndpoints["API Endpoints Constants"]:::frontend
        EnvConfig["Env Config"]:::frontend
        Validations["Input Validations"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend API" 
        direction TB
        EntryPoint["Entry Point & Routes Setup"]:::backend
        AuthMiddleware["Authentication Middleware"]:::backend
        AuthCtrl["AuthController"]:::backend
        ChatCtrl["ChatGroupController"]:::backend
        DBConfig["Database Config"]:::backend
        Prisma["Prisma ORM"]:::backend
    end

    %% External & Database
    OAuth(["OAuth Providers"]):::external
    Database[(PostgreSQL DB)]:::db

    %% Data Flows
    Browser(["Browser"]):::external --> FrontApp
    FrontApp -->|SSR / Data Fetch| FetchModule
    FrontApp -->|Auth Calls| AuthRoute
    FrontApp -->|UI Rendering| PagesLanding
    FrontApp -->|Layout & Styles| LayoutStyles
    FrontApp -->|Dashboard View| DashboardPage
    FrontApp -->|Session Context| SessionProvider

    FetchModule -->|REST Calls| EntryPoint
    AuthRoute -->|Token Exchange| EntryPoint
    EntryPoint -->|use Auth| AuthMiddleware
    EntryPoint -->|route to| AuthCtrl
    EntryPoint -->|route to| ChatCtrl

    AuthCtrl -->|DB Ops| DBConfig
    ChatCtrl -->|DB Ops| DBConfig
    DBConfig -->|ORM Layer| Prisma
    Prisma -->|SQL Queries| Database

    SessionProvider -->|OAuth Flow| OAuth
    AuthRoute -->|Redirect| OAuth

    %% Click Events
    click FrontApp "https://github.com/codercastor/chat-app/tree/main/front/app"
    click AuthRoute "https://github.com/codercastor/chat-app/blob/main/front/app/api/auth/[...nextauth]/route.ts"
    click PagesLanding "https://github.com/codercastor/chat-app/blob/main/front/app/page.tsx"
    click LayoutStyles "https://github.com/codercastor/chat-app/blob/main/front/app/layout.tsx"
    click LayoutStyles "https://github.com/codercastor/chat-app/blob/main/front/app/globals.css"
    click DashboardPage "https://github.com/codercastor/chat-app/blob/main/front/app/dashboard/page.tsx"
    click NextAuthTypes "https://github.com/codercastor/chat-app/blob/main/front/next-auth.d.ts"
    click SessionProvider "https://github.com/codercastor/chat-app/blob/main/front/providers/SessionProvider.tsx"
    click AuthComponents "https://github.com/codercastor/chat-app/tree/main/front/components/auth"
    click BaseUI "https://github.com/codercastor/chat-app/tree/main/front/components/base"
    click DashboardUI "https://github.com/codercastor/chat-app/blob/main/front/components/dashboard/DashNav.tsx"
    click GroupChatComponents "https://github.com/codercastor/chat-app/tree/main/front/components/groupChat"
    click CommonUI "https://github.com/codercastor/chat-app/blob/main/front/components/common/UserAvatar.tsx"
    click FetchModule "https://github.com/codercastor/chat-app/blob/main/front/fetch/groupFetch.ts"
    click APIEndpoints "https://github.com/codercastor/chat-app/blob/main/front/lib/apiEndPoints.ts"
    click EnvConfig "https://github.com/codercastor/chat-app/blob/main/front/lib/env.ts"
    click EnvConfig "https://github.com/codercastor/chat-app/blob/main/front/next.config.ts"
    click Validations "https://github.com/codercastor/chat-app/blob/main/front/validations/groupChatValidation.ts"
    click EntryPoint "https://github.com/codercastor/chat-app/blob/main/server/src/index.ts"
    click EntryPoint "https://github.com/codercastor/chat-app/blob/main/server/src/routes/index.ts"
    click AuthMiddleware "https://github.com/codercastor/chat-app/blob/main/server/src/Middlewares/AuthMiddleware.ts"
    click AuthCtrl "https://github.com/codercastor/chat-app/blob/main/server/src/controllers/AuthController.ts"
    click ChatCtrl "https://github.com/codercastor/chat-app/blob/main/server/src/controllers/ChatGroupController.ts"
    click DBConfig "https://github.com/codercastor/chat-app/blob/main/server/src/config/db.config.ts"
    click Prisma "https://github.com/codercastor/chat-app/blob/main/server/prisma/schema.prisma"
    click Database "https://github.com/codercastor/chat-app/blob/main/server/prisma/migrations/20251118073644_users/migration.sql"
    click Database "https://github.com/codercastor/chat-app/blob/main/server/prisma/migrations/20251119044410_chatgroups/migration.sql"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#1e88e5,stroke-width:1px
    classDef backend fill:#c8e6c9,stroke:#43a047,stroke-width:1px
    classDef db fill:#ffe0b2,stroke:#fb8c00,stroke-width:1px
    classDef external fill:#ffe082,stroke:#fdd835,stroke-width:1px
```
