# openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise architecture

> Architecture diagram of the GitHub repository openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise
- Repository: https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise

## Overview

##### Project type and purpose
- This is a Salesforce DX metadata-driven customization project.
- Purpose: extend a Salesforce org by adding custom objects (Order, Account fields), business logic (Apex classes and triggers) and a Lightning Web Component (LWC) to display or manipulate orders.

##### File structure
- Top-level:
- config/ – scratch org definition (project-scratch-def.json)
- force-app/main/default/ – all Salesforce metadata
- manifest/ – package.xml for deployments
- .github/workflows/ – CI/CD workflow (main_deploy)
- sfdx-project.json, package.json – Salesforce DX and npm config
- Within force-app/main/default:
- classes/ – Apex controllers and business logic
– MyTeamOrdersController.cls (Apex controller for LWC)
– UpdateAllAccounts.cls (batch or utility class) + test
- triggers/ – record-triggered automation
– CalculMontant.trigger (compute something on Order)
– UpdateAccountCA.trigger (update Account revenue)
- lwc/orders/ – Lightning Web Component
– orders.js/.html, metadata, tests
- objects/ – custom object definitions
– Account/fields/Chiffre_d_affaire__c
– Order/fields/{NetAmount__c, ShipmentCost__c}

##### README for additional insights
- Deployment workflow via Salesforce CLI (sf project deploy start)
- Target sandbox or scratch org
- Verification steps: ensure objects, fields, classes, triggers, and LWC are deployed

##### Main components
a. Salesforce Platform (deployed scratch or sandbox org)
b. Data Model
- Account (standard object + custom field Chiffre_d_affaire__c)
- Order (standard object + custom fields NetAmount__c, ShipmentCost__c)
- Underlying Salesforce relational database
c. Business Logic Layer (Apex)
- MyTeamOrdersController – exposes data/services to LWC via @AuraEnabled methods
- UpdateAllAccounts – batch or utility job to recalculate revenue for all accounts
- Triggers:
– CalculMontant.trigger – calculates order totals on insert/update
– UpdateAccountCA.trigger – rolls up Order revenue into Account.Chiffre_d_affaire__c
d. Presentation Layer (Lightning Web Component)
- orders LWC – UI that queries and displays orders, invokes Apex controller
e. Deployment Pipeline & Tooling
- GitHub Actions (main_deploy workflow)
- Salesforce CLI (sf org login, sf project deploy start)
- sfdx-project.json / manifest/package.xml – defines metadata to deploy

##### Relationships and interactions
- LWC (browser) → calls Apex controller (MyTeamOrdersController) → SOQL → Salesforce DB → returns JSON → LWC UI
- User creates or updates Order record → Salesforce triggers fire (CalculMontant, then UpdateAccountCA) → Apex trigger logic updates Order fields and Account revenue
- UpdateAllAccounts can be invoked (manually or scheduled) to recalculate all Account revenues in bulk
- Deployment: developer pushes changes to GitHub → CI/CD workflow runs → uses Salesforce CLI to push metadata into target org

##### Architectural patterns & design principles
- MVC within Salesforce:
- Model = sObjects (Order, Account)
- View = LWC component
- Controller = Apex classes (MyTeamOrdersController) and triggers
- Event-driven: record triggers react to data changes
- Metadata-as-code: all org configuration managed via source files and deployed via CLI/CI
- Separation of concerns: UI (LWC) vs business logic (Apex) vs data model

