# mariariosnavarro/next-payloadcms-app architecture

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

- Interactive diagram: https://gitdiagram.com/mariariosnavarro/next-payloadcms-app
- Repository: https://github.com/mariariosnavarro/next-payloadcms-app

## Overview

##### Main System Components

a) Frontend Layer (Next.js):
- Represented by a blue rectangle labeled "Frontend (Next.js)"
- (frontend) route structure under src/app/(frontend)

b) Admin Panel Layer:
- This parallel to the frontend
- Represented by a green rectangle labeled "Payload Admin Panel"
- Connected to the src/app/(payload)/admin structure

c) API Layer:
- This in the middle
- Represented by a yellow rectangle containing:
- REST API endpoints (/api/[...slug])
- GraphQL endpoint (/api/graphql)
- GraphQL Playground

d) Collections Layer:
- This near the bottom
- Represented by an orange rectangle showing:
- Users
- Posts
- Media

e) Database Layer:
- At the bottom

##### Component Relationships
- Frontend → API Layer (REST/GraphQL requests)
- Admin Panel → API Layer (CMS operations)
- API Layer → Collections Layer (data operations)
- Collections Layer → Database Layer (persistence)

##### Special Architectural Elements

- beforeOperation
- beforeValidate
- beforeChange
- afterChange
- beforeDelete
- afterDelete
- afterRead
- afterError

##### Technical Stack Indicators
- Next.js 13+ (App Router)
- Payload CMS
- TypeScript
- SCSS/Tailwind
- GraphQL

##### Key Design Patterns
Highlight:
- Route Groups ((frontend) and (payload))
- API Routes structure
- Collection-based data modeling

**[Frontend Layer (Next.js)] -----> [Admin Panel Layer]**
- ↓                            ↓
- → [API Layer] ←────┘
- ↓
- [Collections Layer]
- ↓
- [Database Layer]

**[Hooks System Panel]     [Technical Stack]**

Important Considerations:

##### Clear separation between
- Client-side components
- Server-side components
- API endpoints
- Data storage

##### A small section showing the build/deployment setup
- Docker configuration
- Environment variables
- Next.js configuration

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Frontend Layer"
        FL["Frontend (Next.js)"]:::frontend
        ML["Main Layout"]:::frontend
        HP["Homepage"]:::frontend
        GS["Global Styles"]:::frontend
        FL --> ML
        FL --> HP
        FL --> GS
    end

    subgraph "Admin Panel Layer"
        AP["Payload Admin Panel"]:::admin
        AR["Admin Routes"]:::admin
        AL["Admin Layout"]:::admin
        AS["Admin Styles"]:::admin
        AP --> AR
        AP --> AL
        AP --> AS
    end

    subgraph "API Layer"
        API["API Gateway"]:::api
        REST["REST API"]:::api
        GQL["GraphQL"]:::api
        GQLP["GraphQL Playground"]:::api
        API --> REST
        API --> GQL
        API --> GQLP
    end

    subgraph "Collections Layer"
        COL["Collections"]:::collection
        Users["Users Collection"]:::collection
        Posts["Posts Collection"]:::collection
        Media["Media Collection"]:::collection
        COL --> Users
        COL --> Posts
        COL --> Media
    end

    subgraph "Configuration"
        Config["Payload Config"]:::config
        Types["Types"]:::config
    end

    subgraph "Hooks System"
        direction TB
        Hooks["Hooks"]:::hooks
        BeforeOp["beforeOperation"]:::hooks
        BeforeVal["beforeValidate"]:::hooks
        BeforeChange["beforeChange"]:::hooks
        AfterChange["afterChange"]:::hooks
        BeforeDelete["beforeDelete"]:::hooks
        AfterDelete["afterDelete"]:::hooks
        AfterRead["afterRead"]:::hooks
        AfterError["afterError"]:::hooks
        Hooks --> BeforeOp
        Hooks --> BeforeVal
        Hooks --> BeforeChange
        Hooks --> AfterChange
        Hooks --> BeforeDelete
        Hooks --> AfterDelete
        Hooks --> AfterRead
        Hooks --> AfterError
    end

    DB[(Database)]:::database

    FL --> API
    AP --> API
    API --> COL
    COL --> DB
    Config --> API
    Types --> API
    Hooks --> COL

    %% Click Events
    click FL "https://github.com/MariaRiosNavarro/next-payloadcms-app/tree/main/src/app/(frontend)"
    click ML "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/app/(frontend)/layout.tsx"
    click HP "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/app/(frontend)/page.tsx"
    click GS "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/app/(frontend)/globals.scss"
    click AP "https://github.com/MariaRiosNavarro/next-payloadcms-app/tree/main/src/app/(payload)/admin"
    click AR "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/app/(payload)/admin/[[...segments]]"
    click AL "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/app/(payload)/admin/[[...segments]]/page.tsx"
    click AS "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/app/(payload)/custom.scss"
    click REST "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/app/(payload)/api/[...slug]"
    click GQL "https://github.com/MariaRiosNavarro/next-payloadcms-app/tree/main/src/app/(payload)/api/graphql"
    click GQLP "https://github.com/MariaRiosNavarro/next-payloadcms-app/tree/main/src/app/(payload)/api/graphql-playground"
    click Users "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/collections/Users.ts"
    click Posts "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/collections/Posts.ts"
    click Media "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/collections/Media.ts"
    click COL "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/collections/index.ts"
    click Config "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/payload.config.ts"
    click Types "https://github.com/MariaRiosNavarro/next-payloadcms-app/blob/main/src/payload-types.ts"

    classDef frontend fill:#3498db,stroke:#2980b9,color:#fff
    classDef admin fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef api fill:#f1c40f,stroke:#f39c12,color:#000
    classDef collection fill:#e67e22,stroke:#d35400,color:#fff
    classDef database fill:#95a5a6,stroke:#7f8c8d,color:#fff
    classDef config fill:#9b59b6,stroke:#8e44ad,color:#fff
    classDef hooks fill:#1abc9c,stroke:#16a085,color:#fff

    %% Legend
    subgraph Legend
        L1["Frontend"]:::frontend
        L2["Admin"]:::admin
        L3["API"]:::api
        L4["Collections"]:::collection
        L5["Database"]:::database
        L6["Config"]:::config
        L7["Hooks"]:::hooks
    end
```
