# mitate-gengaku/nodejs-php-multistage-build architecture

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

- Interactive diagram: https://gitdiagram.com/mitate-gengaku/nodejs-php-multistage-build
- Repository: https://github.com/mitate-gengaku/nodejs-php-multistage-build

## Overview

##### Project Type and Purpose
- This is a containerized full-stack sample application built to learn Docker multi-stage builds.
- The front-end is a Next.js/React app (“app” directory, Node.js), the back-end is a Laravel REST API (“api” directory, PHP), and there’s orchestration via Docker Compose with separate containers for the app, API, cache, database, and web server.

##### File-Structure Analysis
- Top-level:
- api/ – Laravel project (PHP code, controllers, models, migrations, views, config, tests, Vite assets).
- app/ – Next.js project (React pages, CSS, tests, configs).
- container/ – Dockerfiles for each service (api, app, cache, db, web), plus supporting config (nginx.conf, php.ini).
- docker-compose.yml – Defines services, networks, volumes.
- Key patterns: distinct service per container, 12-factor principles (environment files, separate config, ephemeral containers).

##### README Insights
- “Nodejs and PHP containers for multi-stage build learning”

##### Components
a. Front-end (Next.js container)
b. Back-end API (Laravel container)
c. Database (e.g., MySQL/Postgres container)
d. Cache (Redis container)
e. Web server / reverse proxy (Nginx container)
f. Docker Compose orchestrator (network & volume layer)
g. Developer host (build context)

##### Relationships & Data Flows
- User → Nginx (ports 80/443)
- Nginx → Next.js (Node) for “app” requests
- Nginx → Laravel (php-fpm) for “api” requests
- Laravel → Database (SQL queries)
- Laravel → Redis (session, cache, queue)
- Next.js → Laravel API (fetch/XHR)
- Docker Compose manages the private network connecting all containers

##### Architectural Patterns & Design Principles
- Multi-stage Docker builds: separate “build” and “runtime” stages in Dockerfiles.
- Service isolation: each major subsystem in its own container.
- Clear separation between front-end (Node) and back-end (PHP).
- Externalized configuration via environment files (.env, .env.example).
- Asset bundling via Vite (Laravel) and Next.js build.

##### Technologies & Frameworks
- Next.js, React, Tailwind CSS, Playwright (E2E tests)
- Laravel, PHP, Composer, PHPUnit
- Vite (for asset compilation in Laravel)
- Nginx, Redis, MySQL/Postgres (or whichever DB you select)
- Docker Engine, Docker Compose

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Entry
    User["User"]:::external

    %% Infrastructure Layer
    subgraph "Docker Compose" 
        direction TB
        DC[/"docker-compose.yml"/]:::infra
        DC --- web_nginx
        DC --- app_nextjs
        DC --- api_laravel
        DC --- db_mysql
        DC --- cache_redis
    end

    %% Web Server
    web_nginx["web_nginx (Nginx)\nPorts: 80/443"]:::infra
    web_nginx -.->|"reverse proxy"| app_nextjs
    web_nginx -.->|"reverse proxy"| api_laravel

    %% Frontend Layer
    app_nextjs["app_nextjs\nNext.js (Node.js)\nBuild: multi-stage"]:::frontend
    app_nextjs -->|"REST calls"| api_laravel

    %% Backend Layer
    api_laravel["api_laravel\nLaravel (PHP)\nBuild: multi-stage"]:::backend
    api_laravel -->|"SQL"| db_mysql
    api_laravel -->|"TCP:6379"| cache_redis

    %% Data Layer
    db_mysql["db_mysql\nMySQL/Postgres"]:::data
    cache_redis["cache_redis\nRedis"]:::data

    %% Traffic Flow
    User -->|"HTTP(S) request"| web_nginx

    %% Legend
    subgraph Legend
        direction TB
        L1["Box = Container/Service"]:::legend
        L2["Cylinder = Database"]:::legend
        L3["Hexagon = Cache"]:::legend
        L4["Dashed arrow = Proxy/Route"]:::legend
    end

    %% Click Events
    click app_nextjs "https://github.com/mitate-gengaku/nodejs-php-multistage-build/tree/main/app/"
    click app_nextjs "https://github.com/mitate-gengaku/nodejs-php-multistage-build/tree/main/container/app/Dockerfile"
    click app_nextjs "https://github.com/mitate-gengaku/nodejs-php-multistage-build/blob/main/app/package.json"
    click app_nextjs "https://github.com/mitate-gengaku/nodejs-php-multistage-build/blob/main/app/src/app/page.tsx"

    click api_laravel "https://github.com/mitate-gengaku/nodejs-php-multistage-build/tree/main/api/"
    click api_laravel "https://github.com/mitate-gengaku/nodejs-php-multistage-build/tree/main/container/api/Dockerfile"
    click api_laravel "https://github.com/mitate-gengaku/nodejs-php-multistage-build/blob/main/api/composer.json"
    click api_laravel "https://github.com/mitate-gengaku/nodejs-php-multistage-build/blob/main/api/app/Http/Controllers/Controller.php"

    click db_mysql "https://github.com/mitate-gengaku/nodejs-php-multistage-build/tree/main/container/db/Dockerfile"
    click db_mysql "https://github.com/mitate-gengaku/nodejs-php-multistage-build/blob/main/docker-compose.yml"

    click cache_redis "https://github.com/mitate-gengaku/nodejs-php-multistage-build/tree/main/container/cache/Dockerfile"
    click cache_redis "https://github.com/mitate-gengaku/nodejs-php-multistage-build/blob/main/docker-compose.yml"

    click web_nginx "https://github.com/mitate-gengaku/nodejs-php-multistage-build/tree/main/container/web/Dockerfile"
    click web_nginx "https://github.com/mitate-gengaku/nodejs-php-multistage-build/blob/main/container/web/nginx.conf"
    click web_nginx "https://github.com/mitate-gengaku/nodejs-php-multistage-build/blob/main/container/web/default.conf"
    click web_nginx "https://github.com/mitate-gengaku/nodejs-php-multistage-build/blob/main/docker-compose.yml"

    click DC "https://github.com/mitate-gengaku/nodejs-php-multistage-build/blob/main/docker-compose.yml"
    click DC "https://github.com/mitate-gengaku/nodejs-php-multistage-build/tree/main/container/"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef infra fill:#ddd,stroke:#333,stroke-width:1px
    classDef frontend fill:#bbf,stroke:#333,stroke-width:1px
    classDef backend fill:#bfb,stroke:#333,stroke-width:1px
    classDef data fill:#fb8,stroke:#333,stroke-width:1px
    classDef legend fill:#fff,stroke:#000,stroke-width:0.5px,stroke-dasharray: 2 2
```
