How hichamzrk/oc_p5_blog works
Project type and purpose
• This is a monolithic, full-stack PHP blog application following an MVC (Model-View-Controller) pattern.
• It offers public pages (home, posts, single post view, contact form) and an admin area for creating, updating and deleting posts, plus user management.
File structure
• Top-level directories:
• Controllers – orchestrate requests, call models, render views
• Models – represent data entities (User, Post, Comment, Token) and their managers
• Views – presentation templates, one folder per feature (posts, post, comments, login, admin, etc.) plus a default layout
• Core – framework core: Db connection (Core/Db/Db.php) and Main bootstrapper (Core/Main.php)
• Public – webroot: index.php (front controller), assets (CSS, pictures), .htaccess routing
• SQL schema file (blog.sql) and composer files for dependencies
README for additional insights
• Confirms MVC model, PHP OOP, local server setup, MySQL database, email/contact settings in MainController.
a. Main components
1. Client (Browser)
2. Webserver / PHP runtime
3. Front Controller (Public/index.php + .htaccess)
4. Router / Core/Main – determines which Controller to invoke
5. Controllers (AdminController, PostsController, UserController, MainController)
6. Models / Managers – DB abstraction (Model classes + *Manager classes)
7. Database (MySQL “blog” schema)
8. Views (PHP templates)
9. External services: SMTP for contact form (via MainController)
10. Assets Server (CSS, images served from Public/css, Public/picture)
b. Relationships and interactions
• Browser → HTTP request → Webserver → index.php (Front Controller)
• index.php → Core/Main loads configuration, invokes Router
• Router → resolves URL → appropriate Controller.method()
• Controller → ModelManager (e.g., PostManager) → executes SQL via Core/Db/Db → returns entity objects
• Controller → passes entities to View → View renders HTML → sent back to Client
• For admin actions: Controller checks session, calls UserManager and TokenManager as needed
• Contact form submission: MainController sends email via SMTP
c. Architectural patterns and design principles
• MVC separation of concerns
• Single Responsibility: Controllers handle HTTP logic, Models handle data, Views handle presentation
• Dependency inversion: Controllers depend on Manager interfaces (via Manager.php base)
• Reusable Db connector (Singleton or static factory in Core/Db/Db.php)
d. Key technologies, frameworks, libraries
• PHP 7+ OOP
• Apache/Nginx with .htaccess routing
• MySQL database
• Composer for autoloading
• Native PHP mail or SMTP library for contact form