# sitegui-platform/litegui architecture

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

- Interactive diagram: https://gitdiagram.com/sitegui-platform/litegui
- Repository: https://github.com/sitegui-platform/litegui

## Overview

##### Project Type & Overall Purpose
- This is a CMS system that can function either as a complete content management solution or as a headless API backend. Its design supports both rendering a full-stack web application (through a user portal and an administrative/staff portal) and serving APIs.
- The README emphasizes key features (user/staff management, RBAC, visual editors, widget/layout management, etc.) that suggest a modular, extensible architecture.

##### Analyzing the File Structure
- Top-Level Directories & Files:
- “mysite” is the core folder. Inside, you have:
▪ “resources” – divided into “public” (templates, assets, uploads) and “protected” (app and client_uploads files) – clearly separating files that are accessible from the web and those that aren’t.
▪ “src” – the backend PHP source code. This is structured into subdirectories:
- “App” (likely application-specific logic, e.g. Blog.php)
- “Core” (domain components such as User, Staff, Page, Site, etc.) with Traits and Helper modules (e.g., Upgrade.php)
- “Notification” – handles email via PHPMail and SMTP.
- “Widget” – core widget components (e.g., Editor and Text)
- Entry point scripts like index.php, siteadmin.php, and siteuser.php which serve as the front controller for different portals.
- Other files like “config.php”, “cron.php”, and “setup.sh” indicate setup and scheduled task management.
- Public assets like the HTML templates under “mysite/resources/public/templates” and the vast number of CSS/JS assets provided for the admin themes suggest a heavy reliance on front-end templating and styling.

##### Key System Components
a. Presentation Layer:
– Webpages served to end users (siteuser.php) and to staff (siteadmin.php).
– Static assets served from “resources/public” (templates, images, CSS/JS).
– Separate themes and templates for user and admin interfaces.
b. Backend / Business Logic:
– PHP Application Layer in “src”:
- Core business logic (handled in “Core” modules such as User, Role, Page, etc.)
- Application-specific logic and controllers in “App” and “Widget”.
- Notification systems under “Notification”.
– Entry point scripts for different roles (index.php for general visitors, siteadmin.php for admin, siteuser.php for user accounts).
c. Data Persistence:
– MySQL/MariaDB is used for the database (sitegui_mysite.sql provides schema and data).
– Connections and configurations are made via “config.php” (or config.local.php).
– Optionally, Redis is mentioned for caching.
d. Infrastructure & External Dependencies:
– PHP 8 running via PHP-FPM (seen in Nginx configuration with fastcgi_pass).
– Nginx web server serving both the application’s dynamic PHP content and static files (see Nginx configuration files in the README).
– Optional external services like OAuth providers for social login and Redis for caching.
– Setup scripts (setup.sh) and cron jobs (cron.php) for background processes and maintenance.

##### Architectural Relationships and Data Flow
- Client requests (from browsers or mobile apps) first reach the Nginx server.
- Nginx routes the traffic to the proper PHP script based on the URL:
– General traffic to “index.php”
– Staff interactions to “siteadmin.php”
– User interactions to “siteuser.php”
- PHP-FPM handles the dynamic processing where the “src” layer coordinates business logic by invoking components in “Core”, “App”, and “Widget”.
- The PHP backend communicates with the database using credentials set in “config.php” and optionally to Redis for caching sessions or data.
- For static assets (CSS, JS, images, templates), Nginx is configured to directly serve files from “mysite/resources/public”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        clUser["User Browser"]:::client
        clStaff["Staff Browser"]:::client
    end

    subgraph "Web Server Layer"
        nginx["Nginx (Main Website & Static Assets)"]:::web
    end

    subgraph "Application Layer"
        phpFPM["PHP-FPM Engine"]:::app
        subgraph "Entry Points"
            idx["index.php"]:::appEP
            admin["siteadmin.php"]:::appEP
            user["siteuser.php"]:::appEP
        end
        subgraph "Business Logic"
            core["Core Modules (e.g., User, Page, Role)"]:::logic
            appSpec["App Modules (e.g., Blog)"]:::logic
            widget["Widget Components (Editor, Text)"]:::logic
            notify["Notification System"]:::logic
        end
        config["Configuration (config.php)"]:::infra
        cron["Cron Jobs (cron.php)"]:::infra
        setup["Setup Script (setup.sh)"]:::infra
    end

    subgraph "Data Layer"
        db["Database (MySQL/MariaDB)"]:::db
        redis["Redis Cache (Optional)"]:::db
    end

    %% Data Flow
    clUser -->|"request"| nginx
    clStaff -->|"request"| nginx
    nginx -->|"routes to"| phpFPM
    phpFPM -->|"invokes"| idx
    phpFPM -->|"invokes"| admin
    phpFPM -->|"invokes"| user
    phpFPM -->|"processes with"| core
    phpFPM -->|"processes with"| appSpec
    phpFPM -->|"processes with"| widget
    phpFPM -->|"processes with"| notify
    phpFPM -->|"reads"| config
    phpFPM -->|"schedules"| cron
    phpFPM -->|"initiates"| setup
    phpFPM -->|"queries"| db
    phpFPM -->|"caches"| redis

    %% Click Events
    click idx "https://github.com/sitegui-platform/litegui/blob/main/mysite/src/index.php"
    click admin "https://github.com/sitegui-platform/litegui/blob/main/mysite/src/siteadmin.php"
    click user "https://github.com/sitegui-platform/litegui/blob/main/mysite/src/siteuser.php"
    click nginx "https://github.com/sitegui-platform/litegui/tree/main/mysite/resources/public"
    click core "https://github.com/sitegui-platform/litegui/tree/main/mysite/src/Core"
    click appSpec "https://github.com/sitegui-platform/litegui/tree/main/mysite/src/App"
    click widget "https://github.com/sitegui-platform/litegui/tree/main/mysite/src/Widget"
    click notify "https://github.com/sitegui-platform/litegui/tree/main/mysite/src/Notification"
    click config "https://github.com/sitegui-platform/litegui/blob/main/mysite/src/config.php"
    click setup "https://github.com/sitegui-platform/litegui/blob/main/mysite/setup.sh"
    click cron "https://github.com/sitegui-platform/litegui/blob/main/mysite/src/cron.php"
    click db "https://github.com/sitegui-platform/litegui/blob/main/sitegui_mysite.sql"

    %% Styles
    classDef client fill:#a8dadc,stroke:#457b9d,stroke-width:2px;
    classDef web fill:#fca311,stroke:#d09a35,stroke-width:2px;
    classDef app fill:#e9c46a,stroke:#cfa049,stroke-width:2px;
    classDef appEP fill:#e9c46a,stroke:#cfa049,stroke-width:2px;
    classDef logic fill:#2a9d8f,stroke:#21867a,stroke-width:2px;
    classDef infra fill:#f4a261,stroke:#d17c4e,stroke-width:2px;
    classDef db fill:#e76f51,stroke:#d1563e,stroke-width:2px;
```
