How mhannan-dev/php-blog works
1. System shape
- This is a classic raw PHP CMS/blog with two main surfaces: the public site at the repository root and the admin dashboard under /admin.
- It is not built around a modern framework; instead, it uses procedural entry files plus a small OOP application layer in app/.
2. Request entry points
- Public requests land in root scripts such as index.php, post.php, page.php, cat_posts.php, search.php, and contact_us.php.
- Admin requests land in /admin/*.php, with admin/index.php as the dashboard hub and dedicated pages for CRUD and account actions.
- .htaccess files indicate Apache-based routing/protection, likely for clean URLs and restricted directories.
3. Application bootstrap and shared core
- app/bootstrap.php is the shared bootstrap boundary used to initialize the app before models and helpers are used.
- app/Core/Database.php wraps MySQLi in a singleton-style connection layer.
- app/Core/Session.php centralizes session/auth state and flash-style behavior.
- app/Helpers/Format.php handles content formatting and sanitization concerns shared across pages.
4. Domain model layer
- Business logic is organized into model classes in app/Models/: Post, Category, Page, User, Contact, and Setting.
- These models represent the system’s main data domains: blog content, taxonomy, static pages, users/auth, inbox messages, and site configuration.
- Most page scripts appear to be thin controllers that call into these models and render results.
5. Public site subsystem
- The public-facing site supports a blog feed, individual post view, category-filtered lists, static pages, search, and a contact form.
- Shared layout pieces live in inc/header.php, inc/sidebar.php, inc/footer.php, and inc/slider.php.
- Frontend styling and behavior are in css/ and js/, including Nivo Slider and jQuery-based scripts.
6. Admin CMS subsystem
- The admin area provides the primary content management boundary: post CRUD, category CRUD, page management, slider management, site info edits, social links, and user management.
- There are also inbox/message pages (inbox.php, view_msg.php, reply_msg.php) showing that contact form submissions flow into the admin workflow.
- admin/inc/header.php, sidebar.php, and footer.php define the admin shell.
7. Authentication and user management
- Admin authentication is handled in admin/login.php, with supporting flows for forgotten password and password changes.
- admin/user_list.php, admin/add_user.php, admin/profile.php, and admin/change_password.php show a full account-management path.
- Session state from Session.php is the key boundary for protecting admin routes and preserving logged-in identity.
8. Content editing and rich text
- The admin UI includes a large bundled TinyMCE editor under admin/js/tiny-mce, which is used for rich content creation and editing.
- There are dedicated workflows for image upload and media-enhanced content, especially in post and page editors.
- This strongly affects architecture because content is authored in the admin UI and then rendered directly on the public site.
9. Configuration and environment
- Runtime configuration is split between config/config.php and environment variables in .env / .env.example.
- The README and composer.json indicate use of vlucas/phpdotenv for loading secrets and DB credentials.
- This means database connectivity and site metadata are externally configured rather than hard-coded.
10. Persistence layer and schema
- The application persists data in MySQL/MariaDB, with schema and seed data in db_blg.sql.
- Data entities likely map to tables for posts, categories, pages, users, sliders, settings, contacts, and social links.
- The architecture is database-centric: most application behavior is read/write operations against these tables through the model classes.
11. Asset and presentation boundary
- Frontend and backend presentation are separated into css/, js/, images/, and the corresponding admin/css, admin/js, admin/img trees.
- The admin area bundles several legacy jQuery plugins and UI libraries, which are part of the UI shell rather than business logic.
- Static assets are therefore a major boundary for diagramming: public presentation, admin presentation, and server-side logic are clearly distinct.
12. Key data flows
- Public request → root script → bootstrap/core → model query → template include → HTML response.
- Admin request → login/session guard or action page → model write/read → admin template/UI response.
- Contact form submission is a special flow: public form → Contact model/database → admin inbox/reply workflow.
13. External/runtime boundaries
- The app runs on PHP 8+ with Composer for dependency loading.
- It assumes a traditional Apache/Laragon-style deployment because of the .htaccess structure and PHP file entrypoints.
- The only notable external package is phpdotenv; otherwise, most of the stack is self-contained and locally bundled.
Main entry points: bootstrap.php Bootstrap · Database.php Database · header.php Theme shell · Post.php Content models
Components 24
Public site
Frontend request surface and shared theme includes.
- Home · Main blog feed entry point.
index.php - Post view · Single post display entry point.
post.php - Page view · Static page display entry point.
page.php - Category feed · Category-filtered post listing entry point.
cat_posts.php - Search · Public search results entry point.
search.php - Contact form · Public contact submission endpoint.
contact_us.php - Theme shell · Header, sidebar, footer, and slider composition.
inc/header.php
Admin CMS
Dashboard, auth, and content management surface.
- Dashboard · Admin landing page and control center.
admin/index.php - Login · Administrator sign-in entry point.
admin/login.php - Posts admin · Post list, create, and edit workflows.
admin/post_list.php - Pages admin · Static page management workflows.
admin/page_list.php - Inbox · Message review and reply workflow.
admin/inbox.php - Accounts · User, profile, and password management.
admin/user_list.php - Site config · Site info, titles, slogan, and social settings.
admin/site_info_list.php
Shared app
Bootstrap, core services, helpers, and domain models.
- Bootstrap · Shared application initialization boundary.
app/bootstrap.php - Database · MySQLi connection wrapper.
app/Core/Database.php - Session · Session and auth state management.
app/Core/Session.php - Format · Content formatting and sanitization utilities.
app/Helpers/Format.php - Content models · Post, category, and page persistence logic.
app/Models/Post.php - Identity models · User and session-adjacent account data.
app/Models/User.php - Inbox model · Contact/message persistence and admin workflow support.
app/Models/Contact.php - Settings model · Site configuration and metadata persistence.
app/Models/Setting.php
Data/config
Database schema and environment configuration.
- Env config · Composer-loaded environment secrets and DB settings.
.env - DB schema · MySQL/MariaDB schema and seed data.
db_blg.sql
Connections 32
- Home → Bootstrap: boot · Initializes shared app state before rendering.
- Post view → Bootstrap: boot · Loads shared services and models.
- Page view → Bootstrap: boot · Loads shared services and models.
- Category feed → Bootstrap: boot · Loads shared services and models.
- Search → Bootstrap: boot · Loads shared services and models.
- Contact form → Bootstrap: boot · Loads shared services and models.
- Bootstrap → Database: uses · Creates or accesses the database connection layer.
- Bootstrap → Session: uses · Initializes session and auth handling.
- Bootstrap → Format: uses · Makes formatting and sanitization helpers available.
- Bootstrap → Content models: loads · Wires shared domain models for page controllers.
- Bootstrap → Identity models: loads · Wires shared domain models for auth and profiles.
- Bootstrap → Inbox model: loads · Wires the contact/message domain model.
- Bootstrap → Settings model: loads · Wires settings/configuration model access.
- Home → Theme shell: renders · Composes the public theme shell.
- Post view → Theme shell: renders · Uses shared frontend layout includes.
- Page view → Theme shell: renders · Uses shared frontend layout includes.
- Category feed → Theme shell: renders · Uses shared frontend layout includes.
- Search → Theme shell: renders · Uses shared frontend layout includes.
- Contact form → Inbox model: writes · Stores contact submissions for admin review.
- Dashboard → Session: guards · Requires authenticated admin session state.
- Login → Session: auth · Establishes admin identity in session state.
- Posts admin → Content models: crud · Manages post records through content models.
- Pages admin → Content models: crud · Manages page records through content models.
- Inbox → Inbox model: reads · Reviews and replies to contact submissions.
- Accounts → Identity models: crud · Manages users, profiles, and passwords.
- Site config → Settings model: crud · Edits site-wide configuration records.
- Database → DB schema: persists · Connection layer targets the MySQL schema.
- Env config → Database: configures · Provides credentials and runtime connection settings.
- Content models → Database: queries · Content models read and write through the DB layer.
- Identity models → Database: queries · Identity models read and write through the DB layer.
- Inbox model → Database: queries · Inbox model persists contact messages.
- Settings model → Database: queries · Settings model persists site configuration.