# siddharth7729/vanishchat architecture

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

- Interactive diagram: https://gitdiagram.com/siddharth7729/vanishchat
- Repository: https://github.com/siddharth7729/vanishchat

## Overview

##### Project type and purpose
- This is a full-stack web application using Next.js (App Router) with TypeScript.
- It provides public pages (about, contact), protected user flows (sign-in/up, dashboard, post creation, interactions), and a set of REST-style API routes under `src/app/api`.
- It uses Prisma as ORM to interact with a relational database and Clerk for authentication.

##### File structure
- Top-level directories and files:
- `src/app`: Next.js App Router routes and layouts, split into `(public)`, `(auth)`, `(protected)` segments.
- `src/app/api`: Next.js API route handlers (server-side controllers).
- `src/actions`: business-logic wrappers around queries and mutations.
- `src/components` & `src/components/ui`: reusable React UI components (client- and server-side).
- `src/lib`: shared utilities for API calls and Prisma client initialization.
- `prisma`: schema and migrations defining the database structure.
- `public`: static assets.
- config files: `next.config.ts`, `tailwind.config.ts`, ESLint, TypeScript, PostCSS, etc.
- Patterns:
- App Router with nested layouts.
- Separation of concerns: UI components vs. page layouts vs. API routes vs. data access (Prisma).
- Authentication gating via Clerk in `(auth)` and `(protected)` segments.

##### Insights from README
- Standard Next.js boilerplate.

a. Main components
1. Client (browser) – React components in `src/app/(public)` and `src/app/(protected)`
2. Next.js Server – renders pages (SSR/SSG) and hosts API route handlers
3. Authentication Service – Clerk for sign-in, sign-up, session management
4. Business Logic Layer – `src/actions/*` and `src/app/api/*` that perform queries and mutations
5. Database – PostgreSQL (via Prisma Client defined in `prisma/schema.prisma`)
6. Static Assets – served from `public`
7. Third-party CSS/JS pipeline – Tailwind CSS, PostCSS (build step)

b. Relationships and data flow
- Browser → Next.js Server: page request → Next.js App Router
- Next.js Server ↔ Clerk: authenticate user tokens/session
- Next.js Server (API route) → Business Logic (`src/actions`) → Prisma Client → Database
- Database → Prisma → API → Browser (JSON responses)
- Browser interacts with UI components and calls API routes via fetch/ajax for dynamic data (posts, likes, notifications)

c. Architectural patterns
- App Router (nested layouts) for route composition
- Server Components vs. Client Components distinction
- Layered architecture: Presentation (React), API/controllers, Services/Actions, Data Access (Prisma)
- Authentication gating via folder conventions `(auth)` and `(protected)`

d. Key technologies
- Next.js 13+ (App Router)
- React & TypeScript
- Prisma ORM + PostgreSQL
- Clerk (Authentication)
- Tailwind CSS
- PostCSS, ESLint, TSConfig

