# department-of-veterans-affairs/leaf architecture

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

- Interactive diagram: https://gitdiagram.com/department-of-veterans-affairs/leaf
- Repository: https://github.com/department-of-veterans-affairs/leaf

## Overview

##### Main Components
- Frontend/Client Layers:
– The web interfaces for both the Nexus (organizational chart, admin screens) and the Request Portal (form submissions, workflow tracking).
– The Vue-based frontend (docker/vue-app) that parts of the system, such as the form editor and site designer, may use.
- Application Layers:
– LEAF_Nexus: Contains both PHP files (index.php, admin modules, ajax endpoints, API controllers) and authentication modules (auth_cert, auth_cookie, auth_token, auth_domain) to manage organizational data and user accounts.
– LEAF_Request_Portal: Contains similar PHP modules for electronic forms, workflow logic, and API endpoints.
– Servlets (digital-signing): A Java-based digital signing module offering digital signature and signing functions.
– Scheduled and batch scripts (in the scripts and pipeline directories) that perform tasks such as database updates, employee refreshes, and maintenance.
- Shared and Library Components:
– The “libs” and “app” directories hold third-party libraries and shared utilities (e.g., spreadsheets, logging, configuration, and XSS helpers).
- Infrastructure/Deployment:
– Docker files and Docker Compose/Swarm configurations showing containers for PHP (monolithic LEAF deployment or swarm mode deployments), MySQL databases, NGINX web server, and the Vue.js application.
– Docker volumes and environment configurations that manage secrets, caching, and application settings.

##### Out the Relationships and Interactions
- RESTful API endpoints in both LEAF_Nexus/api and LEAF_Request_Portal/api that serve data (for organizational chart updates, form submissions, etc.).
- How the PHP-based backend communicates with the MySQL database (as configured in the docker/mysql directory).
- Integration between scheduled tasks (present under the “scripts” directory) and backend systems – for example, tasks that run through cron or Docker scheduled jobs to update databases and refresh org chart data.
- Digital signing module of the servlets component as a specialized service that may be called by other components when digital signatures are required.
- Dependencies on shared libraries (libs, app, and php-commons) which are used by both LEAF_Nexus and LEAF_Request_Portal.

##### Architectural Patterns and Principles
- Separation of concerns: one module handles workflow and forms (Request Portal), while the other deals with organizational data and administration (Nexus).
- That there is a layered architecture: presentation (UI), application logic (PHP backends, Java signing service), and data (MySQL).
- Details on API-based communication between components.
- How containerization (Docker) is used to decouple the environments and ease deployment/maintenance.
- Mention that the system incorporates security elements (authentication modules in each area, use of certificates, tokens, etc.) as well as scheduled tasks and logging utilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend / Client Layer
    subgraph "Frontend / Client Layer"
        Browser["Client Browser"]:::client
    end

    %% Application Layer
    subgraph "Application Layer"
        subgraph "LEAF_Nexus (Organizational & Admin)"
            Nexus["LEAF_Nexus – PHP Application"]:::backend
        end
        subgraph "LEAF_Request_Portal (Forms & Workflow)"
            Portal["LEAF_Request_Portal – PHP Application"]:::backend
        end
        Digital["Digital Signing Service – Java/Servlets"]:::backend
        subgraph "Shared Libraries & Utilities"
            AppLib["Application Utilities"]:::library
            Libs["Third-party Libraries"]:::library
        end
        Sched["Scheduled & Batch Scripts"]:::script
    end

    %% Infrastructure / Deployment
    subgraph "Infrastructure / Deployment"
        NGINX["NGINX Web Server"]:::infra
        PHP["PHP Containers"]:::infra
        MySQL["MySQL Database"]:::database
        VueApp["Vue.js Frontend Application"]:::frontend
        Docker["Docker Configurations"]:::docker
    end

    %% Relationships - Frontend to Infra
    Browser -->|"accesses"| NGINX
    NGINX -->|"routes to"| PHP
    Docker -->|"orchestrates"| NGINX
    Docker -->|"orchestrates"| PHP
    Docker -->|"orchestrates"| MySQL
    Docker -->|"orchestrates"| VueApp

    %% Relationships - Infra to Application
    PHP -->|"processes"| Nexus
    PHP -->|"processes"| Portal
    PHP -->|"queries"| MySQL

    %% Application interactions
    Nexus -->|"utilizes"| AppLib
    Nexus -->|"utilizes"| Libs
    Portal -->|"utilizes"| AppLib
    Portal -->|"utilizes"| Libs
    Nexus -->|"triggers"| Sched
    Portal -->|"triggers"| Sched
    Nexus -->|"invokes"| Digital
    Portal -->|"invokes"| Digital

    %% Click Events
    click Nexus "https://github.com/department-of-veterans-affairs/leaf/tree/master/LEAF_Nexus"
    click Portal "https://github.com/department-of-veterans-affairs/leaf/tree/master/LEAF_Request_Portal"
    click AppLib "https://github.com/department-of-veterans-affairs/leaf/tree/master/app"
    click Libs "https://github.com/department-of-veterans-affairs/leaf/tree/master/libs"
    click Digital "https://github.com/department-of-veterans-affairs/leaf/tree/master/servlets/digital-signing"
    click Docker "https://github.com/department-of-veterans-affairs/leaf/tree/master/docker"
    click Sched "https://github.com/department-of-veterans-affairs/leaf/tree/master/scripts"
    click VueApp "https://github.com/department-of-veterans-affairs/leaf/tree/master/docker/vue-app"

    %% Styles
    classDef client fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef backend fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef infra fill:#fad7a0,stroke:#d35400,stroke-width:2px;
    classDef database fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef library fill:#d5f5e3,stroke:#28b463,stroke-width:2px;
    classDef script fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
    classDef docker fill:#d6eaf8,stroke:#2e86c1,stroke-width:2px;
    classDef frontend fill:#fcf3cf,stroke:#b7950b,stroke-width:2px;
```
