Skip to content

REFACTOR: SEPARATION OF CONCERNS (MVC) FOR CORE LOGIC #285

@somethingwithproof

Description

@somethingwithproof

SUMMARY
The plugin logic is currently concentrated in massive, monolithic procedural files like functions.php (2,500+ lines) and setup.php. These files mix UI rendering, business logic, and database access, making maintenance difficult and testing nearly impossible without complex stubs.

Existing structure:

  • functions.php: Contains poller logic, HTML generation, and database wrappers.
  • setup.php: Handles installation, upgrades, and hook registration.

WHY REFACTOR
The monolithic approach leads to high cognitive load and increased risk of regression during updates. Separating concerns into distinct layers (Models, Services, Views) will allow for better code reuse, easier unit testing, and a cleaner path for future modernization (e.g., Cacti 1.3+ support).

PROPOSED CHANGE
Transition to a modern, object-oriented architecture under the src/ directory:

  1. Models: Introduce entity classes (e.g., Cacti\Syslog\Models\Alert) to handle data structure and basic persistence.
  2. Services: Move complex business logic into specialized service classes (e.g., Cacti\Syslog\Services\RemovalProcessor).
  3. Autoloading: Fully utilize PSR-4 via the existing composer.json configuration.

SCOPE

  • Creation of src/Models and src/Services directories.
  • Incremental extraction of logic from functions.php.
  • No functional changes to the plugin behavior; strictly architectural.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions