# noamanahmed/lemp architecture

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

- Interactive diagram: https://gitdiagram.com/noamanahmed/lemp
- Repository: https://github.com/noamanahmed/lemp

## Overview

##### Project type and purpose
- This is a CLI-based automation toolkit (bash scripts) for provisioning and managing a LEMP (Linux, Nginx, MySQL, PHP) server and its ecosystem (Python, NodeJS, Redis, Kafka, etc.).
- The README confirms it’s not a web application but an ops-focused installer/orchestrator for Ubuntu servers.

##### File structure
- Top-level “bin/” directory: dozens of command scripts (create-site-*, enable-*, disable-*, list-*, etc.).
- “installers/”: idempotent .sh modules that install/configure each service (nginx.sh, php.sh, mysql.sh, redis.sh, etc.).
- “templates/”: Jinja-style (bash-templated) configuration snippets grouped by service (nginx vhosts, supervisord conf, systemd units, etc.).
- “includes/helpers.sh”: shared functions and utilities.
- “install.sh”: the entry-point orchestrator that sources helpers, reads parameters, and invoks installer modules.
- “updates/”: scripts for versioned updates.
- “tests/”: terraform and shell tests for validating deployments.

##### README for additional insights
- The tool is designed to run on Ubuntu 20.04+ under root.
- It interacts with external APIs: Slack (webhooks), Uptime Robot.
- It manages services locally (systemd, supervisord, jailkit, UFW, etc.).

##### Main components and their interactions
a. CLI layer (“bin/” scripts and “install.sh”)
- User runs `install.sh` or a `bin/*` command.
- The CLI script parses arguments, sources helpers, then dispatches to the right installer.
b. Shared utilities (“includes/helpers.sh”)
- Logging, error handling, templating functions, environment variable parsing.
- Called by both installers and bin scripts.
c. Installer modules (“installers/*.sh”)
- Each service has its own installer script that:
1. Checks prerequisites.
2. Installs packages (apt, pip, npm, etc.).
3. Copies and renders templates.
4. Restarts/reloads services (systemctl, supervisorctl).
d. Template repository (“templates/…”)
- Holds boilerplate config for Nginx, PHP-FPM, MySQL, Postgres, Redis, etc.
- Rendered at runtime with environment‐specific parameters.
e. System services & targets (the provisioned VPS)
- Nginx, PHP-FPM, MySQL, Redis, Docker, fail2ban, UFW, jailkit, etc.
- Slack/UptimeRobot webhooks called via curl in scripts.
f. Update mechanism (“updates/100/update.sh”)
- Applies incremental updates to the tooling itself.
g. Tests (“tests/”)
- Validates infrastructure via Terraform and bash unit/integration tests.

##### Architectural patterns and design principles
- Modular scripting: one installer per service keeps concerns separated.
- Template-based configuration: promotes DRY, easy customization.
- CLI-driven dispatch: all commands live in “bin/” for discoverability.
- Incremental updates: versioned “updates/” folder.
- Shared library: “includes/helpers.sh” for cross‐cutting needs.

- Clear component labels (e.g., “bin/create-site-php”, “installers/php.sh”).
- User → CLI
- CLI → Helpers / Installers
- Installers → Templates → Services
- Scripts → External APIs

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User((User)):::external

    %% CLI Layer
    subgraph "CLI Layer"
        InstallSH["install.sh"]:::cli
        BinScripts["bin/*"]:::cli
    end

    %% Shared Utilities
    Helpers["includes/helpers.sh"]:::lib

    %% Installer Modules
    Installers["installers/*.sh"]:::cli

    %% Template Repository
    Templates["templates/*"]:::lib

    %% Target Server
    subgraph "Target Server"
        Systemd["Systemd Services<br/>(Nginx, PHP-FPM, MySQL, Redis, etc.)"]:::services
        Supervisor["Supervisord"]:::services
        Security["UFW, Jailkit, Fail2ban"]:::services
    end

    %% External Services
    subgraph "External Services"
        Slack["Slack Webhook"]:::external
        Uptime["UptimeRobot API"]:::external
        DNS["DNS / FQDN"]:::external
    end

    %% Updates and Tests
    Updates["updates/*"]:::cli
    Tests["tests/*"]:::lib

    %% Connections
    User -->|"runs"| InstallSH
    User -->|"runs"| BinScripts

    InstallSH -->|"sources"| Helpers
    BinScripts -->|"sources"| Helpers

    InstallSH -->|"invokes"| Installers
    BinScripts -->|"invokes"| Installers
    Helpers -->|"used by"| Installers

    Installers -->|"renders"| Templates
    Templates -->|"applies to"| Systemd
    Installers -->|"configures"| Systemd
    Installers -->|"configures"| Supervisor
    Installers -->|"configures"| Security

    Installers -->|"calls API"| Slack
    Installers -->|"calls API"| Uptime
    Installers -->|"resolves DNS"| DNS

    InstallSH -->|"runs"| Updates

    Tests -->|"validates"| Systemd
    Tests -->|"validates"| Supervisor
    Tests -->|"validates"| Security

    %% Click Events
    click InstallSH "https://github.com/noamanahmed/lemp/blob/master/install.sh"
    click BinScripts "https://github.com/noamanahmed/lemp/tree/master/bin/"
    click Helpers "https://github.com/noamanahmed/lemp/blob/master/includes/helpers.sh"
    click Installers "https://github.com/noamanahmed/lemp/tree/master/installers/"
    click Templates "https://github.com/noamanahmed/lemp/tree/master/templates/"
    click Updates "https://github.com/noamanahmed/lemp/tree/master/updates/"
    click Tests "https://github.com/noamanahmed/lemp/tree/master/tests/"

    %% Styles
    classDef cli fill:#cce5ff,stroke:#004085
    classDef lib fill:#d4edda,stroke:#155724
    classDef services fill:#fff3cd,stroke:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d
```
