# venturecraft/revisionable architecture

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

- Interactive diagram: https://gitdiagram.com/venturecraft/revisionable
- Repository: https://github.com/venturecraft/revisionable

## Overview

##### Project type and purpose
- This is an open-source Laravel package (“Revisionable”) that adds automatic revision-history tracking to any Eloquent model. It is not a standalone web app but a library you install via Composer into a Laravel application.

##### File structure
- src/
- Venturecraft/RevisionableServiceProvider.php – Laravel service provider
- RevisionableTrait.php – the Trait you “use” in your model
- Revisionable.php – legacy base class
- Revision.php – Eloquent model for the revisions table
- FieldFormatter.php – helper to format old/new values
- src/config/revisionable.php – published config file
- src/migrations – migration to create the revisions table
- tests/ – PHPUnit tests for the package
- composer.json, phpunit.xml, config files, CI settings

##### README for additional insights
- The package boots via a ServiceProvider, publishes config & migrations, hooks into Eloquent model events, writes to a “revisions” table, and fires “revisionable.*” events.
- It supports multiple auth drivers, configurable field-formatting, cleanup rules, and is entirely trait-based.

##### Detail—capture every piece of the architecture
- Trait hooking into multiple Eloquent lifecycle events
- Optional features (e.g., revisionForceDeleteEnabled flag, formatted fields, additional_fields in config)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Laravel Core"
        SC["Service Container / Bootstrapping"]:::core
        ED["Event Dispatcher"]:::core
        EO["Eloquent ORM"]:::core
        Auth["Auth Subsystem"]:::auth
    end

    subgraph "Revisionable Package"
        SP["RevisionableServiceProvider"]:::module
        RT["RevisionableTrait"]:::module
        RV["Revisionable (legacy base class)"]:::module
        RM["Revision Eloquent Model"]:::module
        FF["FieldFormatter"]:::module
        CFG["revisionable.php"]:::doc
        MIG["create_revisions_table"]:::doc
    end

    subgraph "Client Application"
        M["Eloquent Model (e.g., Article)"]:::client
        Listeners["revisionable.* Listeners"]:::client
    end

    DB["revisions table"]:::db

    subgraph "Tests"
        T1["RevisionTest.php"]:::test
        T2["User.php (Test Model)"]:::test
        T3["AddFields Migration 1"]:::test
        T4["AddFields Migration 2"]:::test
    end

    %% Relationships
    SC --> SP
    SP --> CFG
    SP --> MIG
    SP --> EO
    M --> RT
    EO -->|"saved/deleted events"| RT
    RT --> FF
    RT --> RV
    RT --> RM
    RM --> DB
    RM --> ED
    ED --> Listeners
    M -->|"revisionHistory"| RM
    Auth -->|"userResponsible lookup"| RT

    T1 --> MIG
    T1 --> T3
    T1 --> T4
    T1 --> T2
    T1 --> RT
    T1 --> RM

    %% Click Events
    click SP "https://github.com/venturecraft/revisionable/blob/master/src/Venturecraft/Revisionable/RevisionableServiceProvider.php"
    click RT "https://github.com/venturecraft/revisionable/blob/master/src/Venturecraft/Revisionable/RevisionableTrait.php"
    click RV "https://github.com/venturecraft/revisionable/blob/master/src/Venturecraft/Revisionable/Revisionable.php"
    click RM "https://github.com/venturecraft/revisionable/blob/master/src/Venturecraft/Revisionable/Revision.php"
    click FF "https://github.com/venturecraft/revisionable/blob/master/src/Venturecraft/Revisionable/FieldFormatter.php"
    click CFG "https://github.com/venturecraft/revisionable/blob/master/src/config/revisionable.php"
    click MIG "https://github.com/venturecraft/revisionable/blob/master/src/migrations/2013_04_09_062329_create_revisions_table.php"
    click T1 "https://github.com/venturecraft/revisionable/blob/master/tests/RevisionTest.php"
    click T2 "https://github.com/venturecraft/revisionable/blob/master/tests/Models/User.php"
    click T3 "https://github.com/venturecraft/revisionable/blob/master/tests/migrations/2020_01_02_062329_add_additional_field_to_revisions.php"
    click T4 "https://github.com/venturecraft/revisionable/blob/master/tests/migrations/2020_01_02_062330_add_additional_field_to_users.php"

    %% Styles
    classDef core fill:#D0E6FF,stroke:#000
    classDef module fill:#BDD7EE,stroke:#000
    classDef db fill:#D5E8D4,stroke:#000
    classDef doc fill:#FFF2CC,stroke:#000
    classDef auth fill:#F8CECC,stroke:#000
    classDef client fill:#BDD7EE,stroke:#000
    classDef test fill:#FDE9D9,stroke:#000
```
