# honghongk/mylib architecture

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

- Interactive diagram: https://gitdiagram.com/honghongk/mylib
- Repository: https://github.com/honghongk/mylib

## Overview

##### Project type and purpose
- Full-stack utility framework and toolkit, centered on PHP.
- Provides a reusable PHP core library (API, DB abstraction, HTTP, Filesystem, Middleware, Protocols).
- Ships with frontend assets (CSS, JS), CLI tools, Python scripts, shell/Windows scripts.
- Includes Dockerfile definitions and Kubernetes manifests for containerized deployment.
- Use cases: build and deploy PHP-based web applications, automate ops tasks, integrate with external services (Mattermost, Slack).

##### File structure
- Top-level directories:
– css, js: frontend styling and behavior modules
– php: core backend library organized by subsystem (API, DB, HTTP, Filesystem, Middleware, etc.)
– python: auxiliary daemons and scripts for socket, alarm, Creon API, filesystem tasks
– shell, window: OS-level scripts for install, monitoring, backup, certs, port-forwarding
– docker: multi-flavor container recipes (Apache, PHP-FPM, MariaDB, APM, dev)
– k8s: Kubernetes manifests for cluster setup (MariaDB/Galera, Redis/Predixy, nginx+php)
– test: unit/integration examples for PHP and Python components
- Configuration and deployment files: Dockerfiles, shell pods, k8s yamls, iptables, regex.yaml

##### README
- (No content provided) — rely entirely on structure and naming conventions to infer architecture

