# suhaib-md/myblog architecture

> Architecture diagram of the GitHub repository suhaib-md/myblog, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/suhaib-md/myblog
- Repository: https://github.com/suhaib-md/myblog

## Overview

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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Web Browser\nHTML/CSS"]:::frontend
    end

    %% Web Server & Application Layer
    subgraph "Web Server & Application"
        APACHE["Apache + PHP 7.4+"]:::server
        DBCONFIG["Configuration Layer\nconfig/db.php"]:::server
        AUTH["Authentication Middleware\nincludes/auth.php"]:::server
        CONT_INDEX["Home Page Controller\nindex.php"]:::server
        CONT_REGISTER["User Registration Controller\nregister.php"]:::server
        CONT_LOGIN["User Login Controller\nlogin.php"]:::server
        CONT_LOGOUT["User Logout Controller\nlogout.php"]:::server
        CONT_DASH["User Dashboard Controller\ndashboard.php"]:::server
        CONT_CREATE["Create Post Controller\ncreate_post.php"]:::server
        CONT_EDIT["Edit Post Controller\nedit_post.php"]:::server
        CONT_DELETE["Delete Post Controller\ndelete_post.php"]:::server
        VIEW_NAV["Navigation View Template\nincludes/navbar.php"]:::server
        VIEW_FOOT["Footer View Template\nincludes/footer.php"]:::server
        DOCUMENT["Project Documentation\nREADME.md"]:::server
    end

    %% Data Storage Layer
    subgraph "Data Storage Layer"
        MYSQL["MySQL Database\n(users, posts)"]:::database
        UPLOADS["Uploaded Images Storage\nuploads/"]:::database
    end

    %% Interactions
    Browser -->|HTTP Request| APACHE
    APACHE -->|loads| DBCONFIG
    APACHE -->|loads| AUTH
    APACHE -->|routes to| CONT_INDEX
    APACHE -->|routes to| CONT_REGISTER
    APACHE -->|routes to| CONT_LOGIN
    APACHE -->|routes to| CONT_LOGOUT
    APACHE -->|routes to| CONT_DASH
    APACHE -->|routes to| CONT_CREATE
    APACHE -->|routes to| CONT_EDIT
    APACHE -->|routes to| CONT_DELETE

    CONT_INDEX -->|includes| VIEW_NAV
    CONT_INDEX -->|includes| VIEW_FOOT
    CONT_REGISTER -->|includes| VIEW_NAV
    CONT_REGISTER -->|includes| VIEW_FOOT
    CONT_LOGIN -->|includes| VIEW_NAV
    CONT_LOGIN -->|includes| VIEW_FOOT
    CONT_LOGOUT -->|includes| VIEW_NAV
    CONT_LOGOUT -->|includes| VIEW_FOOT
    CONT_DASH -->|includes| VIEW_NAV
    CONT_DASH -->|includes| VIEW_FOOT
    CONT_CREATE -->|includes| VIEW_NAV
    CONT_CREATE -->|includes| VIEW_FOOT
    CONT_EDIT -->|includes| VIEW_NAV
    CONT_EDIT -->|includes| VIEW_FOOT
    CONT_DELETE -->|includes| VIEW_NAV
    CONT_DELETE -->|includes| VIEW_FOOT

    CONT_INDEX -->|queries| MYSQL
    CONT_REGISTER -->|writes| MYSQL
    CONT_LOGIN -->|queries| MYSQL
    CONT_LOGOUT -->|updates session| MYSQL
    CONT_DASH -->|queries| MYSQL
    CONT_CREATE -->|writes| MYSQL
    CONT_EDIT -->|updates| MYSQL
    CONT_DELETE -->|deletes| MYSQL

    CONT_CREATE -->|uploads file| UPLOADS
    UPLOADS -->|served by| APACHE

    DOCUMENT -->|describes architecture| APACHE

    %% Click Events
    click DBCONFIG "https://github.com/suhaib-md/myblog/blob/main/config/db.php"
    click AUTH "https://github.com/suhaib-md/myblog/blob/main/includes/auth.php"
    click CONT_INDEX "https://github.com/suhaib-md/myblog/blob/main/index.php"
    click CONT_REGISTER "https://github.com/suhaib-md/myblog/blob/main/register.php"
    click CONT_LOGIN "https://github.com/suhaib-md/myblog/blob/main/login.php"
    click CONT_LOGOUT "https://github.com/suhaib-md/myblog/blob/main/logout.php"
    click CONT_DASH "https://github.com/suhaib-md/myblog/blob/main/dashboard.php"
    click CONT_CREATE "https://github.com/suhaib-md/myblog/blob/main/create_post.php"
    click CONT_EDIT "https://github.com/suhaib-md/myblog/blob/main/edit_post.php"
    click CONT_DELETE "https://github.com/suhaib-md/myblog/blob/main/delete_post.php"
    click VIEW_NAV "https://github.com/suhaib-md/myblog/blob/main/includes/navbar.php"
    click VIEW_FOOT "https://github.com/suhaib-md/myblog/blob/main/includes/footer.php"
    click UPLOADS "https://github.com/suhaib-md/myblog/tree/main/uploads/"

    %% Styles
    classDef frontend fill:#a2fca2,stroke:#333,stroke-width:1px
    classDef server fill:#7faaff,stroke:#333,stroke-width:1px
    classDef database fill:#ffcc66,stroke:#333,stroke-width:1px
```
