# mhannan-dev/php-blog architecture

> Architecture diagram of the GitHub repository mhannan-dev/php-blog, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mhannan-dev/php-blog
- Repository: https://github.com/mhannan-dev/php-blog

## Overview

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: [`app/bootstrap.php`](https://github.com/mhannan-dev/php-blog/blob/master/app/bootstrap.php) (Bootstrap), [`app/Core/Database.php`](https://github.com/mhannan-dev/php-blog/blob/master/app/Core/Database.php) (Database), [`inc/header.php`](https://github.com/mhannan-dev/php-blog/blob/master/inc/header.php) (Theme shell), [`app/Models/Post.php`](https://github.com/mhannan-dev/php-blog/blob/master/app/Models/Post.php) (Content models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public site"]
  node_index_php["Home<br/>public entry<br/>[index.php]"]
  node_post_php["Post view<br/>public entry<br/>[post.php]"]
  node_page_php["Page view<br/>public entry<br/>[page.php]"]
  node_cat_posts_php["Category feed<br/>public entry<br/>[cat_posts.php]"]
  node_search_php["Search<br/>public entry<br/>[search.php]"]
  node_contact_us_php["Contact form<br/>public entry<br/>[contact_us.php]"]
  node_inc_layout["Theme shell<br/>public layout<br/>[header.php]"]
end

subgraph group_admin["Admin CMS"]
  node_admin_index_php["Dashboard<br/>admin hub<br/>[index.php]"]
  node_admin_login_php["Login<br/>admin auth<br/>[login.php]"]
  node_admin_posts["Posts admin<br/>admin content<br/>[post_list.php]"]
  node_admin_pages["Pages admin<br/>admin content<br/>[page_list.php]"]
  node_admin_messages["Inbox<br/>admin workflow<br/>[inbox.php]"]
  node_admin_accounts["Accounts<br/>admin workflow<br/>[user_list.php]"]
  node_admin_settings["Site config<br/>admin settings<br/>[site_info_list.php]"]
end

subgraph group_shared["Shared app"]
  node_bootstrap_php["Bootstrap<br/>[bootstrap.php]"]
  node_db_core[("Database<br/>core service<br/>[Database.php]")]
  node_session_core(("Session<br/>core service<br/>[Session.php]"))
  node_format_helper["Format<br/>helper<br/>[Format.php]"]
  node_models_content["Content models<br/>domain models<br/>[Post.php]"]
  node_models_identity["Identity models<br/>domain models<br/>[User.php]"]
  node_models_inbox["Inbox model<br/>domain model<br/>[Contact.php]"]
  node_models_config["Settings model<br/>domain model<br/>[Setting.php]"]
end

subgraph group_data["Data/config"]
  node_env_config["Env config<br/>runtime config<br/>[.env]"]
  node_schema_sql[("DB schema<br/>database schema<br/>[db_blg.sql]")]
end

node_index_php -->|"boot"| node_bootstrap_php
node_post_php -->|"boot"| node_bootstrap_php
node_page_php -->|"boot"| node_bootstrap_php
node_cat_posts_php -->|"boot"| node_bootstrap_php
node_search_php -->|"boot"| node_bootstrap_php
node_contact_us_php -->|"boot"| node_bootstrap_php
node_bootstrap_php -->|"uses"| node_db_core
node_bootstrap_php -->|"uses"| node_session_core
node_bootstrap_php -->|"uses"| node_format_helper
node_bootstrap_php -->|"loads"| node_models_content
node_bootstrap_php -->|"loads"| node_models_identity
node_bootstrap_php -->|"loads"| node_models_inbox
node_bootstrap_php -->|"loads"| node_models_config
node_index_php -->|"renders"| node_inc_layout
node_post_php -->|"renders"| node_inc_layout
node_page_php -->|"renders"| node_inc_layout
node_cat_posts_php -->|"renders"| node_inc_layout
node_search_php -->|"renders"| node_inc_layout
node_contact_us_php -->|"writes"| node_models_inbox
node_admin_index_php -->|"guards"| node_session_core
node_admin_login_php -->|"auth"| node_session_core
node_admin_posts -->|"crud"| node_models_content
node_admin_pages -->|"crud"| node_models_content
node_admin_messages -->|"reads"| node_models_inbox
node_admin_accounts -->|"crud"| node_models_identity
node_admin_settings -->|"crud"| node_models_config
node_db_core -->|"persists"| node_schema_sql
node_env_config -->|"configures"| node_db_core
node_models_content -->|"queries"| node_db_core
node_models_identity -->|"queries"| node_db_core
node_models_inbox -->|"queries"| node_db_core
node_models_config -->|"queries"| node_db_core

click node_index_php "https://github.com/mhannan-dev/php-blog/blob/master/index.php"
click node_post_php "https://github.com/mhannan-dev/php-blog/blob/master/post.php"
click node_page_php "https://github.com/mhannan-dev/php-blog/blob/master/page.php"
click node_cat_posts_php "https://github.com/mhannan-dev/php-blog/blob/master/cat_posts.php"
click node_search_php "https://github.com/mhannan-dev/php-blog/blob/master/search.php"
click node_contact_us_php "https://github.com/mhannan-dev/php-blog/blob/master/contact_us.php"
click node_inc_layout "https://github.com/mhannan-dev/php-blog/blob/master/inc/header.php"
click node_admin_index_php "https://github.com/mhannan-dev/php-blog/blob/master/admin/index.php"
click node_admin_login_php "https://github.com/mhannan-dev/php-blog/blob/master/admin/login.php"
click node_admin_posts "https://github.com/mhannan-dev/php-blog/blob/master/admin/post_list.php"
click node_admin_pages "https://github.com/mhannan-dev/php-blog/blob/master/admin/page_list.php"
click node_admin_messages "https://github.com/mhannan-dev/php-blog/blob/master/admin/inbox.php"
click node_admin_accounts "https://github.com/mhannan-dev/php-blog/blob/master/admin/user_list.php"
click node_admin_settings "https://github.com/mhannan-dev/php-blog/blob/master/admin/site_info_list.php"
click node_bootstrap_php "https://github.com/mhannan-dev/php-blog/blob/master/app/bootstrap.php"
click node_db_core "https://github.com/mhannan-dev/php-blog/blob/master/app/Core/Database.php"
click node_session_core "https://github.com/mhannan-dev/php-blog/blob/master/app/Core/Session.php"
click node_format_helper "https://github.com/mhannan-dev/php-blog/blob/master/app/Helpers/Format.php"
click node_models_content "https://github.com/mhannan-dev/php-blog/blob/master/app/Models/Post.php"
click node_models_identity "https://github.com/mhannan-dev/php-blog/blob/master/app/Models/User.php"
click node_models_inbox "https://github.com/mhannan-dev/php-blog/blob/master/app/Models/Contact.php"
click node_models_config "https://github.com/mhannan-dev/php-blog/blob/master/app/Models/Setting.php"
click node_env_config "https://github.com/mhannan-dev/php-blog/blob/master/.env"
click node_schema_sql "https://github.com/mhannan-dev/php-blog/blob/master/db_blg.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_index_php,node_post_php,node_page_php,node_cat_posts_php,node_search_php,node_contact_us_php,node_inc_layout toneBlue
class node_admin_index_php,node_admin_login_php,node_admin_posts,node_admin_pages,node_admin_messages,node_admin_accounts,node_admin_settings toneAmber
class node_bootstrap_php,node_db_core,node_session_core,node_format_helper,node_models_content,node_models_identity,node_models_inbox,node_models_config toneMint
class node_env_config,node_schema_sql toneRose
```

## Components

### Public site

Frontend request surface and shared theme includes.

- [Home](https://github.com/mhannan-dev/php-blog/blob/master/index.php): public entry · Main blog feed entry point. · `index.php`
- [Post view](https://github.com/mhannan-dev/php-blog/blob/master/post.php): public entry · Single post display entry point. · `post.php`
- [Page view](https://github.com/mhannan-dev/php-blog/blob/master/page.php): public entry · Static page display entry point. · `page.php`
- [Category feed](https://github.com/mhannan-dev/php-blog/blob/master/cat_posts.php): public entry · Category-filtered post listing entry point. · `cat_posts.php`
- [Search](https://github.com/mhannan-dev/php-blog/blob/master/search.php): public entry · Public search results entry point. · `search.php`
- [Contact form](https://github.com/mhannan-dev/php-blog/blob/master/contact_us.php): public entry · Public contact submission endpoint. · `contact_us.php`
- [Theme shell](https://github.com/mhannan-dev/php-blog/blob/master/inc/header.php): public layout · Header, sidebar, footer, and slider composition. · `inc/header.php`

### Admin CMS

Dashboard, auth, and content management surface.

- [Dashboard](https://github.com/mhannan-dev/php-blog/blob/master/admin/index.php): admin hub · Admin landing page and control center. · `admin/index.php`
- [Login](https://github.com/mhannan-dev/php-blog/blob/master/admin/login.php): admin auth · Administrator sign-in entry point. · `admin/login.php`
- [Posts admin](https://github.com/mhannan-dev/php-blog/blob/master/admin/post_list.php): admin content · Post list, create, and edit workflows. · `admin/post_list.php`
- [Pages admin](https://github.com/mhannan-dev/php-blog/blob/master/admin/page_list.php): admin content · Static page management workflows. · `admin/page_list.php`
- [Inbox](https://github.com/mhannan-dev/php-blog/blob/master/admin/inbox.php): admin workflow · Message review and reply workflow. · `admin/inbox.php`
- [Accounts](https://github.com/mhannan-dev/php-blog/blob/master/admin/user_list.php): admin workflow · User, profile, and password management. · `admin/user_list.php`
- [Site config](https://github.com/mhannan-dev/php-blog/blob/master/admin/site_info_list.php): admin settings · Site info, titles, slogan, and social settings. · `admin/site_info_list.php`

### Shared app

Bootstrap, core services, helpers, and domain models.

- [Bootstrap](https://github.com/mhannan-dev/php-blog/blob/master/app/bootstrap.php): app bootstrap · Shared application initialization boundary. · `app/bootstrap.php`
- [Database](https://github.com/mhannan-dev/php-blog/blob/master/app/Core/Database.php): core service · MySQLi connection wrapper. · `app/Core/Database.php`
- [Session](https://github.com/mhannan-dev/php-blog/blob/master/app/Core/Session.php): core service · Session and auth state management. · `app/Core/Session.php`
- [Format](https://github.com/mhannan-dev/php-blog/blob/master/app/Helpers/Format.php): helper · Content formatting and sanitization utilities. · `app/Helpers/Format.php`
- [Content models](https://github.com/mhannan-dev/php-blog/blob/master/app/Models/Post.php): domain models · Post, category, and page persistence logic. · `app/Models/Post.php`
- [Identity models](https://github.com/mhannan-dev/php-blog/blob/master/app/Models/User.php): domain models · User and session-adjacent account data. · `app/Models/User.php`
- [Inbox model](https://github.com/mhannan-dev/php-blog/blob/master/app/Models/Contact.php): domain model · Contact/message persistence and admin workflow support. · `app/Models/Contact.php`
- [Settings model](https://github.com/mhannan-dev/php-blog/blob/master/app/Models/Setting.php): domain model · Site configuration and metadata persistence. · `app/Models/Setting.php`

### Data/config

Database schema and environment configuration.

- [Env config](https://github.com/mhannan-dev/php-blog/blob/master/.env): runtime config · Composer-loaded environment secrets and DB settings. · `.env`
- [DB schema](https://github.com/mhannan-dev/php-blog/blob/master/db_blg.sql): database schema · MySQL/MariaDB schema and seed data. · `db_blg.sql`

## Connections

- 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.
