# payloadcms/public-demo architecture

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

- Interactive diagram: https://gitdiagram.com/payloadcms/public-demo
- Repository: https://github.com/payloadcms/public-demo

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js App Router application
- Client-side components (src/app/_components)
- Page templates and routes (src/app/(pages))
- Theme and styling system (src/app/_css)
- Client-side providers (src/app/_providers)

b) Backend Layer:
- Payload CMS core
- Collections (Users, Posts, Projects, Pages, Media, Categories, Comments)
- Globals (Header, Footer, Settings)
- GraphQL API (src/app/_graphql)
- Authentication system
- Access control layer

c) Database Layer:
- MongoDB database
- Media storage

##### Relationships and Data Flow

a) Client-Server Communication:
- GraphQL queries/mutations
- REST API endpoints (src/app/api/*)
- Authentication flows
- Draft preview system
- Comment submission flow

b) Content Management:
- Admin panel interactions
- Content publishing workflow
- Media handling
- SEO management
- Redirect handling

##### Architectural Patterns

Patterns:

**[Frontend Layer]**

- (GraphQL/REST)
- v
**[Backend Layer]**

- (Database Operations)
- v
**[Database Layer]**

##### Component Details

a) Frontend Components:
**[Next.js App]**
- Pages & Routes
- Components
- Blocks System
- Theme Provider
- Auth Provider

b) Backend Services:
**[Payload CMS]**
- Collections
- Access Control
- GraphQL API
- Media Handler
- Authentication

##### Special Features

Unique features:

- Premium content access flow
- Draft preview system
- Comment moderation workflow
- Layout builder system
- SEO and redirect handling

##### Technical Stack Indicators

- Next.js
- Payload CMS
- MongoDB
- GraphQL
- TypeScript
- SCSS Modules

Remember to show the clear separation between the admin panel and public website interfaces, as well as how they interact with the shared backend services.

This system design should help developers understand both the overall architecture and the specific implementation patterns used in this project.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        NextApp[Next.js App]
        Components[Components]
        Pages[Pages & Routes]
        Blocks[Blocks System]
        Theme[Theme System]
        AuthProvider[Auth Provider]
        ClientAPI[Client API]
        Forms[Form Components]
        Heroes[Hero Components]
    end

    subgraph Backend
        PayloadCMS[Payload CMS]
        Collections[Collections]
        AccessControl[Access Control]
        GraphQLAPI[GraphQL API]
        MediaHandler[Media Handler]
        Auth[Authentication]
        RichText[Rich Text Editor]
        APIEndpoints[API Endpoints]
        Globals[Global Settings]
        Seeds[Database Seeding]
    end

    subgraph Database
        MongoDB[(MongoDB)]
        MediaStorage[(Media Storage)]
    end

    %% Frontend Relationships
    NextApp --> Components
    NextApp --> Pages
    NextApp --> Blocks
    NextApp --> Theme
    NextApp --> AuthProvider
    NextApp --> ClientAPI
    NextApp --> Forms
    NextApp --> Heroes

    %% Backend Relationships
    PayloadCMS --> Collections
    PayloadCMS --> AccessControl
    PayloadCMS --> GraphQLAPI
    PayloadCMS --> MediaHandler
    PayloadCMS --> Auth
    PayloadCMS --> RichText
    PayloadCMS --> APIEndpoints
    PayloadCMS --> Globals
    PayloadCMS --> Seeds

    %% Cross-layer Relationships
    NextApp -.->|GraphQL/REST| PayloadCMS
    PayloadCMS -->|Database Operations| MongoDB
    MediaHandler -->|Storage Operations| MediaStorage

    %% Component Mappings
    click Components "https://github.com/payloadcms/public-demo/tree/master/src/app/_components"
    click Pages "https://github.com/payloadcms/public-demo/tree/master/src/app/(pages)"
    click Theme "https://github.com/payloadcms/public-demo/tree/master/src/app/_css"
    click AuthProvider "https://github.com/payloadcms/public-demo/tree/master/src/app/_providers"
    click GraphQLAPI "https://github.com/payloadcms/public-demo/tree/master/src/app/_graphql"
    click Collections "https://github.com/payloadcms/public-demo/tree/master/src/payload/collections"
    click AccessControl "https://github.com/payloadcms/public-demo/tree/master/src/payload/access"
    click Auth "https://github.com/payloadcms/public-demo/tree/master/src/payload/collections/Users"
    click Blocks "https://github.com/payloadcms/public-demo/tree/master/src/app/_blocks"
    click APIEndpoints "https://github.com/payloadcms/public-demo/tree/master/src/app/api"
    click Heroes "https://github.com/payloadcms/public-demo/tree/master/src/app/_heros"
    click ClientAPI "https://github.com/payloadcms/public-demo/tree/master/src/app/_api"
    click Seeds "https://github.com/payloadcms/public-demo/tree/master/src/payload/seed"
    click Globals "https://github.com/payloadcms/public-demo/tree/master/src/payload/globals"
    click Forms "https://github.com/payloadcms/public-demo/tree/master/src/payload/blocks/Form"
    click MediaHandler "https://github.com/payloadcms/public-demo/blob/master/src/payload/collections/Media.ts"
    click RichText "https://github.com/payloadcms/public-demo/tree/master/src/payload/fields/richText"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef security fill:#e74c3c,stroke:#c0392b,color:white

    class NextApp,Components,Pages,Blocks,Theme,AuthProvider,ClientAPI,Forms,Heroes frontend
    class PayloadCMS,Collections,AccessControl,GraphQLAPI,MediaHandler,Auth,RichText,APIEndpoints,Globals,Seeds backend
    class MongoDB,MediaStorage database
    class Auth,AccessControl,AuthProvider security
```
