# mitate-gengaku/test-multistage-build architecture

> Architecture diagram of the GitHub repository mitate-gengaku/test-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/test-multistage-build
- Repository: https://github.com/mitate-gengaku/test-multistage-build

## Overview

##### Project type and purpose
- This is a learning‐oriented, full-stack Dockerized application demonstrating multi-stage builds for Node.js (Next.js) and PHP (Laravel).
- The root contains two main code bases—“app” (Next.js frontend) and “api” (Laravel backend)—plus a “container” folder with Dockerfiles and a docker-compose.yml orchestrating five services.

##### File structure
- Top-level directories:
- api: Laravel PHP MVC application (Controllers, Models, routes, config, migrations, resources, tests).
- app: Next.js + React + TypeScript front end (pages/app, globals.css, layout.tsx, tests, Tailwind).
- container: per-service Dockerfiles (api, app, cache, db, web).
- docker-compose.yml: defines services “api,” “app,” “cache,” “db,” “web,” plus networks/volumes.
- Architectural hints: clean separation of API and UI, container-per-service pattern, reverse-proxy via “web.”

##### Extract README insights
- Purpose: to practice multi-stage Docker builds for both Node.js and PHP.

a. Main components:
- Client / Browser
- web container (Nginx reverse proxy)
- app container (Next.js frontend)
- api container (Laravel backend)
- cache container (Redis)
- db container (MySQL or PostgreSQL)
- Shared Docker network & volumes for code and persistent data
b. Relationships and interactions:
- Browser → web (HTTP/HTTPS)
- web → app for frontend routes and SSR
- web → api for API calls (e.g. /api/*)
- api ↔ db for data persistence (SQL queries)
- api ↔ cache for session or query caching (Redis)
- app may also call api directly (client-side fetch)
c. Architectural patterns & principles:
- Microservices-style container separation
- Reverse-proxy layer (web) isolating public endpoints
- MVC within api (Controllers, Models, Views)
- SSR/SSG within app (Next.js)
- Multi-stage Docker builds for lean images
d. Key technologies:
- Docker & Docker Compose
- Nginx (web container)
- Node.js, Next.js, React, TypeScript, Tailwind CSS (app)
- PHP, Laravel, Composer, Blade templates (api)
- Redis (cache)
- MySQL/PostgreSQL (db)
- Volumes for code hot-reload (app, api) and database persistence

##### Detail without overcomplicating
- Five docker-compose services and their runtime relationships.
- Ports (e.g., 80/443 on web, 3000 on app, 8000 on api).
- Volume mounts (code live-reload, db data, cache data).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Ingress Layer
    subgraph "Ingress Layer"
        Browser["Client Browser"]:::external
        Web["web (Nginx Reverse Proxy)"]:::infra
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        App["app (Next.js Frontend)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Api["api (Laravel Backend)"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        Cache["cache (Redis)"]:::data
        DB["db (MySQL/PostgreSQL)"]:::data
    end

    %% Orchestration
    Compose["docker-compose.yml"]:::infra

    %% Connections
    Browser -->|"HTTP/HTTPS"| Web
    Web -->|"For SSR & Assets"| App
    Web -->|"Proxy /api/*"| Api
    App -->|"Client-side API calls"| Api
    Api -->|"Reads/Writes"| DB
    Api -->|"Reads/Writes"| Cache
    Compose -.-> Web
    Compose -.-> App
    Compose -.-> Api
    Compose -.-> Cache
    Compose -.-> DB

    %% Click Events
    click App "https://github.com/mitate-gengaku/test-multistage-build/tree/main/container/app/Dockerfile"
    click Api "https://github.com/mitate-gengaku/test-multistage-build/tree/main/container/api/Dockerfile"
    click Web "https://github.com/mitate-gengaku/test-multistage-build/tree/main/container/web/Dockerfile"
    click Cache "https://github.com/mitate-gengaku/test-multistage-build/tree/main/container/cache/Dockerfile"
    click DB "https://github.com/mitate-gengaku/test-multistage-build/tree/main/container/db/Dockerfile"
    click Compose "https://github.com/mitate-gengaku/test-multistage-build/blob/main/docker-compose.yml"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#2a5fbd,color:#000;
    classDef backend fill:#d4edda,stroke:#278a0e,color:#000;
    classDef data fill:#fff3cd,stroke:#b88b00,color:#000;
    classDef infra fill:#f8d7da,stroke:#a71d2a,color:#000;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#000;
```
