# mohd-kaif-dev/chatteristic-next architecture

> Architecture diagram of the GitHub repository mohd-kaif-dev/chatteristic-next, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohd-kaif-dev/chatteristic-next
- Repository: https://github.com/mohd-kaif-dev/chatteristic-next

## Overview

##### Project Type and Purpose
- This is a Next.js full-stack web application (bootstrapped with create-next-app) that implements social features: users, profiles, posts, notifications, and image uploads.
- It uses React Server Components (the `/src/app` folder and client/server boundary), Prisma as an ORM for a relational database, and Uploadthing for file storage.

##### File Structure Analysis
- Top-level config files: `next.config.mjs`, `tsconfig.json`, `tailwind.config.ts`, `postcss.config.mjs`
- `prisma/schema.prisma`: database schema
- `src/lib/`: helper modules (Prisma client, upload utilities, general utils)
- `src/app/`: Next.js App Router routes and layouts
- `/api/uploadthing/*`: serverless upload endpoints
- `/page.tsx`, `/layout.tsx`, `/notifications`, `/profile/[username]`
- `src/actions/`: Domain-specific business logic (posts, users, profiles, notifications)
- `src/components/`: Reusable UI components, including the `/ui` subfolder for primitive controls

##### Key Architectural Patterns
- Frontend/Server-side convergence via Next.js App Router
- React Server Components and Client Components coexistence
- Single service boundary (Vercel serverless functions) for all `/app/api/*` routes
- Prisma ORM interacting with a Postgres/MySQL/SQLite database
- External file storage via Uploadthing (likely backed by S3 or similar)

##### Main Components
a. Client Layer (Browser)
- React components (Next.js pages and client components)
- HTTP/HTTPS requests to Next.js serverless API routes
b. Next.js Application Layer
- App Router
- Server Components (data fetching, Prisma calls)
- Client Components (interactive UI)
- API Routes (uploadthing, any other `/api/*` routes)
- Business Logic (`src/actions/*`)
c. Persistence Layer
- Prisma ORM
- Relational Database (Postgres/MySQL/SQLite)
d. External Services
- Uploadthing service (and underlying storage like S3)
- Vercel (deployment, CDN)

##### Relationships and Data Flows
- Browser → Next.js frontend (SSR/SSG/ISR)
- Browser → API routes (file uploads, JSON actions)
- Next.js Server Components / API handlers → Prisma client → Database
- API route (Uploadthing) ↔ External storage (S3)
- Vercel hosting + CDN in front of Next.js

