# carloshcobos/phpbookc17 architecture

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

- Interactive diagram: https://gitdiagram.com/carloshcobos/phpbookc17
- Repository: https://github.com/carloshcobos/phpbookc17

## Overview

##### Project Type and Purpose
- This is a modular, full-stack PHP/MySQL CMS (Content Management System) with a public website and an admin panel.
- It uses Composer dependencies (Twig for templating, PHPMailer for email, HTMLPurifier for sanitization) and follows an MVC-like separation of concerns.

##### Key File-Structure Highlights
- config/ → database credentials, route definitions
- public/ → web-root assets (CSS, JS, fonts, uploads) and index.php (front controller)
- src/bootstrap.php → autoloading, DI container or setup
- src/pages/ → “controllers” for public and admin endpoints
- src/classes/
- CMS/ → domain models (Article, Category, Comment, Member, Like, Session, Token, Database)
- Email/ → mailer wrapper
- Validate/ → input validation logic
- templates/ → Twig view layer (separate subfolders for admin & public)
- var/cache/ → compiled templates cache
- vendor/ → third-party libraries

##### Extracted Architectural Patterns
- Front Controller pattern (public/index.php routes all requests)
- MVC-style layering (Controllers in src/pages, Models in src/classes/CMS, Views in templates)
- Service classes for cross-cutting concerns (Email, Validate)
- Template caching (Twig + var/cache)
- Composer-based dependency management

A. Client Browser
B. Web Server (Apache/nginx or built-in PHP server)
→ hosts public/index.php
C. Front Controller / Router (public/index.php + src/bootstrap.php)
→ resolves URL, loads dependencies
D. Controllers (src/pages)
→ handle request actions (list articles, login, save changes)
E. Domain & Service Layer (src/classes)
- CMS models interact with Database class
- Validate service cleans & validates input
- Email service sends mail via PHPMailer/SMTP
F. Templating Engine (Twig + templates/)
→ renders HTML views, writes to var/cache
G. Data Storage
- MySQL database (configured in config/config.php)
- File store for uploads (public/uploads)
H. External Services
- SMTP Mail Server
- (Optionally) Third-party identity or caching services

1. Client → HTTP request → Web Server
2. Web Server → Front Controller → Controller
3. Controller ↔ Domain Layer (Models/Services) ↔ MySQL
4. Domain Layer → Templating Engine → HTML Response
5. Templating Engine caches output in var/cache
6. Controller may invoke Email Service → SMTP
7. Web Server → HTTP Response → Client

##### Important Architectural Notes
- Separate admin vs public controllers and templates
- Use namespaces and PSR-4 autoloading (composer.json)
- Centralized config and bootstrap for route and DB connection
- Cache compiled twig templates for performance
- Sanitization via HTMLPurifier before rendering user content

## Diagram (Mermaid)

