# markshust/docker-magento architecture

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

- Interactive diagram: https://gitdiagram.com/markshust/docker-magento
- Repository: https://github.com/markshust/docker-magento

## Overview

##### Project type and purpose
- This is an infrastructure-as-code repository providing Docker-based development environment for Magento 2.
- It delivers Docker images (nginx, php-fpm, opensearch/elasticsearch, rabbitmq, ssh) under `images/` and sample Docker Compose setups under `compose/`.
- It wraps common Magento operations via shell scripts in `compose/bin/` (e.g., `bin/start`, `bin/mysql`, `bin/magento`, `bin/update`).

##### Main components of the system
- Host environment – developer’s machine running Docker Desktop or Docker on Linux/WSL.
- Docker daemon / Docker Compose orchestration.
- Containers:
- nginx – serves HTTP(S) requests, reverse-proxies to PHP-FPM.
- php-fpm – runs PHP code (Magento), mounts project source (`src`).
- db – MySQL/MariaDB for Magento data storage.
- redis – cache and session storage.
- elasticsearch OR opensearch – search engine.
- rabbitmq – message queue.
- ssh – optional SFTP/SSH server for IDE sync.
- mailcatcher (in `compose.dev.yaml`) – intercepts outbound email.
- phpmyadmin (in `compose.dev.yaml`) – web UI for MySQL.
- selenium (optional for MFTF tests).
- Volumes:
- Source code volume (`src`).
- Data volumes: db data, redis data, rabbitmq data, search engine data.
- Configuration bind-mounts: Docker Compose YAML, env files, Nginx/PHP configs.
- Networks:
- Single bridge network where service hostnames equal service names (e.g., `db`, `redis`, `elasticsearch`).

##### Relationships and interactions
- User browser ↔ nginx container (80/443)
nginx ↔ php-fpm via FastCGI socket/port.
- php-fpm ↔ db over TCP (`db:3306`).
- php-fpm ↔ redis (`redis:6379`) for cache, sessions, page‐cache.
- php-fpm ↔ search engine (`opensearch:9200` or `elasticsearch:9200`).
- php-fpm ↔ rabbitmq (`rabbitmq:5672`) for async jobs.
- php-fpm ↔ mailcatcher (`mailcatcher:1025`) for SMTP and mail UI (`:1080`).
- php-fpm ↔ phpmyadmin (optional) only host↔phpmyadmin↔db.
- IDE/host ↔ ssh container for file sync (compose.dev-ssh.yaml).
- CI/CD pipelines (GitHub Actions) build/publish custom Docker images from `images/`.

##### Architectural patterns and design principles
- Container per service; each service isolated; everything defined in Docker Compose.
- Volumes provide data persistence; bind-mount for source code.
- Environment files (`compose/env/*.env`) decouple configuration.
- CLI‐wrapper pattern: wrapper scripts (`compose/bin/*`) abstract Docker Compose commands.
- Healthcheck compose file to verify operational status of services before start.

##### Relevant technologies, frameworks, and libraries
- Docker, Docker Compose (multiple YAML templates).
- Magento 2 (PHP application).
- PHP-FPM, Nginx.
- MySQL (or MariaDB).
- Redis.
- Elasticsearch / OpenSearch.
- RabbitMQ.
- Mailcatcher, PhpMyAdmin, Selenium (optional).
- Blackfire.io, Cloudflare Tunnel, SPX profiling (via PHP extensions).
- Grunt and LiveReload for frontend.

