# nomura-kainos/japanese-ddd-sample architecture

> Architecture diagram of the GitHub repository nomura-kainos/japanese-ddd-sample, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nomura-kainos/japanese-ddd-sample
- Repository: https://github.com/nomura-kainos/japanese-ddd-sample

## Overview

##### Project Type and Purpose
- This project is a Laravel-based application that uses Docker to set up its development environment. It is designed to run a full-stack Laravel application with a well‐structured, domain-driven approach using packages for features such as cart management, product handling, order processing, etc.

a. Docker Infrastructure:
– Containers/Services: PHP (the Laravel runtime environment), MySQL (database server), and nginx (web server).
– Configuration files: docker-compose.yml, docker folder (with Dockerfiles and configurations for db, nginx, and php).
b. Laravel Application (src folder):
– Core Application Layers:
- App – contains the Laravel “app” code (controllers, middleware, providers, etc.).
- Config, Database (migrations and seeds), Resources (views, assets, translations) and Public folder.
c. Domain/Module Packages (inside src/packages):
– Separate modules implementing domain logic via a domain-driven design. For example:
- Cart
- Product
- Product Category
- Order
- Featured (特集)
- Authentication (認証)
– Each package typically splits into layers:
- Application (ユースケース)
- Infrastructure (エロクアント, レスポンスデータ, リポジトリ)
- Domain (モデル and interfaces)
- Presentation (コントローラ, ビューモデル, フォームリクエスト)

##### Relationships and Interactions
- The Docker containers work together to host and run the Laravel application. The nginx container acts as the entry point (frontend web server) that passes requests to the PHP container, which in turn interacts with the MySQL container for persistent storage.
- Inside the Laravel app, HTTP requests pass through middleware and controllers (located under src/app/Http and in each package’s presentation layer). These controllers invoke use cases (アプリ/ユースケース in each domain package) that interact with domain models and repository interfaces.
- The infrastructure layer in each package implements data persistence (using Eloquent models under エロクアント, repository classes, and query services) and external services such as email and file uploads.
- The common “packages/共通” cover shared functionalities (such as ID generation, transaction management, domain events, and login user handling).

##### Architectural Patterns and Design Principles
- Domain-Driven Design: The separation into packages based on bounded contexts (Cart, Product, etc.) with clear divisions into application, domain, infrastructure, and presentation layers.
- MVC: The classic separation of controllers (HTTP layer), models (domain and Eloquent), and views (Blade templates under resources/views).
- Docker Microservices (development environment): Leveraging Docker Compose to orchestrate multiple services running in separate containers.
- Dependency Injection and Service Providers: Laravel providers (in src/app/Providers) are used to register services and bind interfaces to their implementations (such as repository interfaces).

