# passbolt/passbolt_api architecture

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

- Interactive diagram: https://gitdiagram.com/passbolt/passbolt_api
- Repository: https://github.com/passbolt/passbolt_api

## Overview

- Clients and User Interfaces:
- Browser Extensions, Mobile apps, Desktop app (when available) and CLI.
- Web-based user interface (the “webroot” directory and templates).
- API/Application Layer:
- The “src/Controller” and “src/Component” layers expose APIs (HTTP endpoints) that the various clients interact with.
- This layer implements authentication controllers (AuthLogin, AuthLogout, AuthVerify, etc.) and various domain-specific controllers (Users, Groups, Resources, Secrets).
- Middleware:
- A set of middlewares (found under “src/Middleware”) that handle cross-cutting concerns: session management, CSRF protection, SSL enforcement, API versioning, and specific security headers (like GpgAuthHeadersMiddleware).
- Business Logic / Services Layer:
- “src/Service” hosts a rich service layer that manages core business logic. For example, separate services to handle authentication tokens, groups, secrets, permissions, resources, password expiry, and the OpenPGP/GPG key processing. There are dedicated services for healthchecks and integration with external systems.
- Plugin Modules:
- The “plugins” directory contains multiple plugins such as JWTAuthentication, Folders, EmailDigest, MultiFactorAuthentication and others. Each can be represented as a distinct module that integrates with the overall application.
- Data Persistence:
- External Infrastructure:
- Integration points with external systems such as an email server (configured via SMTP settings, see “plugins/PassboltCe/SmtpSettings” and “src/Mailer”), as well as connections for healthchecks.

##### Relationships and Data Flows
- To connect the services layer to the database (for CRUD operations) and to external services such as an email server or third-party integrations.

##### Architectural Patterns & Design Principles
- Modular Architecture: The project’s design supports extendability via its plugins, meaning that many features (authentication, logging, localization, password expiry, resource sharing) are implemented as attachable modules.
- Layered Architecture: There is a clear separation of concerns between the presentation layer (controllers/views), request processing (middleware), business logic (services) and persistence (model/database).
- Use of Standard Framework Patterns: The project follows conventions typical of CakePHP (such as MVC, use of behaviors on models, and component-based controllers).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Subgraph
    subgraph "Clients"
        Web_UI["Web UI"]:::client
        Browser_Ext["Browser Extension"]:::client
        Mobile_App["Mobile App"]:::client
        Desktop_App["Desktop App"]:::client
        subgraph "CLI"
            CLIScripts["CLI Scripts"]:::client
            CLICommands["CLI Commands"]:::client
        end
    end

    %% API Layer Subgraph
    subgraph "API Layer"
        Controller["HTTP Controllers (src/Controller)"]:::api
        Component["API Components (src/Component)"]:::api
    end

    %% Middleware Subgraph
    subgraph "Middleware"
        Middleware["Request Middleware (src/Middleware)"]:::middleware
    end

    %% Business Services Subgraph
    subgraph "Business Services"
        Business_Services["Business Services (src/Service)"]:::services
    end

    %% Plugin Modules Subgraph
    subgraph "Plugin Modules"
        Plugins["Plugin Modules (plugins)"]:::plugins
    end

    %% Data Persistence Subgraph
    subgraph "Data Persistence"
        Models["Models (src/Model)"]:::persistence
        DB_Config["DB Config (config)"]:::persistence
    end

    %% External Services Subgraph
    subgraph "External Services"
        SMTP["SMTP Settings (plugins/PassboltCe/SmtpSettings)"]:::external
        Mailer["Email Service (src/Mailer)"]:::external
    end

    %% Connections from Clients to API Layer
    Web_UI --> Controller
    Browser_Ext --> Controller
    Mobile_App --> Controller
    Desktop_App --> Controller
    CLIScripts --> Controller
    CLICommands --> Controller

    %% API Layer Internal Connections
    Controller -->|"uses"| Component
    Controller -->|"validatedBy"| Middleware
    Component -->|"validatedBy"| Middleware

    %% From Middleware to Business Services
    Middleware -->|"invokes"| Business_Services

    %% Business Services to Data Persistence and External Services
    Business_Services -->|"CRUD operations"| Models
    Models -->|"configuredBy"| DB_Config
    Business_Services -->|"sendsEmail"| SMTP
    Business_Services -->|"sendsEmail"| Mailer

    %% Integration with Plugin Modules
    Business_Services ---|"integrates"| Plugins

    %% Click Events
    click Web_UI "https://github.com/passbolt/passbolt_api/tree/master/webroot"
    click CLIScripts "https://github.com/passbolt/passbolt_api/tree/master/bin"
    click CLICommands "https://github.com/passbolt/passbolt_api/tree/master/src/Command"
    click Controller "https://github.com/passbolt/passbolt_api/tree/master/src/Controller"
    click Component "https://github.com/passbolt/passbolt_api/tree/master/src/Component"
    click Middleware "https://github.com/passbolt/passbolt_api/tree/master/src/Middleware"
    click Business_Services "https://github.com/passbolt/passbolt_api/tree/master/src/Service"
    click Plugins "https://github.com/passbolt/passbolt_api/tree/master/plugins"
    click Models "https://github.com/passbolt/passbolt_api/tree/master/src/Model"
    click DB_Config "https://github.com/passbolt/passbolt_api/tree/master/config"
    click SMTP "https://github.com/passbolt/passbolt_api/tree/master/plugins/PassboltCe/SmtpSettings"
    click Mailer "https://github.com/passbolt/passbolt_api/tree/master/src/Mailer"

    %% Styles
    classDef client fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef api fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef middleware fill:#c5e1a5,stroke:#33691e,stroke-width:2px;
    classDef services fill:#b39ddb,stroke:#4a148c,stroke-width:2px;
    classDef plugins fill:#ffccbc,stroke:#bf360c,stroke-width:2px;
    classDef persistence fill:#f0f4c3,stroke:#827717,stroke-width:2px;
    classDef external fill:#d1c4e9,stroke:#311b92,stroke-width:2px;
```
