# mustafa-kh-hamad/bnka architecture

> Architecture diagram of the GitHub repository mustafa-kh-hamad/bnka, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mustafa-kh-hamad/bnka
- Repository: https://github.com/mustafa-kh-hamad/bnka

## Overview

##### Project type and purpose
- This is a full-stack PHP web application for a memorization center.
- It follows an MVC-like pattern: routing and controllers in `app/HTTP`, business logic in `app/Class`, views in `app/view`, and core bootstrap/config in `core`.

##### File structure
- Top-level:
- `public/` – webroot and static resources
- `core/` – framework bootstrap, routing, autoload, configuration
- `app/Class/` – service classes (Authenticator, Validator, Database, Session, Router), plus middleware
- `app/HTTP/controller/` – controllers organized by resource (classes, dashboard, register, session, etc.)
- `app/view/` – HTML views and components
- Configuration: `core/configuration.php`, `app/Class/Database.php`
- Routing: `core/route.php` → `app/Class/Router.php`
- Middleware: `app/Class/middleware/*` for Auth, Admin, Guest checks

##### Extract architecture hints from README
- Uses PHP server with single entry point (`public/index.php`)
- MySQL database with two tables: `users` (with `classes_id` FK) and `classes`
- Admin and user flows, automatic “Distribute” logic

##### Main components and their interactions
a. Client (browser) – sends HTTP requests, receives HTML/CSS/JS
b. Web server/PHP runtime – front-controller at `public/index.php`
c. Core framework – `core/bootstrap.php` loads autoloader, configures environment
d. Router – `core/route.php` & `app/Class/Router.php` dispatch requests to controllers
e. Middleware – Auth, Admin, Guest interceptors applied per-route
f. Controllers – in `app/HTTP/controller` handle requests, orchestrate services
g. Service classes – `app/Class/Authenticator`, `Validator`, `Database`, `Session`, `ClassesModification`
h. Views – `app/view/` template rendering, components (header, footer)
i. Database – MySQL, accessed via `app/Class/Database.php`
j. Static assets – `public/resources/images/`, Tailwind CSS in the views

##### Architectural patterns & design principles
- MVC-inspired separation: Controllers ↔ Models (service classes) ↔ Views
- Front Controller: single entry (`public/index.php`)
- Dependency Injection via autoload; centralized configuration
- Middleware pipeline for authentication/authorization
- REST-style controllers for CRUD on classes, dashboard, sessions