- Component has a clear and descriptive label.
– Client → nginx → PHP container → Laravel controllers → Domain Use Cases → Database (MySQL) via repository interfaces.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Docker Infrastructure
    subgraph "Docker Infrastructure"
        DC1["docker-compose.yml"]:::dockerFile
        subgraph "Docker Services"
            DNG["nginx (Web Server)"]:::dockerService
            DP["php (Laravel Runtime)"]:::dockerService
            DM["MySQL (Database)"]:::dockerService
            DDB["docker/db"]:::dockerDir
            DNGD["docker/nginx"]:::dockerDir
            DPHP["docker/php"]:::dockerDir
        end
    end

    %% Laravel Application Cluster
    subgraph "Laravel Application"
        subgraph "Core Laravel"
            LAPP["src/app"]:::laravel
            LCONFIG["src/config"]:::laravel
            LDB["src/database"]:::laravel
            LRES["src/resources"]:::laravel
            LPUB["src/public"]:::laravel
        end

        subgraph "Domain Modules"
            %% Cart Module
            subgraph "Cart Module"
                CART_APP["Application"]:::module
                CART_DOM["Domain"]:::module
                CART_INF["Infrastructure"]:::module
                CART_PRES["Presentation"]:::module
            end
            %% Product Module
            subgraph "Product Module"
                PROD_APP["Application"]:::module
                PROD_DOM["Domain"]:::module
                PROD_INF["Infrastructure"]:::module
                PROD_PRES["Presentation"]:::module
            end
            %% Product Category Module
            subgraph "Product Category Module"
                PROD_CAT_APP["Application"]:::module
                PROD_CAT_DOM["Domain"]:::module
                PROD_CAT_INF["Infrastructure"]:::module
                PROD_CAT_PRES["Presentation"]:::module
            end
            %% Order Module
            subgraph "Order Module"
                ORDER_APP["Application"]:::module
                ORDER_DOM["Domain"]:::module
                ORDER_INF["Infrastructure"]:::module
                ORDER_PRES["Presentation"]:::module
            end
            %% Featured Module
            subgraph "Featured Module"
                FEAT_APP["Application"]:::module
                FEAT_DOM["Domain"]:::module
                FEAT_INF["Infrastructure"]:::module
                FEAT_PRES["Presentation"]:::module
            end
            %% Authentication Module
            subgraph "Authentication Module"
                AUTH_APP["Application"]:::module
                AUTH_DOM["Domain"]:::module
                AUTH_INF["Infrastructure"]:::module
                AUTH_PRES["Presentation"]:::module
            end
            %% Common/Shared Domain Logic
            subgraph "Common Module"
                COMMON["Shared Domain Logic"]:::module
            end
        end
    end

    %% Connections between Docker components
    DNG -->|"forwards"| DP
    DP -->|"queries"| DM

    %% Docker to Laravel application integration
    DP -->|"runs"| LAPP

    %% Core Laravel interactions
    LAPP -->|"uses"| LCONFIG
    LAPP -->|"accesses"| LDB
    LAPP -->|"renders"| LPUB
    LAPP -->|"loads"| LRES

    %% Domain Modules internal flows
    CART_PRES -->|"calls"| CART_APP
    CART_APP -->|"invokes"| CART_DOM
    CART_APP -->|"uses"| CART_INF

    PROD_PRES -->|"calls"| PROD_APP
    PROD_APP -->|"invokes"| PROD_DOM
    PROD_APP -->|"uses"| PROD_INF

    PROD_CAT_PRES -->|"calls"| PROD_CAT_APP
    PROD_CAT_APP -->|"invokes"| PROD_CAT_DOM
    PROD_CAT_APP -->|"uses"| PROD_CAT_INF

    ORDER_PRES -->|"calls"| ORDER_APP
    ORDER_APP -->|"invokes"| ORDER_DOM
    ORDER_APP -->|"uses"| ORDER_INF

    FEAT_PRES -->|"calls"| FEAT_APP
    FEAT_APP -->|"invokes"| FEAT_DOM
    FEAT_APP -->|"uses"| FEAT_INF

    AUTH_PRES -->|"calls"| AUTH_APP
    AUTH_APP -->|"invokes"| AUTH_DOM
    AUTH_APP -->|"uses"| AUTH_INF

    %% Laravel Application integration with Domain Modules
    LAPP -->|"integrates"| CART_APP
    LAPP -->|"integrates"| PROD_APP
    LAPP -->|"integrates"| PROD_CAT_APP
    LAPP -->|"integrates"| ORDER_APP
    LAPP -->|"integrates"| FEAT_APP
    LAPP -->|"integrates"| AUTH_APP
    LAPP -->|"integrates"| COMMON

    %% Click Events
    click DC1 "https://github.com/nomura-kainos/japanese-ddd-sample/blob/develop/docker-compose.yml"
    click DDB "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/docker/db"
    click DNGD "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/docker/nginx"
    click DPHP "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/docker/php"
    click LAPP "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/app"
    click LCONFIG "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/config"
    click LDB "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/database"
    click LRES "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/resources"
    click LPUB "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/public"
    click CART_PRES "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/packages/カート"
    click PROD_PRES "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/packages/商品"
    click PROD_CAT_PRES "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/packages/商品カテゴリ"
    click ORDER_PRES "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/packages/注文"
    click FEAT_PRES "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/packages/特集"
    click AUTH_PRES "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/packages/認証"
    click COMMON "https://github.com/nomura-kainos/japanese-ddd-sample/tree/develop/src/packages/共通"

    %% Styles
    classDef dockerFile fill:#f9f,stroke:#333,stroke-width:2px;
    classDef dockerDir fill:#ccf,stroke:#333,stroke-width:2px;
    classDef dockerService fill:#cfc,stroke:#333,stroke-width:2px;
    classDef laravel fill:#fcf,stroke:#333,stroke-width:2px;
    classDef module fill:#cff,stroke:#333,stroke-width:2px;
```
