# halofie/knf architecture

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

- Interactive diagram: https://gitdiagram.com/halofie/knf
- Repository: https://github.com/halofie/knf

## Overview

##### Project type and purpose
- The “knft” folder contains the core business logic and CRUD endpoints; “public” holds all front-end assets; “login”, “admin”, “consumer”, “producer” folders contain role-specific views.

##### File structure
- Top-level folders:
- knft – PHP scripts (API endpoints, business logic).
- public – Static assets (CSS, JS, images).
- admin, consumer, producer – Role-specific HTML/PHP pages.
- login – Authentication UI.
- vendor – Composer packages.
- Key configuration: composer.json/composer.lock for dependencies.
- No separate “src” or microservices: it’s a single PHP codebase served by one web server (e.g., Apache/Nginx+PHP-FPM).

##### README
- Minimal content; no additional architecture notes. All architectural insight must come from file layout.

##### Diagramming the system architecture
a. Main components
1. Clients (Web Browsers)
2. Web Server (Apache/Nginx + PHP-FPM)
3. PHP Application
– Presentation layer: “public” assets + role views (login/, admin/, consumer/, producer/)
– Controller/Service layer: knft/*.php (authenticate.php, submitOrder.php, getCustomer.php, etc.)
– Data-access layer: knft scripts interacting with the Database
4. Database (MySQL/PostgreSQL)
5. External services/dependencies
– Composer/vendor libraries
– File transfer (knft/transferFile.php)
b. Relationships and interactions
- Browser → HTTP request for HTML or assets → Web Server
- Web Server routes static requests to “public” folder; PHP requests to dispatcher (e.g., index.php or direct script URLs)
- PHP scripts in “knft” handle business logic: read/write to Database, perform authentication, hash passwords, manage inventory/orders/customers/routes/suppliers.
- Responses (HTML, JSON, redirects) flow back to the browser.
- Composer/vendor code is autoloaded by PHP at runtime.
c. Architectural patterns/design principles
- Layered architecture: Presentation → Business logic → Data Access
- Role-based modules (Admin, Consumer, Producer) share common business logic in knft/
- Lightweight endpoint style (each PHP file is a single endpoint)
d. Key technologies
– PHP 7/8, Composer for dependency management
– HTML/CSS/JavaScript on the front end
– jQuery and custom JS scripts for dynamic UI
– MySQL or equivalent relational database

## Diagram (Mermaid)

```mermaid
flowchart TB
    Browser["Browser"]:::ui
    WebServer["Web Server\n(Apache/Nginx + PHP-FPM)"]:::server
    Browser -->|GET/POST| WebServer

    subgraph "Presentation Layer"
        Public["Static Assets\n(public/)"]:::ui
        Login["Login Module\n(login/login.html)"]:::ui
        AdminView["Admin View\n(admin/adminfr.php)"]:::ui
        ConsumerDashboard["Consumer Dashboard\n(consumer/customer_dashboard.php)"]:::ui
        ConsumerOrder["Consumer Order\n(consumer/orderfr.php)"]:::ui
        ProducerAddInv["Producer Inventory\n(producer/addinv.html)"]:::ui
    end

    WebServer -->|Static file fetch| Public
    WebServer -->|Route to views| Login
    WebServer --> AdminView
    WebServer --> ConsumerDashboard
    WebServer --> ConsumerOrder
    WebServer --> ProducerAddInv

    subgraph "Service Layer (knft)"
        Auth["Authentication\n(knft/authenticate.php)"]:::service
        OD1["submitOrder.php"]:::service
        OD2["getConsumerpurchaseHistory.php"]:::service
        OD3["getOrderFullfill.php"]:::service
        OD4["printorder.php"]:::service
        IM1["submitINV.php"]:::service
        IM2["getInv.php"]:::service
        IM3["loadTempInventory.php"]:::service
        IM4["removeQuantity.php"]:::service
        UCM1["submitCustomer.php"]:::service
        UCM2["getCustomer.php"]:::service
        UCM3["deleteCustomer.php"]:::service
        UCM4["editCustomer.php"]:::service
        PCM1["submitProduct.php"]:::service
        PCM2["getProduct.php"]:::service
        PCM3["submitCategory.php"]:::service
        PCM4["getCategory.php"]:::service
        SRM1["submitSupplier.php"]:::service
        SRM2["getSupplier.php"]:::service
        SRM3["submitRoute.php"]:::service
        SRM4["getRoutes.php"]:::service
        Helpers["Shared Helpers\n(header.php, hash.php,\nlogout.php)"]:::service
        Composer["Composer/Vendor\n(composer.json, composer.lock,\nvendor/)"]:::external
    end

    WebServer -->|Execute PHP scripts| Auth
    Auth -->|uses Helpers| Helpers
    Auth -->|autoloads| Composer

    Auth -->|SQL queries| DB
    OD1 -->|SQL queries| DB
    OD2 -->|SQL queries| DB
    OD3 -->|SQL queries| DB
    OD4 -->|SQL queries| DB
    IM1 -->|SQL queries| DB
    IM2 -->|SQL queries| DB
    IM3 -->|SQL queries| DB
    IM4 -->|SQL queries| DB
    UCM1 -->|SQL queries| DB
    UCM2 -->|SQL queries| DB
    UCM3 -->|SQL queries| DB
    UCM4 -->|SQL queries| DB
    PCM1 -->|SQL queries| DB
    PCM2 -->|SQL queries| DB
    PCM3 -->|SQL queries| DB
    PCM4 -->|SQL queries| DB
    SRM1 -->|SQL queries| DB
    SRM2 -->|SQL queries| DB
    SRM3 -->|SQL queries| DB
    SRM4 -->|SQL queries| DB

    DB["Database\n(MySQL/PostgreSQL)"]:::db

    click Public "https://github.com/halofie/knf/tree/main/public/"
    click Login "https://github.com/halofie/knf/blob/main/login/login.html"
    click AdminView "https://github.com/halofie/knf/blob/main/admin/adminfr.php"
    click ConsumerDashboard "https://github.com/halofie/knf/blob/main/consumer/customer_dashboard.php"
    click ConsumerOrder "https://github.com/halofie/knf/blob/main/consumer/orderfr.php"
    click ProducerAddInv "https://github.com/halofie/knf/blob/main/producer/addinv.html"
    click Auth "https://github.com/halofie/knf/blob/main/knft/authenticate.php"
    click OD1 "https://github.com/halofie/knf/blob/main/knft/submitOrder.php"
    click OD2 "https://github.com/halofie/knf/blob/main/knft/getConsumerpurchaseHistory.php"
    click OD3 "https://github.com/halofie/knf/blob/main/knft/getOrderFullfill.php"
    click OD4 "https://github.com/halofie/knf/blob/main/knft/printorder.php"
    click IM1 "https://github.com/halofie/knf/blob/main/knft/submitINV.php"
    click IM2 "https://github.com/halofie/knf/blob/main/knft/getInv.php"
    click IM3 "https://github.com/halofie/knf/blob/main/knft/loadTempInventory.php"
    click IM4 "https://github.com/halofie/knf/blob/main/knft/removeQuantity.php"
    click UCM1 "https://github.com/halofie/knf/blob/main/knft/submitCustomer.php"
    click UCM2 "https://github.com/halofie/knf/blob/main/knft/getCustomer.php"
    click UCM3 "https://github.com/halofie/knf/blob/main/knft/deleteCustomer.php"
    click UCM4 "https://github.com/halofie/knf/blob/main/knft/editCustomer.php"
    click PCM1 "https://github.com/halofie/knf/blob/main/knft/submitProduct.php"
    click PCM2 "https://github.com/halofie/knf/blob/main/knft/getProduct.php"
    click PCM3 "https://github.com/halofie/knf/blob/main/knft/submitCategory.php"
    click PCM4 "https://github.com/halofie/knf/blob/main/knft/getCategory.php"
    click SRM1 "https://github.com/halofie/knf/blob/main/knft/submitSupplier.php"
    click SRM2 "https://github.com/halofie/knf/blob/main/knft/getSupplier.php"
    click SRM3 "https://github.com/halofie/knf/blob/main/knft/submitRoute.php"
    click SRM4 "https://github.com/halofie/knf/blob/main/knft/getRoutes.php"
    click Helpers "https://github.com/halofie/knf/blob/main/knft/header.php"
    click Composer "https://github.com/halofie/knf/blob/main/knft/composer.json"

    classDef ui fill:#D0E8FF,stroke:#049ED7,color:#000
    classDef server fill:#E0E0E0,stroke:#888888,color:#000
    classDef service fill:#DFFFD0,stroke:#9CBA7F,color:#000
    classDef db fill:#FFE4B3,stroke:#E29A2C,color:#000
    classDef external fill:#F0F0F0,stroke-dasharray: 5 5,stroke:#666666,color:#000
```
