How suhaib-md/myblog works
Project type and purpose
• This is a full-stack PHP web application: a Simple Blog Platform.
• Purpose: allow users to register/log in, create/edit/delete blog posts (text + optional images), and view posts.
File structure
• Top-level scripts (controllers):
• index.php (public homepage/view posts)
• register.php, login.php, logout.php (auth workflows)
• dashboard.php, create_post.php, edit_post.php, delete_post.php (CRUD operations)
• config/
• db.php (database connection settings)
• includes/ (shared view and logic)
• auth.php (session checks & access control)
• navbar.php, footer.php (layout templates)
• uploads/ (static asset storage for images)
This maps to a simplified Model-View-Controller pattern:
• Model: MySQL database (users, posts tables accessed via PDO)
• Controller: individual PHP scripts handling requests & business logic
• View: embedded‐PHP templates in index.php, dashboard.php, form scripts
• Configuration & Authentication layers as cross-cutting concerns
Key architectural insights from README
• Technology stack: Apache + PHP 7.4+, MySQL, PDO, HTML/CSS
• Security: password hashing, prepared statements, XSS/authorization checks, secure uploads
• MVC layers: configuration, authentication, controllers, views, assets
Main components
a. Client Layer
• Web Browser (Frontend UI: HTML/CSS delivered)
b. Web Server Layer
• Apache + PHP runtime
• config/db.php (Database Connector)
• includes/auth.php (Session & Access Control)
• Controllers (index.php, register/login/logout, dashboard, create/edit/delete)
• Views (navbar.php, footer.php + embedded templates)
• Uploads folder (image storage)
c. Data Layer
• MySQL Database (users, posts tables accessed via PDO)
d. External/Infrastructure
• File system (to persist uploaded images)
• Optional future services (e.g., rich-text editor, email service, search engine)
Component interactions and data flows
• Browser → HTTP request → Apache/PHP
• PHP Controller loads config/db.php → opens PDO connection to MySQL
• Auth layer (includes/auth.php) checks session/cookies for protected routes
• Controller executes business logic (CRUD) → issues SQL via PDO → MySQL responds
• Controller assembles data + view templates (navbar, footer) → Response → Browser
• Image uploads: Controller accepts multipart data → validates & moves file → saved to uploads/ → file path stored in DB → static resource served by Apache
Architectural patterns & principles
• Simplified MVC: separation of concerns between request handlers (controllers), data access (models via PDO), and presentation (views)
• Layered security: authentication layer, prepared statements, output escaping
• Filesystem as asset store for images
Details to capture
• Configuration Layer (db.php) feeding every controller
• Authentication middleware (includes/auth.php) gating dashboard/create/edit/delete
• Each CRUD controller’s relation to views and DB
• Static asset path (uploads/) and how Apache serves images