# ajacques/certmanager architecture

> Architecture diagram of the GitHub repository ajacques/certmanager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ajacques/certmanager
- Repository: https://github.com/ajacques/certmanager

## Overview

##### Main System Components

Frontend Layer:
- React components (under app/javascript/components)
- Asset pipeline (CSS/JS under app/assets)
- HAML templates (under app/views)

Application Layer:
- Rails Controllers (app/controllers)
- Models (app/models)
- Background Jobs (app/jobs)
- Mailers (app/mailers)

Infrastructure Layer:
- Nginx (reverse proxy)
- Unicorn (app server)
- Redis (for caching and job queues)
- PostgreSQL (primary database)
- Resque (background job processing)

##### Component Relationships

a) Client-facing flow:
**Client → Nginx → Unicorn → Rails Application**

b) Background processing flow:
**Redis ← Resque Worker ← Scheduler**

c) Data flow:
**Rails Application ↔ PostgreSQL**
**Rails Application ↔ Redis**

##### Specific Components to Highlight

Certificate Management:
- Certificate model (app/models/certificate.rb)
- Certificate bundles (app/models/certificate_bundle)
- Public/Private key management (app/models/public_key.rb, private_key.rb)
- ACME integration (app/controllers/lets_encrypt_controller.rb)

Service Integration:
- Service deployments (app/models/service/*)
- Agent system (app/models/agent.rb)
- Background jobs for deployment (app/jobs/deploy_certificate_job.rb)

##### Important Architectural Patterns

- MVC pattern implementation
- Background job processing architecture
- Service-oriented deployment system
- Certificate lifecycle management
- Authentication/Authorization flow

##### Specific Implementation Details

- OAuth integration points
- Let's Encrypt ACME challenge flow
- Certificate deployment paths
- Monitoring and health check endpoints
- Email notification system

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph "Frontend Layer"
        React["React Components"]:::frontend
        Assets["Asset Pipeline"]:::frontend
        Views["HAML Templates"]:::frontend
    end

    subgraph "Application Layer"
        Controllers["Rails Controllers"]:::app
        Models["Domain Models"]:::app
        Jobs["Background Jobs"]:::app
        Mailers["Email System"]:::app
    end

    subgraph "Certificate Management"
        CertModel["Certificate Model"]:::security
        CertBundle["Certificate Bundles"]:::security
        PubKey["Public Key Manager"]:::security
        PrivKey["Private Key Manager"]:::security
        ACME["ACME Integration"]:::security
    end

    subgraph "Service Integration"
        ServiceModels["Service Models"]:::service
        AgentSystem["Agent System"]:::service
        DeployJobs["Deployment Jobs"]:::service
    end

    subgraph "Infrastructure Layer"
        Nginx["Nginx Proxy"]:::infra
        Unicorn["Unicorn Server"]:::infra
        Redis["Redis Cache"]:::storage
        PostgreSQL["PostgreSQL DB"]:::storage
        Resque["Resque Worker"]:::infra
    end

    Browser --> Nginx
    Nginx --> Unicorn
    Unicorn --> Controllers
    
    React --> Controllers
    Assets --> Views
    Views --> Controllers
    
    Controllers --> Models
    Models --> PostgreSQL
    Controllers --> Jobs
    Jobs --> Redis
    Redis --> Resque
    
    Models --> CertModel
    CertModel --> CertBundle
    CertModel --> PubKey
    CertModel --> PrivKey
    Controllers --> ACME
    
    Jobs --> ServiceModels
    ServiceModels --> AgentSystem
    Jobs --> DeployJobs
    
    Jobs --> Mailers

    %% Click events for component mapping
    click React "https://github.com/ajacques/CertManager/tree/master/app/javascript/components/"
    click Assets "https://github.com/ajacques/CertManager/tree/master/app/assets/"
    click Views "https://github.com/ajacques/CertManager/tree/master/app/views/"
    click Controllers "https://github.com/ajacques/CertManager/tree/master/app/controllers/"
    click Models "https://github.com/ajacques/CertManager/tree/master/app/models/"
    click Jobs "https://github.com/ajacques/CertManager/tree/master/app/jobs/"
    click Mailers "https://github.com/ajacques/CertManager/tree/master/app/mailers/"
    click CertModel "https://github.com/ajacques/CertManager/blob/master/app/models/certificate.rb"
    click CertBundle "https://github.com/ajacques/CertManager/tree/master/app/models/certificate_bundle/"
    click PubKey "https://github.com/ajacques/CertManager/blob/master/app/models/public_key.rb"
    click PrivKey "https://github.com/ajacques/CertManager/blob/master/app/models/private_key.rb"
    click ACME "https://github.com/ajacques/CertManager/blob/master/app/controllers/lets_encrypt_controller.rb"
    click ServiceModels "https://github.com/ajacques/CertManager/tree/master/app/models/service/"
    click AgentSystem "https://github.com/ajacques/CertManager/blob/master/app/models/agent.rb"
    click DeployJobs "https://github.com/ajacques/CertManager/blob/master/app/jobs/deploy_certificate_job.rb"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef app fill:#2ecc71,stroke:#27ae60,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef service fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef infra fill:#34495e,stroke:#2c3e50,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        AppComponent["Application Component"]:::app
        SecurityComponent["Security Component"]:::security
        ServiceComponent["Service Component"]:::service
        StorageComponent["Storage Component"]:::storage
        InfraComponent["Infrastructure Component"]:::infra
    end
```