##### Main components and their interactions
a. Presentation layer
– Browser runs HTML pages referencing css/*.css and js/*.js
– JS modules (dragdrop, excel, tree, upload, validate) call backend via HTTP/REST
b. Web/API layer
– HTTP server (Apache or nginx + php-fpm) hosts Router → Handler → Middleware → PHP controllers
– Route dispatches requests to API modules (php/API), CLI commands (php/CLI) or Script entrypoints
c. Application/core layer
– Core services in php/ (Logger, URL, Str, Time, Calc, Client, Protocol)
– DB abstraction (php/DB/MySQL) communicates with MariaDB/MySQL over TCP
– Filesystem abstraction (php/Filesystem) manages storage of JSON, Excel, images, videos, zips
– Middleware components manage CSRF, Throttle, Validation
d. Data layer
– Relational database: MariaDB/Galera (stateful set)
– Cache: Redis (stand-alone or Predixy proxy)
– File storage: local or mounted volumes
– External services: Mattermost (php/API/Mattermost), Solr or other HTTP endpoints via php/Protocol/Http
e. Auxiliary components
– CLI tools: invoked by operators or cron (php/CLI/Process)
– Python daemons and scripts for socket comms, alarms, custom tasks
– Shell scripts for installation, monitoring, backups, certificate management
– Windows scripts for local development or port-forwarding

##### Infrastructure and deployment
- Containers: multiple Docker images for each role (centos7-apache, php-fpm, mariadb, apm, dev)
- Orchestration: Kubernetes manifests group services into logical clusters
- Networking: iptables rules, k8s services, ingress (nginx-php.yaml), port-forwarding
- CI/CD could mount tests and run python/test_request.py, test_server.py, php tests

##### Architectural patterns and design principles
- Layered architecture: Presentation → Application → Domain/Core → Data
- Modularity: each subsystem in its own directory, adhering to single-responsibility
- Abstraction: filesystem and database layered behind interfaces
- Containerization: isolates each service, promotes repeatable deployments
- Infrastructure-as-code: all deploy and config scripts versioned

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients and Presentation
    User["User/Browser"]:::client
    subgraph "Presentation Layer"
        CSS["CSS Files"]:::static
        JS["JS Files"]:::static
    end
    User -->|HTTP/HTTPS| CSS
    User -->|HTTP/HTTPS| JS

    %% Web/API Layer
    CSS -->|loads static assets| HTTP["HTTP Server<br/>(Apache/nginx + PHP-FPM)"]:::server
    JS -->|AJAX/REST calls| HTTP
    HTTP -->|"dispatch"| Router
    Router["Router<br/>(php/Route.php)"]:::backend
    Router --> Handler
    Handler["Handler<br/>(php/Handler.php)"]:::backend
    Handler --> MiddlewareInterface
    subgraph "Middleware Layer"
        MiddlewareInterface["MiddlewareInterface.php"]:::backend
        CSRF["CSRF.php"]:::backend
        Throttle["Throttle.php"]:::backend
        Validate["Validate.php"]:::backend
    end
    MiddlewareInterface --> CSRF
    MiddlewareInterface --> Throttle
    MiddlewareInterface --> Validate
    CSRF -->|"passes"| Controllers
    Throttle -->|"passes"| Controllers
    Validate -->|"passes"| Controllers

    subgraph "Controllers"
        API["API Module<br/>(Mattermost)"]:::backend
        CLI["CLI Tool<br/>(Process)"]:::backend
    end
    CSRF --> API
    Throttle --> API
    Validate --> API
    CLI -- cron/operator --> Core

    %% Core Services
    subgraph "Core Services" 
        direction TB
        Utils["Utility Services"]:::util
        HTTPClient["HTTP Abstractions"]:::util
        DBModule["DB Abstraction (MySQL)"]:::util
        FSModule["Filesystem Abstraction"]:::util
        Protocol["Protocol Clients"]:::util
    end
    Controllers -->|calls| Utils
    Controllers -->|HTTP calls| HTTPClient
    Controllers -->|DB queries| DBModule
    Controllers -->|file ops| FSModule
    Controllers -->|external protocols| Protocol

    %% Utility Services Details
    subgraph UtilsDetails["Utility Services Modules"]
        Logger["Logger.php"]:::util
        URL["URL.php"]:::util
        Str["Str.php"]:::util
        Time["Time.php"]:::util
        Calc["Calc.php"]:::util
        Arr["Arr.php"]:::util
        ExcelUtil["phpexcel_replace.php"]:::util
    end
    Utils --> Logger & URL & Str & Time & Calc & Arr & ExcelUtil

    %% HTTP Abstraction Details
    subgraph HTTPDetails["HTTP Abstraction Modules"]
        Req["Request.php"]:::util
        Res["Response.php"]:::util
        Curl["Curl.php"]:::util
        Cookie["Cookie.php"]:::util
        Session["Session.php"]:::util
    end
    HTTPClient --> Req & Res & Curl & Cookie & Session

    %% DB Abstraction Details
    subgraph DBDetails["DB Abstraction Modules"]
        MySQLi["MySQLi.php"]:::util
        Query["Query.php"]:::util
        Stmt["Statement.php"]:::util
        Dep["Dependency.php"]:::util
        Dump["Dump.php"]:::util
        TestDB["Test.php"]:::util
    end
    DBModule --> MySQLi & Query & Stmt & Dep & Dump & TestDB

    %% Filesystem Details
    subgraph FSDetails["Filesystem Modules"]
        AbstractFS["AbstractFS.php"]:::util
        FileMod["File.php"]:::util
        Folder["Folder.php"]:::util
        Json["Json.php"]:::util
        ExcelFS["Excel.php"]:::util
        Image["Image.php"]:::util
        Video["Video.php"]:::util
        ZipMod["Zip.php"]:::util
        Storage["Storage.php"]:::util
        FSEx["FilesystemException.php"]:::util
    end
    FSModule --> AbstractFS & FileMod & Folder & Json & ExcelFS & Image & Video & ZipMod & Storage & FSEx

    %% Protocol Clients
    subgraph ProtocolDetails["Protocol Clients"]
        HTTPProto["Http.php"]:::util
        EmailProto["Email.php"]:::util
        Sendmail["Sendmail.php"]:::util
    end
    Protocol --> HTTPProto & EmailProto & Sendmail

    %% Data Layer
    subgraph "Data Layer"
        DBStore["MariaDB/Galera<br/>(MySQL:3306)"]:::data
        Cache["Redis/Predixy<br/>(Redis:6379)"]:::data
        FileStorage["File Storage<br/>(Volumes)"]:::data
        ExternalSvc["External Services<br/>(Solr, Mattermost, Slack)"]:::data
    end
    DBModule -->|MySQL/3306| DBStore
    HTTPClient -->|HTTP/80| ExternalSvc
    Protocol -->|HTTP/80| ExternalSvc
    Utils -->|reads/writes| FileStorage
    HTTPClient -->|GET/SET| Cache

    %% Auxiliary Components
    subgraph "Auxiliary Components"
        Python["Python Daemons & Scripts"]:::aux
        Shell["Shell Scripts"]:::aux
        Windows["Windows Scripts"]:::aux
    end
    Python -->|uses Core| Utils
    Python -->|DB ops| DBModule
    Shell -->|ops tasks| Core
    Windows -->|dev tasks| Core

    %% Infrastructure
    subgraph "Infrastructure"
        Containers["Docker Container Recipes"]:::infra
        K8s["Kubernetes Manifests"]:::infra
    end
    Containers --> HTTP
    Containers --> DBStore
    Containers --> Cache
    Containers --> Python
    K8s --> Containers

    %% Click events
    click CSS "https://github.com/honghongk/mylib/tree/main/css/"
    click JS "https://github.com/honghongk/mylib/tree/main/js/"
    click HTTP "https://github.com/honghongk/mylib/tree/main/docker/centos7-apache/Dockerfile"
    click HTTP "https://github.com/honghongk/mylib/tree/main/docker/centos7-php-fpm/Dockerfile"
    click Router "https://github.com/honghongk/mylib/blob/main/php/Route.php"
    click Handler "https://github.com/honghongk/mylib/blob/main/php/Handler.php"
    click CSRF "https://github.com/honghongk/mylib/blob/main/php/Middleware/CSRF.php"
    click Throttle "https://github.com/honghongk/mylib/blob/main/php/Middleware/Throttle.php"
    click Validate "https://github.com/honghongk/mylib/blob/main/php/Middleware/Validate.php"
    click MiddlewareInterface "https://github.com/honghongk/mylib/blob/main/php/Middleware/MiddlewareInterface.php"
    click API "https://github.com/honghongk/mylib/blob/main/php/API/Mattermost.php"
    click CLI "https://github.com/honghongk/mylib/blob/main/php/CLI/Process.php"
    click Logger "https://github.com/honghongk/mylib/blob/main/php/Logger.php"
    click URL "https://github.com/honghongk/mylib/blob/main/php/URL.php"
    click Str "https://github.com/honghongk/mylib/blob/main/php/Str.php"
    click Time "https://github.com/honghongk/mylib/blob/main/php/Time.php"
    click Calc "https://github.com/honghongk/mylib/blob/main/php/Calc.php"
    click Arr "https://github.com/honghongk/mylib/blob/main/php/Arr.php"
    click ExcelUtil "https://github.com/honghongk/mylib/blob/main/php/phpexcel_replace.php"
    click Req "https://github.com/honghongk/mylib/blob/main/php/HTTP/Request.php"
    click Res "https://github.com/honghongk/mylib/blob/main/php/HTTP/Response.php"
    click Curl "https://github.com/honghongk/mylib/blob/main/php/HTTP/Curl.php"
    click Cookie "https://github.com/honghongk/mylib/blob/main/php/HTTP/Cookie.php"
    click Session "https://github.com/honghongk/mylib/blob/main/php/HTTP/Session.php"
    click MySQLi "https://github.com/honghongk/mylib/blob/main/php/DB/Mysql/MySQLi.php"
    click Query "https://github.com/honghongk/mylib/blob/main/php/DB/Mysql/Query.php"
    click Stmt "https://github.com/honghongk/mylib/blob/main/php/DB/Mysql/Statement.php"
    click Dep "https://github.com/honghongk/mylib/blob/main/php/DB/Mysql/Dependency.php"
    click Dump "https://github.com/honghongk/mylib/blob/main/php/DB/Mysql/Dump.php"
    click TestDB "https://github.com/honghongk/mylib/blob/main/php/DB/Mysql/Test.php"
    click AbstractFS "https://github.com/honghongk/mylib/blob/main/php/Filesystem/AbstractFS.php"
    click FileMod "https://github.com/honghongk/mylib/blob/main/php/Filesystem/File.php"
    click Folder "https://github.com/honghongk/mylib/blob/main/php/Filesystem/Folder.php"
    click Json "https://github.com/honghongk/mylib/blob/main/php/Filesystem/Json.php"
    click ExcelFS "https://github.com/honghongk/mylib/blob/main/php/Filesystem/Excel.php"
    click Image "https://github.com/honghongk/mylib/blob/main/php/Filesystem/Image.php"
    click Video "https://github.com/honghongk/mylib/blob/main/php/Filesystem/Video.php"
    click ZipMod "https://github.com/honghongk/mylib/blob/main/php/Filesystem/Zip.php"
    click Storage "https://github.com/honghongk/mylib/blob/main/php/Filesystem/Storage.php"
    click FSEx "https://github.com/honghongk/mylib/blob/main/php/Filesystem/FilesystemException.php"
    click HTTPProto "https://github.com/honghongk/mylib/blob/main/php/Protocol/Http.php"
    click EmailProto "https://github.com/honghongk/mylib/blob/main/php/Protocol/Email.php"
    click Sendmail "https://github.com/honghongk/mylib/blob/main/php/Protocol/Sendmail.php"
    click Containers "https://github.com/honghongk/mylib/tree/main/docker/"
    click K8s "https://github.com/honghongk/mylib/tree/main/k8s/"
    classDef client fill:#a2d2ff,stroke:#000;
    classDef static fill:#bde0fe,stroke:#000;
    classDef server fill:#ffcad4,stroke:#000;
    classDef backend fill:#ffd6a5,stroke:#000;
    classDef util fill:#fdffb6,stroke:#000;
    classDef data fill:#caffbf,stroke:#000;
    classDef infra fill:#ffc6ff,stroke:#000;
    classDef aux fill:#9bf6ff,stroke:#000;
```
