# shubham7854/headless-cms architecture

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

- Interactive diagram: https://gitdiagram.com/shubham7854/headless-cms
- Repository: https://github.com/shubham7854/headless-cms

## Overview

##### Project Type & Purpose
- Full-stack Next.js 13 “App Router” application.
- Implements user authentication (sign-in/sign-up), an admin console for managing posts & users, and a public thumbnails folder.
- Uses Prisma as the ORM, Tailwind for styling, Node.js runtime.

##### Main Components
A. Client (Browser)
– React pages & components served by Next.js (src/app/(auth), src/app/(admin), etc.)
– Tailwind.css styling applied at build time.
B. Next.js Server
1. Frontend Layer (App Router)
- Server + client React components (page.jsx under each route).
- Static assets served from /public (e.g., /thumbnails).
2. Backend/API Layer
- Server-side actions (src/app/actions/getBlogs.js, getSingleUser.js)
- Next.js route handlers (if any) or in-component fetch calls
- Authentication logic in (auth) pages.
C. Data Access Layer
- Prisma Client invoked by actions and page server-side code.
- Prisma schema defined in prisma/schema.prisma – models for User, Post, etc.
D. Database
- PostgreSQL / MySQL / SQLite instance (as configured in .env).
E. (Optional) CDN / Edge

##### Relationships & Data Flows
1. Browser → Next.js Frontend
- HTTP GET for pages (e.g., /auth/sign-in, /admin/posts)
- CSS/JS bundles and static assets fetched from /public.
2. Frontend → Backend (in-page data calls)
- page.jsx calls fetch() or server actions getBlogs() / getSingleUser().
- These invoke Prisma Client queries.
3. Backend → Prisma → Database
- Prisma issues SQL queries to read/write Users, Posts.
4. Auth workflows
- Sign-up form → POST to auth handler → create user via Prisma → session (cookie/JWT) issued
- Sign-in form → verify credentials via Prisma → session.
5. Admin workflows
- Admin → /admin/posts → fetch list of posts via getBlogs() → render table
- Admin → /admin/users → fetch list via getSingleUser() → render.

##### Architectural Patterns & Principles
- “App Router” directory-based routing (each folder under src/app is a route segment).
- Server & client React components (use “use client” where needed).
- Single codebase handling both rendering and API logic (backend interwoven).
- Prisma as a data-mapper (separates schema from code).
- Tailwind for utility-first CSS (build-time configured via tailwind.config.js).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        Browser["Browser"]:::external
        Assets["public/thumbnails"]:::static
    end

    subgraph "Frontend Layer"
        SignIn["/auth/sign-in page.jsx"]:::frontend
        SignUp["/auth/sign-up page.jsx"]:::frontend
        AdminPosts["/admin/posts page.jsx"]:::frontend
        AdminUsers["/admin/users page.jsx"]:::frontend
    end

    subgraph "Backend Layer"
        GetBlogs["getBlogs action"]:::backend
        GetUser["getSingleUser action"]:::backend
    end

    subgraph "Configuration"
        Tailwind["tailwind.config.js"]:::infra
        NextConfig["next.config.mjs"]:::infra
    end

    subgraph "Data Layer"
        PrismaSchema["prisma/schema.prisma"]:::infra
        PrismaClient["Prisma Client"]:::infra
    end

    Database["Database"]:::db

    %% Connections
    Browser -->|"HTTP GET"| SignIn
    Browser -->|"HTTP GET"| SignUp
    Browser -->|"HTTP GET"| AdminPosts
    Browser -->|"HTTP GET"| AdminUsers
    Browser -->|"Fetch static assets"| Assets

    SignIn -->|"JS call"| GetUser
    SignUp -->|"JS call"| GetUser
    AdminPosts -->|"invoke getBlogs()"| GetBlogs
    AdminUsers -->|"invoke getSingleUser()"| GetUser

    GetBlogs -->|"uses Prisma Client"| PrismaClient
    GetUser -->|"uses Prisma Client"| PrismaClient

    PrismaSchema --> PrismaClient
    PrismaClient -->|"SQL"| Database

    %% Click Events
    click Assets "https://github.com/shubham7854/headless-cms/tree/main/public/thumbnails"
    click SignIn "https://github.com/shubham7854/headless-cms/blob/main/src/app/(auth)/sign-in/page.jsx"
    click SignUp "https://github.com/shubham7854/headless-cms/blob/main/src/app/(auth)/sign-up/page.jsx"
    click AdminPosts "https://github.com/shubham7854/headless-cms/blob/main/src/app/(admin)/posts/page.jsx"
    click AdminUsers "https://github.com/shubham7854/headless-cms/blob/main/src/app/(admin)/users/page.jsx"
    click GetBlogs "https://github.com/shubham7854/headless-cms/blob/main/src/app/actions/getBlogs.js"
    click GetUser "https://github.com/shubham7854/headless-cms/blob/main/src/app/actions/getSingleUser.js"
    click PrismaSchema "https://github.com/shubham7854/headless-cms/blob/main/prisma/schema.prisma"
    click Tailwind "https://github.com/shubham7854/headless-cms/blob/main/tailwind.config.js"
    click NextConfig "https://github.com/shubham7854/headless-cms/blob/main/next.config.mjs"

    %% Styles
    classDef frontend fill:#ccffcc,stroke:#2d7a2d,color:#000
    classDef backend fill:#cce5ff,stroke:#1a5fb4,color:#000
    classDef infra fill:#f2f2f2,stroke:#999,color:#000
    classDef db fill:#e5ccff,stroke:#6a0dad,color:#000
    classDef external fill:#fff2cc,stroke:#d4a017,color:#000
    classDef static fill:#e6ffe6,stroke:#33a02c,color:#000
```
