# sundev207/mern-stack-cms architecture

> Architecture diagram of the GitHub repository sundev207/mern-stack-cms, 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/sundev207/mern-stack-cms
- Repository: https://github.com/sundev207/mern-stack-cms

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) content management system (CMS).
- The “client” folder contains a React/Redux single-page app (SPA) for both public site views and an admin interface.
- The “server” folder houses an Express RESTful API, Pug views for server-rendered pages (error/index), static asset hosting, authentication/middleware, and a MongoDB data layer.

##### File structure
- Top-level:
· client/ – React application (src, public, Redux actions/reducers, components/containers)
· server/ – Express app (app.js, routes/, models/, middlewares/, views/, public/static upload & styles)
· config.js & sites.json – global configuration and multisite definitions for MongoDB import
- Patterns & concerns:
· client/src/actions + reducers → Redux state management (REST calls, auth, categories, posts, sites, snackbars)
· client/src/containers → React Router routes and admin vs public page separation
· server/routes/*.js → REST endpoints for users, posts, pages, tags, sites, capabilities
· server/middlewares → authentication, brute-force rate limiting
· server/models/schemas.js → Mongoose schemas, models/index.js → model initialization
· server/public/upload/themes → user-uploadable theme assets
· server/views → Pug templates for server-rendered entry points (error.pug, index.pug)

##### Key README insights
- Uses MongoDB 3.2+, multi-site import via sites.json
- Separate npm installs/starts for client (port 3000) & server (port 3001)
- First admin user setup by manually updating the users collection’s role field

##### Detailing and essential capture
· Public UI vs Admin UI sections in the SPA
· API Gateway vs Business Logic vs Data Layer on the server
· External dependencies (MongoDB, file storage)
- Authentication flow: login → token/cookie → protected route middleware
- Static file serving path (e.g., GET /upload/themes/:themeName → file system)
- Special routes (e.g., /sites to load multisite configuration)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client (React SPA)"
        UI["UI Components"]:::client
        Actions["Redux Actions"]:::client
        Reducers["Redux Reducers"]:::client
        Router["React Router Containers"]:::client
        Index["index.js"]:::client
        App["App.js"]:::client
    end

    subgraph "Server"
        subgraph "API Gateway"
            APIApp["Express API"]:::server
        end
        subgraph "REST Endpoints"
            RIndex["index.js"]:::server
            RUsers["users.js"]:::server
            RPosts["posts.js"]:::server
            RPages["pages.js"]:::server
            RTags["tags.js"]:::server
            RSites["sites.js"]:::server
            RCaps["capabilities.js"]:::server
        end
        subgraph "Middleware Layer"
            Auth["authenticate.js"]:::server
            Brute["bruteforce.js"]:::server
        end
        subgraph "Business Logic & Controllers"
            ReactCMS["reactcms.js"]:::server
            UtilsIndex["index.js"]:::server
        end
        subgraph "Data Layer (Mongoose Models)"
            Schemas["schemas.js"]:::server
            ModelsIndex["index.js"]:::server
        end
        subgraph "Pug View Engine"
            IndexPug["index.pug"]:::server
            ErrorPug["error.pug"]:::server
            LayoutPug["layout.pug"]:::server
        end
        subgraph "Static Asset Store"
            Themes["upload/themes"]:::static
            Styles["stylesheets"]:::static
        end
    end

    ConfigJS["config.js"]:::misc
    SitesJSON["sites.json"]:::misc
    DB["MongoDB"]:::db

    UI --> Actions
    UI --> Reducers
    Actions -->|"HTTP Requests"| APIApp
    App --> APIApp
    Router --> App

    APIApp --> RIndex
    APIApp --> RUsers
    APIApp --> RPosts
    APIApp --> RPages
    APIApp --> RTags
    APIApp --> RSites
    APIApp --> RCaps

    RIndex --> Auth
    RUsers --> Auth
    RPosts --> Auth
    RPages --> Auth
    RTags --> Auth
    RSites --> Auth
    RCaps --> Auth

    Auth --> Brute
    Brute --> ReactCMS
    ReactCMS --> UtilsIndex
    UtilsIndex --> Schemas
    Schemas --> ModelsIndex
    ModelsIndex --> DB
    DB --> ModelsIndex
    ModelsIndex --> ReactCMS
    ReactCMS --> RIndex

    APIApp --> IndexPug
    APIApp --> ErrorPug
    APIApp --> LayoutPug

    APIApp --> Themes
    APIApp --> Styles
    Themes --> APIApp
    Styles --> APIApp

    ConfigJS --> DB
    SitesJSON --> DB

    classDef client fill:#ADD8E6,stroke:#0000FF
    classDef server fill:#90EE90,stroke:#008000
    classDef db fill:#FFA500,stroke:#FF8C00
    classDef static fill:#D3D3D3,stroke:#A9A9A9
    classDef misc fill:#F5F5F5,stroke:#C0C0C0

    click UI "https://github.com/sundev207/mern-stack-cms/tree/master/client/src/components"
    click Actions "https://github.com/sundev207/mern-stack-cms/tree/master/client/src/actions"
    click Reducers "https://github.com/sundev207/mern-stack-cms/tree/master/client/src/reducers"
    click Router "https://github.com/sundev207/mern-stack-cms/tree/master/client/src/containers"
    click Index "https://github.com/sundev207/mern-stack-cms/blob/master/client/src/index.js"
    click App "https://github.com/sundev207/mern-stack-cms/blob/master/client/src/App.js"
    click APIApp "https://github.com/sundev207/mern-stack-cms/blob/master/server/app.js"
    click RIndex "https://github.com/sundev207/mern-stack-cms/blob/master/server/routes/index.js"
    click RUsers "https://github.com/sundev207/mern-stack-cms/blob/master/server/routes/users.js"
    click RPosts "https://github.com/sundev207/mern-stack-cms/blob/master/server/routes/posts.js"
    click RPages "https://github.com/sundev207/mern-stack-cms/blob/master/server/routes/pages.js"
    click RTags "https://github.com/sundev207/mern-stack-cms/blob/master/server/routes/tags.js"
    click RSites "https://github.com/sundev207/mern-stack-cms/blob/master/server/routes/sites.js"
    click RCaps "https://github.com/sundev207/mern-stack-cms/blob/master/server/routes/capabilities.js"
    click Auth "https://github.com/sundev207/mern-stack-cms/blob/master/server/middlewares/authenticate.js"
    click Brute "https://github.com/sundev207/mern-stack-cms/blob/master/server/middlewares/bruteforce.js"
    click ReactCMS "https://github.com/sundev207/mern-stack-cms/blob/master/server/utils/reactcms.js"
    click UtilsIndex "https://github.com/sundev207/mern-stack-cms/blob/master/server/utils/index.js"
    click Schemas "https://github.com/sundev207/mern-stack-cms/blob/master/server/models/schemas.js"
    click ModelsIndex "https://github.com/sundev207/mern-stack-cms/blob/master/server/models/index.js"
    click IndexPug "https://github.com/sundev207/mern-stack-cms/blob/master/server/views/index.pug"
    click ErrorPug "https://github.com/sundev207/mern-stack-cms/blob/master/server/views/error.pug"
    click LayoutPug "https://github.com/sundev207/mern-stack-cms/blob/master/server/views/layout.pug"
    click Themes "https://github.com/sundev207/mern-stack-cms/tree/master/server/public/upload/themes"
    click Styles "https://github.com/sundev207/mern-stack-cms/tree/master/server/public/stylesheets"
    click ConfigJS "https://github.com/sundev207/mern-stack-cms/blob/master/config.js"
    click SitesJSON "https://github.com/sundev207/mern-stack-cms/blob/master/sites.json"
```