##### Architectural Patterns & Design Principles
- Separation of Concerns: Presentation (components) vs. Business Logic (`actions`) vs. Data Access (Prisma)
- API-driven development: All side effects (file upload, CRUD) surface via API routes or server actions
- Serverless deployment: Each API route runs in an isolated function
- React Server Components optimize data fetching on the server

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer" 
        direction TB
        Browser["Browser (HTTP Requests)"]:::client
        subgraph "React UI"
            direction TB
            HomePage["Home Page (/src/app/page.tsx)"]:::client
            NotificationsPage["Notifications Page (/src/app/notifications/page.tsx)"]:::client
            ProfilePage["Profile Page (/src/app/profile/[username]/page.tsx)"]:::client
            ProfileClient["ProfilePageClient (/src/app/profile/[username]/ProfilePageClient.tsx)"]:::client
            UserCard["UserCard Component (/src/app/profile/[username]/UserCard.tsx)"]:::client
            UIComponents["UI Library (/src/components)"]:::client
            PrimitiveUI["Primitive UI Library (/src/components/ui)"]:::client
        end
    end

    %% Server Layer
    subgraph "Next.js Server" 
        direction TB
        AppRouter["App Router (/src/app)"]:::server
        Layout["Global Layout (/src/app/layout.tsx)"]:::server
        GlobalsCSS["Global Styles (/src/app/globals.css)"]:::server
        Middleware["Global Middleware (/src/middleware.ts)"]:::server

        subgraph "API Routes (Uploadthing)"
            direction TB
            UploadCore["Upload Core Logic (/src/app/api/uploadthing/core.ts)"]:::server
            UploadRoute["Upload Route Handler (/src/app/api/uploadthing/route.ts)"]:::server
        end

        subgraph "Business Logic Actions"
            direction TB
            NotificationAction["Notifications Action (/src/actions/notification.action.ts)"]:::server
            PostAction["Posts Action (/src/actions/post.action.ts)"]:::server
            ProfileAction["Profiles Action (/src/actions/profile.action.ts)"]:::server
            UserAction["Users Action (/src/actions/user.action.ts)"]:::server
        end

        subgraph "Lib Utilities"
            direction TB
            PrismaClient["Prisma Client (/src/lib/prisma.ts)"]:::server
            UploadUtils["Upload Utilities (/src/lib/uploadthing.ts)"]:::server
            Utils["General Utilities (/src/lib/utils.ts)"]:::server
        end

        ConfigNext["next.config.mjs"]:::server
        ConfigTS["tsconfig.json"]:::server
        ConfigTailwind["tailwind.config.ts"]:::server
        ConfigPostCSS["postcss.config.mjs"]:::server
    end

    %% Database Layer
    subgraph "Database Layer"
        direction TB
        SchemaPrisma["Schema Definition (prisma/schema.prisma)"]:::db
        Database["Relational Database"]:::db
    end

    %% External Services
    subgraph "External Services"
        direction TB
        UploadService["Uploadthing/S3 Storage"]:::ext
        Vercel["Vercel Hosting & CDN"]:::ext
    end

    %% Connections
    Browser -->|"HTTP GET / POST"| AppRouter
    Browser -->|"Fetch /api/uploadthing"| UploadRoute
    AppRouter -->|"Renders Server Components"| HomePage
    AppRouter -->|"Renders Server Components"| NotificationsPage
    AppRouter -->|"Renders Server Components"| ProfilePage
    ProfilePage -->|"Uses Client Component"| ProfileClient
    ProfileClient -->|"Imports"| UserCard
    HomePage -->|"<Client Components>"| UIComponents
    NotificationsPage -->|"<Client Components>"| UIComponents
    UIComponents -->|"<Primitives>"| PrimitiveUI

    AppRouter -->|"<Middleware>"| Middleware
    UploadRoute -->|"<Invokes>"| UploadCore
    UploadCore -->|"multipart/form-data"| UploadService
    UploadRoute -->|"<Server Action>"| PostAction
    PostAction -->|"<DB Query>"| PrismaClient
    ProfileAction -->|"<DB Query>"| PrismaClient
    NotificationAction -->|"<DB Query>"| PrismaClient
    UserAction -->|"<DB Query>"| PrismaClient
    PrismaClient -->|"SQL Queries"| Database

    Vercel -->|"<Hosts>"| AppRouter
    Vercel -->|"<CDN Caching>"| Browser

    %% Click Events
    click AppRouter "https://github.com/mohd-kaif-dev/chatteristic-next/tree/main/src/app"
    click HomePage "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/app/page.tsx"
    click NotificationsPage "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/app/notifications/page.tsx"
    click ProfilePage "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/app/profile/[username]/page.tsx"
    click ProfileClient "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/app/profile/[username]/ProfilePageClient.tsx"
    click UserCard "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/app/profile/[username]/UserCard.tsx"
    click Layout "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/app/layout.tsx"
    click GlobalsCSS "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/app/globals.css"
    click UploadCore "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/app/api/uploadthing/core.ts"
    click UploadRoute "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/app/api/uploadthing/route.ts"
    click NotificationAction "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/actions/notification.action.ts"
    click PostAction "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/actions/post.action.ts"
    click ProfileAction "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/actions/profile.action.ts"
    click UserAction "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/actions/user.action.ts"
    click PrismaClient "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/lib/prisma.ts"
    click SchemaPrisma "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/prisma/schema.prisma"
    click UploadUtils "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/lib/uploadthing.ts"
    click Utils "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/lib/utils.ts"
    click UIComponents "https://github.com/mohd-kaif-dev/chatteristic-next/tree/main/src/components"
    click PrimitiveUI "https://github.com/mohd-kaif-dev/chatteristic-next/tree/main/src/components/ui"
    click Middleware "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/src/middleware.ts"
    click ConfigNext "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/next.config.mjs"
    click ConfigTS "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/tsconfig.json"
    click ConfigTailwind "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/tailwind.config.ts"
    click ConfigPostCSS "https://github.com/mohd-kaif-dev/chatteristic-next/blob/main/postcss.config.mjs"

    %% Styles
    classDef client fill:#bbdefb,stroke:#0d47a1,stroke-width:1px
    classDef server fill:#ffcc80,stroke:#e65100,stroke-width:1px
    classDef db fill:#c8e6c9,stroke:#1b5e20,stroke-width:1px
    classDef ext fill:#eceff1,stroke:#546e7a,stroke-width:1px
```
