# kevinohara80/sfdc-trigger-framework architecture

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

- Interactive diagram: https://gitdiagram.com/kevinohara80/sfdc-trigger-framework
- Repository: https://github.com/kevinohara80/sfdc-trigger-framework

## Overview

##### Project type and purpose
- This is an open-source Salesforce Apex library (“SFDC trigger framework”) intended to simplify and standardize writing Apex triggers.
- It provides a single base class, TriggerHandler, which you inherit from in your own trigger handlers.  It uses a Template Method pattern to invoke context-specific override methods, and it provides recursion control (“max loop count”) and a bypass API.

##### File structure
- Top-level:
- package.json – npm distribution manifest
- pmd.xml / .codeclimate.yml – static analysis configuration
- README.md – project description and usage
- src/package.xml – Salesforce metadata descriptor for deployment
- src/classes:
- TriggerHandler.cls (+ metadata) – core base class
- TriggerHandler_Test.cls (+ metadata) – unit tests
- No frontend or external microservices; this is a pure Apex library to be deployed into a Salesforce org.

##### README for architecture insights
- Describes the Template Method flow: base class watches for Trigger contexts, calls override methods in subclasses.
- Highlights two cross-cutting concerns: recursion prevention (max loop count) and the bypass API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Salesforce Platform Layer
    subgraph "Salesforce Platform" 
        direction TB
        SP("Salesforce Platform Runtime"):::platform
        DML["DML Event (e.g., insert Account)"]:::platform
        TriggerMeta["Trigger Metadata (AccountTrigger.trigger)"]:::platform
        SP --> DML
        DML --> TriggerMeta
    end

    %% Core Library Layer
    subgraph "Core Library (SFDC Trigger Framework)"
        direction TB
        THBase["TriggerHandler Base Class"]:::core
        THMeta["TriggerHandler Metadata"]:::core
        Recursion["Recursion Control"]:::core
        Bypass["Bypass API"]:::core
        ContextMethods["Context Methods (beforeInsert(), afterUpdate(), etc.)"]:::core
        THBase --> Recursion
        THBase --> Bypass
        THBase --> ContextMethods
        THBaseMeta["TriggerHandler.cls-meta.xml"]:::core
        THBase --> THBaseMeta
    end

    %% User-Defined Handlers
    subgraph "User-Defined Handler Subclasses"
        direction TB
        Subclass["OpportunityTriggerHandler"]:::user
    end

    %% Test Suite & CI
    subgraph "Test Suite & CI"
        direction TB
        Tests["TriggerHandler_Test.cls"]:::tests
        TestsMeta["TriggerHandler_Test.cls-meta.xml"]:::tests
        StaticPMD["pmd.xml"]:::tests
        StaticCC[".codeclimate.yml"]:::tests
        Tests --> TestsMeta
    end

    %% Deployment Pipeline
    subgraph "Deployment Pipeline"
        direction TB
        NPM["package.json"]:::tests
        SFDX["src/package.xml"]:::tests
        Docs["README.md"]:::tests
        License["LICENSE"]:::tests
        GitIgnore[".gitignore"]:::tests
        NPM --> SFDX
        SFDX --> Docs
        Docs --> License
        License --> GitIgnore
    end

    %% Execution Flow
    TriggerMeta -->|"instantiates"| Subclass
    Subclass -->|"calls run()"| THBase
    THBase -->|"checks loop count"| Recursion
    THBase -->|"registers bypass"| Bypass
    THBase -->|"invokes override"| ContextMethods
    ContextMethods -->|"user logic, may DML"| DML
    Tests --> TriggerMeta

    %% Click Events
    click THBase "https://github.com/kevinohara80/sfdc-trigger-framework/blob/master/src/classes/TriggerHandler.cls"
    click THBaseMeta "https://github.com/kevinohara80/sfdc-trigger-framework/blob/master/src/classes/TriggerHandler.cls-meta.xml"
    click Tests "https://github.com/kevinohara80/sfdc-trigger-framework/blob/master/src/classes/TriggerHandler_Test.cls"
    click TestsMeta "https://github.com/kevinohara80/sfdc-trigger-framework/blob/master/src/classes/TriggerHandler_Test.cls-meta.xml"
    click SFDX "https://github.com/kevinohara80/sfdc-trigger-framework/blob/master/src/package.xml"
    click NPM "https://github.com/kevinohara80/sfdc-trigger-framework/blob/master/package.json"
    click StaticPMD "https://github.com/kevinohara80/sfdc-trigger-framework/blob/master/pmd.xml"
    click StaticCC "https://github.com/kevinohara80/sfdc-trigger-framework/blob/master/.codeclimate.yml"
    click Docs "https://github.com/kevinohara80/sfdc-trigger-framework/blob/master/README.md"
    click License "https://github.com/kevinohara80/sfdc-trigger-framework/tree/master/LICENSE"
    click GitIgnore "https://github.com/kevinohara80/sfdc-trigger-framework/blob/master/.gitignore"

    %% Styles
    classDef platform fill:#BBE1FA,stroke:#333,stroke-width:1px
    classDef core fill:#BAFFC9,stroke:#333,stroke-width:1px
    classDef user fill:#FFFACD,stroke:#333,stroke-width:1px
    classDef tests fill:#D3D3D3,stroke:#333,stroke-width:1px
```
