# forstman1/inception-42 architecture

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

- Interactive diagram: https://gitdiagram.com/forstman1/inception-42
- Repository: https://github.com/forstman1/inception-42

## Overview

##### Project type and purpose
- This is a multi-container, Docker-compose based full-stack project (“Inception_42”) that demonstrates how to build and orchestrate a WordPress site (PHP-FPM + Nginx) backed by MariaDB, enhanced with Redis caching, managed via Adminer, served via FTP, and monitored by cAdvisor. It also includes a static “websites” bonus service and all Dockerfiles/configs live under srcs/requirements.

##### Key directories
- srcs/docker-compose.yml + .env – defines the services, networks, and volumes.
- srcs/requirements/<service> – each microservice lives in its own folder with a Dockerfile, .dockerignore, and tools (init scripts, configuration files).
– mariadb: database container and initialization scripts
– wordpress: PHP-FPM container, WP-CLI setup, configuration injection
– nginx: reverse-proxy / HTTPS termination container with OpenSSL certs
– redis: caching container for WP object cache
– adminer: DB-GUI container
– ftp: FTP server container for file uploads
– cadvisor: container monitoring agent
– bonus/websites: static site container

##### Main components & relationships
a. Docker Host & Engine
– Single Docker host running Docker Engine and Docker Compose
– A user-defined bridge network connects all containers.
b. Service containers
1. Nginx (port 80/443)
- HTTPS termination (self-signed via OpenSSL)
- reverse-proxies PHP requests to WordPress (FastCGI on port 9000)
- serves static files from shared volume (/var/www/html)
2. WordPress (PHP-FPM on port 9000)
- talks to MariaDB (TCP 3306) for persistent storage
- connects to Redis (TCP 6379) for object caching
- code/data shared via a named volume used by Nginx and FTP
3. MariaDB
- persistent data volume
- initialized via tools/script.sh and SQL scripts
4. Redis
- in-memory cache for WP
5. FTP
- exposes /var/www/html/files over FTP to manage uploads
6. Adminer
- DB admin UI → connects to MariaDB
7. cAdvisor
- monitors all containers via Docker API on port 8080
c. Volumes & Data flow
- wordpress_data – shared between WP, Nginx, FTP
- mariadb_data – holds database files
- named Redis volume if used (in-memory state)
d. Networks
- single Docker network for inter-container communication
- external port mappings (443 → nginx, 21 → ftp, 8080 → cadvisor, etc.)

##### Architectural patterns & design principles
- Microservices: each feature in its own container
- Single responsibility containers (DB, cache, web, proxy, monitoring, file transfer)
- Shared volumes for code and persistent data
- Clear orchestration via docker-compose.yml
- Environment-driven configuration via .env and startup scripts
- Use of FastCGI (PHP-FPM) pattern behind Nginx reverse proxy
- TLS termination at the edge (Nginx)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Actor
    User["User"]:::external

    %% Docker Host and Engine
    subgraph "Docker Host"
        direction TB
        DockerEngine["Docker Engine / Compose"]:::host

        subgraph "Configuration"
            direction TB
            Compose["docker-compose.yml"]:::config
            EnvFile[".env"]:::config
        end

        subgraph "Services"
            direction TB
            %% Web Tier
            subgraph "Web Tier" 
                direction TB
                Nginx["Nginx\n(80/443)"]:::web
                WordPress["WordPress\n(PHP-FPM:9000)"]:::web
            end

            %% Data Tier
            subgraph "Data Tier"
                direction TB
                MariaDB["MariaDB\n(3306)"]:::data
                Redis["Redis\n(6379)"]:::data
            end

            %% Management / Auxiliary
            subgraph "Management & Auxiliary"
                direction TB
                Adminer["Adminer"]:::aux
                FTP["FTP Server\n(21)"]:::aux
                cAdvisor["cAdvisor\n(8080)"]:::aux
            end
        end

        %% Volumes
        subgraph "Volumes"
            direction TB
            WPData["wordpress_data\n(/var/www/html)"]:::volume
            DBData["mariadb_data"]:::volume
        end

        %% Network
        DockerNetwork(("Docker Network")):::network
    end

    %% Connections
    User -->|"HTTPS"| Nginx
    Nginx -->|"FastCGI"| WordPress
    WordPress -->|"TCP 3306"| MariaDB
    WordPress -->|"TCP 6379"| Redis
    Adminer -->|"TCP 3306"| MariaDB
    FTPClient["FTP Client"]:::external -->|"FTP"| FTP
    FTP -->WPData
    WPData --> WordPress
    WPData --> Nginx
    cAdvisor -.->|"Docker API"| DockerEngine

    %% Network connections
    DockerEngine --> DockerNetwork
    DockerNetwork --> Nginx
    DockerNetwork --> WordPress
    DockerNetwork --> MariaDB
    DockerNetwork --> Redis
    DockerNetwork --> Adminer
    DockerNetwork --> FTP
    DockerNetwork --> cAdvisor

    %% Click Events
    click Compose "https://github.com/forstman1/inception-42/blob/main/srcs/docker-compose.yml"
    click EnvFile "https://github.com/forstman1/inception-42/blob/main/srcs/.env"
    click Nginx "https://github.com/forstman1/inception-42/tree/main/srcs/requirements/nginx"
    click WordPress "https://github.com/forstman1/inception-42/tree/main/srcs/requirements/wordpress"
    click MariaDB "https://github.com/forstman1/inception-42/tree/main/srcs/requirements/mariadb"
    click Redis "https://github.com/forstman1/inception-42/tree/main/srcs/requirements/bonus/redis"
    click Adminer "https://github.com/forstman1/inception-42/tree/main/srcs/requirements/bonus/adminer"
    click FTP "https://github.com/forstman1/inception-42/tree/main/srcs/requirements/bonus/ftp"
    click cAdvisor "https://github.com/forstman1/inception-42/tree/main/srcs/requirements/bonus/cadvisor"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef host fill:#333,color:#fff,stroke:#000,stroke-width:2px
    classDef config fill:#bbf,stroke:#333,stroke-width:1px
    classDef web fill:#8ecae6,stroke:#023047,stroke-width:1px
    classDef data fill:#a8dadc,stroke:#1d3557,stroke-width:1px
    classDef aux fill:#ffb703,stroke:#fb8500,stroke-width:1px
    classDef volume fill:#cdb4db,stroke:#6a4c93,stroke-width:1px,stroke-dasharray: 5 5
    classDef network fill:#e0fbfc,stroke:#2ec4b6,stroke-width:1px,stroke-dasharray: 2 2
```