##### Elements
- “Browser / LWC orders”
- “Apex Controller (MyTeamOrdersController)”
- “Apex Triggers (CalculMontant, UpdateAccountCA)”
- “Batch Job / Utility (UpdateAllAccounts)”
- “Salesforce Data Model (Order, Account)”
- “GitHub Actions / CI-CD”
- “Salesforce CLI”
- LWC → Apex → DB → LWC
- Data change → triggers → DB updates
- GitHub → CI → Salesforce CLI → Org
- Blue for UI components
- Green for business logic (Apex)
- Orange for data model
- Grey for external tools/deployment

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment Pipeline
    subgraph "Deployment Pipeline"
        direction TB
        GH["GitHub Actions\n(main_deploy)"]:::external
        CLI["Salesforce CLI\n(sf project deploy start)"]:::external
        SFDX["sfdx-project.json\nconfig/project-scratch-def.json"]:::external
        MAN["manifest/package.xml"]:::external

        GH -->|"trigger workflow"| CLI
        CLI -->|"uses config & manifest"| SFDX
        CLI -->|"deploy metadata"| PLATFORM
    end

    %% Salesforce Platform Boundary
    subgraph "Salesforce Platform"
        direction TB

        %% Presentation Layer
        subgraph "Presentation Layer (LWC)" 
            direction TB
            LWC["Browser / LWC orders"]:::frontend
        end

        %% Business Logic Layer
        subgraph "Business Logic Layer (Apex)" 
            direction TB
            CTRL["Apex Controller\nMyTeamOrdersController"]:::logic
            BATCH["Batch Job / Utility\nUpdateAllAccounts"]:::logic
            TRIGGERS["Apex Triggers\nCalculMontant, UpdateAccountCA"]:::logic
        end

        %% Data Model & Database
        subgraph "Data Model & Database"
            direction TB
            OBJECTS["Salesforce Data Model\nOrder & Account"]:::data
            DB["Salesforce Relational DB"]:::data
        end

        %% Interactions
        LWC -->|"@AuraEnabled / SOQL Query"| CTRL
        CTRL -->|"SOQL"| DB
        DB -->|"JSON Response"| CTRL
        CTRL -->|"Returns Data"| LWC

        %% Record changes
        UserAction["User creates/updates Order"]:::external
        UserAction -->|"Record Insert/Update"| TRIGGERS
        TRIGGERS -->|"Calculations & Rollup"| DB

        %% Batch invocation
        Scheduler["Manual/Scheduled Run"]:::external
        Scheduler -->|"invoke batch"| BATCH
        BATCH -->|"bulk update Account revenue"| DB
    end

    %% Click Events
    click GH "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/tree/main/.github/workflows/main_deploy"
    click SFDX "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/sfdx-project.json"
    click SFDX "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/config/project-scratch-def.json"
    click MAN "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/manifest/package.xml"
    click CTRL "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/classes/MyTeamOrdersController.cls"
    click CTRL "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/classes/MyTeamOrdersController.cls-meta.xml"
    click BATCH "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/classes/UpdateAllAccounts.cls"
    click BATCH "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/classes/UpdateAllAccounts.cls-meta.xml"
    click BATCH "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/classes/testUpdateAllAccounts.cls"
    click BATCH "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/classes/testUpdateAllAccounts.cls-meta.xml"
    click TRIGGERS "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/triggers/CalculMontant.trigger"
    click TRIGGERS "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/triggers/CalculMontant.trigger-meta.xml"
    click TRIGGERS "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/triggers/UpdateAccountCA.trigger"
    click TRIGGERS "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/triggers/UpdateAccountCA.trigger-meta.xml"
    click LWC "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/tree/main/force-app/main/default/lwc/orders/"
    click LWC "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/lwc/orders/orders.js"
    click LWC "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/lwc/orders/orders.html"
    click LWC "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/lwc/orders/orders.js-meta.xml"
    click LWC "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/lwc/orders/__tests__/orders.test.js"
    click OBJECTS "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/objects/Account/fields/Chiffre_d_affaire__c.field-meta.xml"
    click OBJECTS "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/objects/Order/fields/NetAmount__c.field-meta.xml"
    click OBJECTS "https://github.com/openclassrooms-student-center/p9-ameliorez-organisation-salesforce-pour-votre-entreprise/blob/main/force-app/main/default/objects/Order/fields/ShipmentCost__c.field-meta.xml"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef logic fill:#DFFFE0,stroke:#333,stroke-width:1px
    classDef data fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px

    class GH,CLI,SFDX,MAN,Scheduler,UserAction external
    class LWC frontend
    class CTRL,BATCH,TRIGGERS logic
    class OBJECTS,DB data
```