##### Detail
- Service, its ports, its dependencies.
- Distinguish dev-only services (phpmyadmin, selenium) vs core environment.
- Version build pipelines (GitHub Actions) for image creation if relevant to ops.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Layer 1: Host & Docker
    subgraph "Layer 1: Host & Docker"
        IDE("IDE"):::infra
        Docker("Docker Engine / Docker Desktop"):::infra
        Compose("Docker Compose Orchestration"):::infra
        EnvFiles("Environment Files"):::infra
        CLIWrapper("CLI-wrapper Scripts"):::infra
    end

    %% Layer 2: Reverse Proxy
    subgraph "Layer 2: Reverse Proxy (Web Tier)"
        Nginx["nginx\nPorts: 80/443"]:::web
    end

    %% Layer 3: Application
    subgraph "Layer 3: Application (App Tier)"
        PHPFPM["php-fpm\nMount: ./src:/var/www/html"]:::app
    end

    %% Layer 4: Data Stores & Messaging
    subgraph "Layer 4: Data Stores & Messaging"
        DB["MySQL/MariaDB\nVolume: db:/var/lib/mysql"]:::datastore
        Redis["Redis\nVolume: redis:/data"]:::datastore
        Search["Elasticsearch / OpenSearch\nVolume: search:/usr/share/elasticsearch"]:::search
        Rabbit["RabbitMQ\nVolume: rabbitmq:/var/lib/rabbitmq"]:::messaging
    end

    %% Layer 5: Dev/Test Services
    subgraph "Layer 5: Dev/Test Services"
        Mail["MailCatcher\nPorts: 1025/1080"]:::aux
        PhpAdmin["phpMyAdmin\nPort: 8080"]:::aux
        SSH["SSH Container"]:::aux
        Selenium["Selenium"]:::aux
    end

    %% Connections
    IDE -->|sync via SSH| SSH
    Docker --> Compose
    EnvFiles --> Compose
    CLIWrapper --> Compose

    Compose --> Nginx
    Compose --> PHPFPM
    Compose --> DB
    Compose --> Redis
    Compose --> Search
    Compose --> Rabbit
    Compose --> Mail
    Compose --> PhpAdmin
    Compose --> SSH
    Compose --> Selenium

    Browser("Browser"):::external --> Nginx
    Nginx -->|FastCGI| PHPFPM
    PHPFPM -->|TCP 3306| DB
    PHPFPM -->|TCP 6379| Redis
    PHPFPM -->|TCP 9200| Search
    PHPFPM -->|TCP 5672| Rabbit
    PHPFPM -->|SMTP 1025| Mail

    %% Click Events
    click Nginx "https://github.com/markshust/docker-magento/tree/release/next/images/nginx/1.18/"
    click Nginx "https://github.com/markshust/docker-magento/tree/release/next/images/nginx/1.22/"
    click Nginx "https://github.com/markshust/docker-magento/tree/release/next/images/nginx/1.24/"

    click PHPFPM "https://github.com/markshust/docker-magento/tree/release/next/images/php/8.1/"
    click PHPFPM "https://github.com/markshust/docker-magento/tree/release/next/images/php/8.2/"
    click PHPFPM "https://github.com/markshust/docker-magento/tree/release/next/images/php/8.3/"
    click PHPFPM "https://github.com/markshust/docker-magento/tree/release/next/images/php/8.4/"

    click DB "https://github.com/markshust/docker-magento/blob/release/next/compose/env/db.env"
    click DB "https://github.com/markshust/docker-magento/blob/release/next/compose/compose.yaml"

    click Redis "https://github.com/markshust/docker-magento/blob/release/next/compose/env/redis.env"
    click Redis "https://github.com/markshust/docker-magento/blob/release/next/compose/compose.yaml"

    click Search "https://github.com/markshust/docker-magento/tree/release/next/images/elasticsearch/7.16/"
    click Search "https://github.com/markshust/docker-magento/tree/release/next/images/elasticsearch/7.17/"
    click Search "https://github.com/markshust/docker-magento/tree/release/next/images/elasticsearch/8.4/"
    click Search "https://github.com/markshust/docker-magento/tree/release/next/images/elasticsearch/8.5/"
    click Search "https://github.com/markshust/docker-magento/tree/release/next/images/elasticsearch/8.7/"
    click Search "https://github.com/markshust/docker-magento/tree/release/next/images/elasticsearch/8.11/"
    click Search "https://github.com/markshust/docker-magento/tree/release/next/images/elasticsearch/8.13/"
    click Search "https://github.com/markshust/docker-magento/tree/release/next/images/opensearch/1.2/"
    click Search "https://github.com/markshust/docker-magento/tree/release/next/images/opensearch/2.5/"
    click Search "https://github.com/markshust/docker-magento/tree/release/next/images/opensearch/2.12/"

    click Rabbit "https://github.com/markshust/docker-magento/tree/release/next/images/rabbitmq/3.9/"
    click Rabbit "https://github.com/markshust/docker-magento/tree/release/next/images/rabbitmq/3.11/"
    click Rabbit "https://github.com/markshust/docker-magento/tree/release/next/images/rabbitmq/3.12/"
    click Rabbit "https://github.com/markshust/docker-magento/tree/release/next/images/rabbitmq/3.13/"
    click Rabbit "https://github.com/markshust/docker-magento/tree/release/next/images/rabbitmq/4.1/"

    click SSH "https://github.com/markshust/docker-magento/tree/release/next/images/ssh/Dockerfile"
    click SSH "https://github.com/markshust/docker-magento/blob/release/next/compose/compose.dev-ssh.yaml"

    click Mail "https://github.com/markshust/docker-magento/blob/release/next/compose/compose.dev.yaml"
    click PhpAdmin "https://github.com/markshust/docker-magento/blob/release/next/compose/compose.dev.yaml"
    click Selenium "https://github.com/markshust/docker-magento/blob/release/next/compose/compose.dev.yaml"

    click Compose "https://github.com/markshust/docker-magento/blob/release/next/compose/compose.yaml"
    click Compose "https://github.com/markshust/docker-magento/blob/release/next/compose/compose.dev.yaml"
    click Compose "https://github.com/markshust/docker-magento/blob/release/next/compose/compose.dev-linux.yaml"
    click Compose "https://github.com/markshust/docker-magento/blob/release/next/compose/compose.healthcheck.yaml"

    click EnvFiles "https://github.com/markshust/docker-magento/blob/release/next/compose/env/*.env"

    click CLIWrapper "https://github.com/markshust/docker-magento/tree/release/next/compose/bin/start"
    click CLIWrapper "https://github.com/markshust/docker-magento/tree/release/next/compose/bin/mysql"
    click CLIWrapper "https://github.com/markshust/docker-magento/tree/release/next/compose/bin/magento"
    click CLIWrapper "https://github.com/markshust/docker-magento/tree/release/next/compose/bin/update"

    %% Styles
    classDef web fill:#a8e6a1,stroke:#2d7f36,color:#000
    classDef app fill:#add8ff,stroke:#0050a0,color:#000
    classDef datastore fill:#ffcc99,stroke:#b35900,color:#000
    classDef messaging fill:#d8b4ff,stroke:#6a00a0,color:#000
    classDef search fill:#99f2e0,stroke:#008060,color:#000
    classDef aux fill:#e0e0e0,stroke:#7a7a7a,color:#000
    classDef infra fill:#f0e68c,stroke:#a08f00,color:#000
    classDef external fill:#ffffff,stroke:#888888,color:#000,stroke-dasharray: 2 2
```
