How mitate-gengaku/nodejs-php-multistage-build works
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