##### Final recommendations
- Be highly detailed: break out UI pages (public vs. protected) only if it aids understanding; otherwise group under “Frontend”.
- Folder-based auth gating: a note that all routes under `(protected)` check Clerk session.
- Build/config steps in a sidebar or footnote.
- Avoid over-simplification—include the API layer, business-logic layer (actions), and data-access (Prisma) separately.
- That Prisma migrations live in `prisma/migrations` and that schema changes flow through migration SQL.
- Finally, include any middleware (e.g., `src/middleware.ts`) that may intercept requests for logging or auth enforcement.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Browser (Client)"]:::client
    subgraph "Frontend (Next.js App Router)" 
        direction TB
        PublicPages["Public Pages\nsrc/app/(public)"]:::frontend
        ProtectedPages["Protected Pages\nsrc/app/(protected)"]:::frontend
        AuthRoutes["Auth Routing & UI\nsrc/app/(auth)"]:::frontend
        UIComponents["Reusable UI Components\nsrc/components/ui"]:::frontend
        Layouts["Global Layouts & Entry\nsrc/app/layout.tsx\nsrc/app/page.tsx\nsrc/app/globals.css"]:::frontend
    end

    %% Server
    subgraph "Next.js Server"
        direction TB
        Middleware["Middleware\nsrc/middleware.ts"]:::server
        APIRoutes["API Routes\nsrc/app/api"]:::server
        Actions["Business Logic Layer\nsrc/actions"]:::server
        APIUtils["API Utilities\nsrc/lib/api.ts"]:::server
        Utils["Shared Utilities\nsrc/lib/utils.ts"]:::server
        PrismaClient["Prisma Client\nsrc/lib/prisma.ts"]:::server
    end

    %% Database
    Database[(PostgreSQL Database)]:::database
    Schema["Prisma Schema\nprisma/schema.prisma"]:::server
    Migrations["Migrations\nprisma/migrations"]:::server

    %% External Services
    Clerk["Clerk Authentication"]:::external
    StaticAssets["Static Assets\npublic"]:::server
    BuildPipeline["Build Pipeline\nTailwind: tailwind.config.ts\nPostCSS: postcss.config.mjs"]:::server

    %% Connections
    Browser -->|"requests pages"| PublicPages
    Browser -->|"requests pages"| ProtectedPages
    Browser -->|"requests auth UI"| AuthRoutes
    Browser -->|"loads layouts/components"| Layouts
    Browser -->|"loads assets"| StaticAssets
    Browser -->|"AJAX/fetch calls"| APIRoutes

    PublicPages --> Middleware
    ProtectedPages --> Middleware
    AuthRoutes --> Middleware

    Middleware --> Next.js_Server["Next.js Server"]:::server

    Next.js_Server --> Clerk
    Next.js_Server --> APIRoutes
    Next.js_Server --> StaticAssets

    APIRoutes --> APIUtils
    APIRoutes --> Utils
    APIRoutes --> Actions
    Actions --> PrismaClient
    PrismaClient --> Schema
    PrismaClient --> Database
    Migrations --> Database

    BuildPipeline -.-> Layouts

    %% Click Events
    click PublicPages "https://github.com/siddharth7729/vanishchat/tree/master/src/app/(public)"
    click ProtectedPages "https://github.com/siddharth7729/vanishchat/tree/master/src/app/(protected)"
    click AuthRoutes "https://github.com/siddharth7729/vanishchat/tree/master/src/app/(auth)"
    click UIComponents "https://github.com/siddharth7729/vanishchat/tree/master/src/components/ui"
    click Layouts "https://github.com/siddharth7729/vanishchat/blob/master/src/app/layout.tsx"
    click APIRoutes "https://github.com/siddharth7729/vanishchat/tree/master/src/app/api"
    click Actions "https://github.com/siddharth7729/vanishchat/tree/master/src/actions"
    click PrismaClient "https://github.com/siddharth7729/vanishchat/blob/master/src/lib/prisma.ts"
    click Schema "https://github.com/siddharth7729/vanishchat/blob/master/prisma/schema.prisma"
    click Migrations "https://github.com/siddharth7729/vanishchat/tree/master/prisma/migrations"
    click StaticAssets "https://github.com/siddharth7729/vanishchat/tree/master/public"
    click Middleware "https://github.com/siddharth7729/vanishchat/blob/master/src/middleware.ts"
    click BuildPipeline "https://github.com/siddharth7729/vanishchat/blob/master/tailwind.config.ts"
    click BuildPipeline "https://github.com/siddharth7729/vanishchat/blob/master/postcss.config.mjs"
    click APIUtils "https://github.com/siddharth7729/vanishchat/blob/master/src/lib/api.ts"
    click Utils "https://github.com/siddharth7729/vanishchat/blob/master/src/lib/utils.ts"

    %% Styles
    classDef client fill:#E0F7FA,stroke:#006064
    classDef frontend fill:#E0F7FA,stroke:#006064
    classDef server fill:#E8F5E9,stroke:#1B5E20
    classDef external fill:#FFF9C4,stroke:#F57F17
    classDef database fill:#CFD8DC,stroke:#37474F
```
