# cleantalk/security-malware-firewall architecture

> Architecture diagram of the GitHub repository cleantalk/security-malware-firewall, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cleantalk/security-malware-firewall
- Repository: https://github.com/cleantalk/security-malware-firewall

## Overview

##### Major components
- Plugin Core & Business Logic: Represent the PHP modules located in the “inc” and “lib” directories. These include:
– Security logic components (spbc-firewall.php, spbc-admin.php, spbc-settings.php, spbc-scanner.php, and other spbc-*.php files).
– Core libraries under “lib/CleantalkSP” and “lib/CleantalkSP/SpbctWP” that implement scanning (heuristic and signatures analysers), database interactions, state handling, remote calls, and security functions.
- External Services & Communication: Include CleanTalk’s cloud security service (for logging, access key generation, and daily security reports) that communicates with the plugin when API calls or notifications are needed.
- Build & Deployment Pipeline: Outline configuration components (gulpfile.js, webpack.config.js, .github workflows) that facilitate CI/CD, testing, and releasing. Also, note dependencies managed via composer.json and package.json.
- Testing Framework: Represent the extensive test suites (located in “tests” and “spec”) which support continuous integration, unit testing for security functions, scanning modules, and IP-based logic.

##### Interactions and relationships
- The WordPress environment (hosting the plugin via index.php, install script, and templates) acts as the container. Data flows from the website’s incoming HTTP requests into the plugin’s security modules.
- The backend modules (inc and lib directories) receive events from WordPress hooks. They process tasks (e.g., checking login attempts, scanning files, interacting with the firewall module, and queueing requests) and then communicate results back to the WordPress dashboard.
- The UI components (built in JavaScript/React) provide an interactive admin interface that retrieves data from the underlying PHP modules (using AJAX or REST calls).
- External API channels link the plugin to CleanTalk’s cloud service where logs and security events are stored for a period (45 days). This channel is used to verify API keys and deliver notifications.
- The asset/build process (via gulp, webpack, etc.) transforms and packages CSS/JS resources that get served by WordPress.

##### Architectural patterns and design principles
- Modularity: The separation of functionalities into distinct directories (for scanning, firewall, admin, etc.) implies a modular design, facilitating maintenance and scalability.
- MVC-like Separation: Although not a pure MVC framework, the plugin separates presentation logic (JS and CSS), business logic (PHP in inc/ and lib/), and data/persistence (DB abstraction in lib/SpbctWP/DB).
- Integration with third-party services: The design leverages external cloud-based monitoring and reporting, underscoring the SaaS approach.
- Asynchronous and scheduled processes: There are elements such as cron jobs (in lib/CleantalkSP/Common/Cron.php and tests for spbc-cron) which reflect background task scheduling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% WordPress Environment
    subgraph "WordPress Integration"
        WP["WordPress Environment (HTTP Requests, index.php, install script)"]:::wordpress
    end

    %% Plugin Core & Business Logic
    subgraph "Plugin Core & Business Logic"
        inc_firewall["Security Firewall Module"]:::backend
        inc_admin["Admin Module"]:::backend
        inc_settings["Settings Module"]:::backend
        inc_scanner["Scanner Module"]:::backend
        core_lib["Core Libraries"]:::backend
    end

    %% Admin/User Interface
    subgraph "Admin/User Interface"
        react_ui["React Admin Dashboard"]:::frontend
        css_assets["CSS Assets"]:::frontend
    end

    %% External Services & Communication
    subgraph "External Services & Communication"
        external_api["CleanTalk Cloud API"]:::external
    end

    %% Build & Deployment Pipeline
    subgraph "Build & Deployment Pipeline"
        gulp["Gulp Build"]:::build
        webpack["Webpack Config"]:::build
        composer["Composer"]:::build
        package["Package Manager"]:::build
        github["GitHub Workflows"]:::build
    end

    %% Testing Framework
    subgraph "Testing Framework"
        php_tests["PHP Tests"]:::testing
        js_tests["JS Tests"]:::testing
    end

    %% Relationships
    WP -->|"triggers"| inc_firewall
    WP -->|"triggers"| inc_admin
    WP -->|"triggers"| inc_settings
    WP -->|"triggers"| inc_scanner

    inc_firewall -->|"reports"| core_lib
    inc_admin -->|"updates"| react_ui
    inc_settings -->|"configures"| core_lib
    inc_scanner -->|"invokes"| core_lib

    core_lib -->|"API calls"| external_api
    react_ui -->|"AJAX/REST"| core_lib
    css_assets --> react_ui

    gulp -->|"packages"| react_ui
    webpack -->|"bundles"| react_ui
    composer -->|"manages"| core_lib
    package -->|"manages"| react_ui
    github -->|"triggers"| php_tests
    github -->|"triggers"| js_tests
    php_tests -->|"validates"| core_lib
    js_tests -->|"validates"| react_ui

    %% Click Events for Plugin Core & Business Logic
    click inc_firewall "https://github.com/cleantalk/security-malware-firewall/blob/master/inc/spbc-firewall.php"
    click inc_admin "https://github.com/cleantalk/security-malware-firewall/blob/master/inc/spbc-admin.php"
    click inc_settings "https://github.com/cleantalk/security-malware-firewall/blob/master/inc/spbc-settings.php"
    click inc_scanner "https://github.com/cleantalk/security-malware-firewall/blob/master/inc/spbc-scanner.php"
    click core_lib "https://github.com/cleantalk/security-malware-firewall/tree/master/lib/CleantalkSP"

    %% Click Events for Admin/User Interface
    click react_ui "https://github.com/cleantalk/security-malware-firewall/tree/master/js/src/react"
    click css_assets "https://github.com/cleantalk/security-malware-firewall/tree/master/css/src"

    %% Click Event for External Services
    click external_api "https://github.com/cleantalk/security-malware-firewall/blob/master/lib/CleantalkSP/SpbctWP/API.php"

    %% Click Events for Build & Deployment Pipeline
    click gulp "https://github.com/cleantalk/security-malware-firewall/blob/master/gulpfile.js"
    click webpack "https://github.com/cleantalk/security-malware-firewall/blob/master/webpack.config.js"
    click composer "https://github.com/cleantalk/security-malware-firewall/blob/master/composer.json"
    click package "https://github.com/cleantalk/security-malware-firewall/blob/master/package.json"
    click github "https://github.com/cleantalk/security-malware-firewall/blob/master/.github"

    %% Click Events for Testing Framework
    click php_tests "https://github.com/cleantalk/security-malware-firewall/tree/master/tests"
    click js_tests "https://github.com/cleantalk/security-malware-firewall/tree/master/spec"

    %% Styles
    classDef wordpress fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef backend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef frontend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef build fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef testing fill:#DDA0DD,stroke:#000,stroke-width:1px;
```