```mermaid
graph TD
    Client["Client Browser"]:::client
    WebServer["Web Server\n(Apache/nginx)"]:::server
    FrontController["Front Controller\n(public/index.php)"]:::router
    Bootstrap["Bootstrap & DI Setup\n(src/bootstrap.php)"]:::router
    Config["Configuration\n(config/config.php)"]:::router

    subgraph "Controllers"
        direction TB
        PublicCtrl["Public Controllers\n(src/pages/*.php)"]:::controller
        AdminCtrl["Admin Controllers\n(src/pages/admin/*.php)"]:::controller
    end

    subgraph "Domain & Services"
        direction TB
        Article["Article Model"]:::domain
        Category["Category Model"]:::domain
        Comment["Comment Model"]:::domain
        Like["Like Model"]:::domain
        Member["Member Model"]:::domain
        Session["Session Model"]:::domain
        Token["Token Model"]:::domain
        DB["Database Abstraction\n(src/classes/CMS/Database.php)"]:::domain
        ValidateSvc["Validation Service\n(src/classes/Validate/Validate.php)"]:::service
        EmailSvc["Email Service\n(src/classes/Email/Email.php)"]:::service
    end

    subgraph "View Layer & Cache"
        direction TB
        TwigEngine["Twig Engine"]:::view
        TemplatesPub["Public Templates\n(templates/*.html)"]:::view
        TemplatesAdmin["Admin Templates\n(templates/admin/*.html)"]:::view
        Cache["Compiled Templates\n(var/cache/)"]:::store
    end

    subgraph "Storage & Assets"
        direction TB
        MySQL["MySQL Database"]:::store
        Uploads["File Upload Store\n(public/uploads/)"]:::store
        StaticAssets["Static Assets\n(public/css/, public/js/, public/font/, public/img/)"]:::store
    end

    subgraph "External Services"
        SMTP["SMTP Mail Server"]:::external
    end

    Client -->|"HTTP Request"| WebServer
    WebServer --> FrontController
    FrontController --> Config
    FrontController --> Bootstrap
    Bootstrap --> Vendor
    FrontController --> PublicCtrl
    FrontController --> AdminCtrl

    PublicCtrl -->|"calls"| Article
    PublicCtrl --> Category
    PublicCtrl --> Comment
    PublicCtrl --> Like
    PublicCtrl --> Member
    PublicCtrl --> Session
    PublicCtrl --> Token
    PublicCtrl --> DB

    AdminCtrl -->|"manages"| Article
    AdminCtrl --> Category
    AdminCtrl --> Comment
    AdminCtrl --> Like
    AdminCtrl --> Member
    AdminCtrl --> Session
    AdminCtrl --> Token
    AdminCtrl --> DB

    Article --> DB
    Category --> DB
    Comment --> DB
    Like --> DB
    Member --> DB
    Session --> DB
    Token --> DB

    PublicCtrl --> ValidateSvc
    AdminCtrl --> ValidateSvc

    AdminCtrl --> EmailSvc
    PublicCtrl --> EmailSvc

    PublicCtrl --> TwigEngine
    AdminCtrl --> TwigEngine
    TwigEngine --> TemplatesPub
    TwigEngine --> TemplatesAdmin
    TwigEngine --> Cache

    Cache -->|"reads"| TwigEngine

    MySQL -->|"SQL"| DB
    DB -->|"SQL"| MySQL

    EmailSvc -->|"SMTP"| SMTP

    WebServer -->|"serves"| StaticAssets
    WebServer -->|"uploads"| Uploads

    WebServer -->|"HTTP Response"| Client

    click FrontController "https://github.com/carloshcobos/phpbookc17/blob/main/public/index.php"
    click Bootstrap "https://github.com/carloshcobos/phpbookc17/blob/main/src/bootstrap.php"
    click Config "https://github.com/carloshcobos/phpbookc17/blob/main/config/config.php"
    click PublicCtrl "https://github.com/carloshcobos/phpbookc17/blob/main/src/pages/*.php"
    click AdminCtrl "https://github.com/carloshcobos/phpbookc17/blob/main/src/pages/admin/*.php"
    click Article "https://github.com/carloshcobos/phpbookc17/blob/main/src/classes/CMS/Article.php"
    click Category "https://github.com/carloshcobos/phpbookc17/blob/main/src/classes/CMS/Category.php"
    click Comment "https://github.com/carloshcobos/phpbookc17/blob/main/src/classes/CMS/Comment.php"
    click Like "https://github.com/carloshcobos/phpbookc17/blob/main/src/classes/CMS/Like.php"
    click Member "https://github.com/carloshcobos/phpbookc17/blob/main/src/classes/CMS/Member.php"
    click Session "https://github.com/carloshcobos/phpbookc17/blob/main/src/classes/CMS/Session.php"
    click Token "https://github.com/carloshcobos/phpbookc17/blob/main/src/classes/CMS/Token.php"
    click DB "https://github.com/carloshcobos/phpbookc17/blob/main/src/classes/CMS/Database.php"
    click EmailSvc "https://github.com/carloshcobos/phpbookc17/blob/main/src/classes/Email/Email.php"
    click ValidateSvc "https://github.com/carloshcobos/phpbookc17/blob/main/src/classes/Validate/Validate.php"
    click TemplatesPub "https://github.com/carloshcobos/phpbookc17/tree/main/templates/"
    click TemplatesAdmin "https://github.com/carloshcobos/phpbookc17/tree/main/templates/admin/"
    click Cache "https://github.com/carloshcobos/phpbookc17/tree/main/var/cache/"
    click StaticAssets "https://github.com/carloshcobos/phpbookc17/tree/main/public/css/"
    click Uploads "https://github.com/carloshcobos/phpbookc17/tree/main/public/uploads/"
    click Vendor "https://github.com/carloshcobos/phpbookc17/tree/main/vendor/"

    classDef client fill:#e6ffe6,stroke:#006600,stroke-width:2px
    classDef server fill:#e6f0ff,stroke:#003399,stroke-width:2px
    classDef router fill:#cce0ff,stroke:#0059b3,stroke-width:2px
    classDef controller fill:#ffe6cc,stroke:#b35900,stroke-width:2px
    classDef domain fill:#ffffcc,stroke:#999900,stroke-width:2px
    classDef service fill:#fff2cc,stroke:#b38600,stroke-width:2px
    classDef view fill:#e6ffe6,stroke:#00994d,stroke-width:2px
    classDef store fill:#f2e6ff,stroke:#660099,stroke-width:2px
    classDef external fill:#f2f2f2,stroke:#666666,stroke-width:2px
```