##### What
- Clear component labels (Core, Router, Middleware, Controllers, Services, Views, DB)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External client
    Browser["Browser<br/>(Client)"]:::external

    %% Web server and front controller
    Browser -->|"HTTP Request"| WebServer["Web Server / PHP Runtime"]:::backend
    WebServer -->|"Includes"| FrontController["public/index.php"]:::backend
    click FrontController "https://github.com/mustafa-kh-hamad/bnka/blob/main/public/index.php"

    %% Core bootstrap and config
    FrontController --> CoreBootstrap["Core Bootstrap"]:::backend
    click CoreBootstrap "https://github.com/mustafa-kh-hamad/bnka/blob/main/core/bootstrap.php"
    CoreBootstrap --> Autoloader["Autoloader"]:::backend
    click Autoloader "https://github.com/mustafa-kh-hamad/bnka/blob/main/core/autoload.php"
    CoreBootstrap --> Configuration["Configuration"]:::backend
    click Configuration "https://github.com/mustafa-kh-hamad/bnka/blob/main/core/configuration.php"

    %% Routing setup and router
    CoreBootstrap --> RoutingSetup["Routing Setup"]:::backend
    click RoutingSetup "https://github.com/mustafa-kh-hamad/bnka/blob/main/core/route.php"
    RoutingSetup --> RouterClass["Router"]:::backend
    click RouterClass "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/Class/Router.php"

    %% Middleware pipeline
    RouterClass --> MiddlewareBase["Middleware Base"]:::middleware
    click MiddlewareBase "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/Class/middleware/Middleware.php"
    MiddlewareBase --> AuthMiddleware["Auth Middleware"]:::middleware
    click AuthMiddleware "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/Class/middleware/Auth.php"
    MiddlewareBase --> AdminMiddleware["Admin Middleware"]:::middleware
    click AdminMiddleware "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/Class/middleware/Admin.php"
    MiddlewareBase --> GuestMiddleware["Guest Middleware"]:::middleware
    click GuestMiddleware "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/Class/middleware/Guest.php"

    %% Controllers
    RouterClass --> ControllersGroup["Controllers"]:::backend
    subgraph Controllers
        direction TB
        RootControllers["Root Controllers"]:::backend
        SessionControllers["Session Controllers"]:::backend
        RegisterControllers["Register Controllers"]:::backend
        ClassesControllers["Classes Controllers"]:::backend
        DashboardControllers["Dashboard Controllers"]:::backend
    end
    click RootControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/index.php"
    click RootControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/about.php"
    click RootControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/search.php"
    click SessionControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/session/index.php"
    click SessionControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/session/store.php"
    click SessionControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/session/destroy.php"
    click RegisterControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/register/index.php"
    click RegisterControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/register/store.php"
    click ClassesControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/classes/index.php"
    click ClassesControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/classes/show.php"
    click ClassesControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/classes/show-edit.php"
    click ClassesControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/classes/store.php"
    click ClassesControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/classes/edit.php"
    click ClassesControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/classes/destroy.php"
    click DashboardControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/dashbord/index.php"
    click DashboardControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/dashbord/show.php"
    click DashboardControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/dashbord/distribute.php"
    click DashboardControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/dashbord/edit.php"
    click DashboardControllers "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/HTTP/controller/dashbord/destroy.php"

    %% Services and database
    ControllersGroup --> ServicesGroup["Service Classes"]:::backend
    subgraph Services
        direction TB
        AuthService["Authenticator"]:::backend
        ValidateService["Validator"]:::backend
        DBService["Database Service"]:::backend
        SessionService["Session Service"]:::backend
        ClassesModService["ClassesModification"]:::backend
    end
    click AuthService "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/Class/Authenticator.php"
    click ValidateService "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/Class/Validator.php"
    click DBService "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/Class/Database.php"
    click SessionService "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/Class/Session.php"
    click ClassesModService "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/Class/ClassesModification.php"

    ServicesGroup --> DB["MySQL Database"]:::database
    DBService --> DB

    %% Views and response
    ControllersGroup --> ViewsGroup["View Renderer"]:::frontend
    subgraph Views
        direction TB
        GlobalViews["Global Views"]:::frontend
        ClassesViews["Classes Views"]:::frontend
        DashboardViews["Dashboard Views"]:::frontend
        SessionViews["Session Views"]:::frontend
        RegisterViews["Register Views"]:::frontend
        SharedComponents["Shared View Components"]:::frontend
    end
    click GlobalViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/index.view.php"
    click GlobalViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/about.view.php"
    click GlobalViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/search.view.php"
    click GlobalViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/403.view.php"
    click GlobalViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/404.view.php"
    click ClassesViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/classes/index.view.php"
    click ClassesViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/classes/show.view.php"
    click ClassesViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/classes/show-edit.view.php"
    click DashboardViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/dashbord/index.view.php"
    click DashboardViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/dashbord/show.view.php"
    click SessionViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/session/index.view.php"
    click RegisterViews "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/register/index.view.php"
    click SharedComponents "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/components/heading.view.php"
    click SharedComponents "https://github.com/mustafa-kh-hamad/bnka/blob/main/app/view/components/footer.view.php"

    ViewsGroup --> Browser

    %% Static assets
    Static["Static Assets<br/>(Images)"]:::frontend
    click Static "https://github.com/mustafa-kh-hamad/bnka/tree/main/public/resources/images/"

    %% Styles
    classDef backend fill:#D0E8FF,stroke:#0366d6,stroke-width:1px
    classDef frontend fill:#E6FFEA,stroke:#1f8f00,stroke-width:1px
    classDef database fill:#FFE5B4,stroke:#d2691e,stroke-width:1px
    classDef middleware fill:#F5E6FF,stroke:#9370DB,stroke-width:1px
    classDef external fill:#F0F0F0,stroke:#999999,stroke-width:1px,stroke-dasharray: 2 2
```
