How carloshcobos/phpbookc17 works
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