# koutsoumposval/laravel-microservices architecture

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

- Interactive diagram: https://gitdiagram.com/koutsoumposval/laravel-microservices
- Repository: https://github.com/koutsoumposval/laravel-microservices

## Overview

##### Project Type and Purpose
- This project is a demonstration of microservices (or “pseudo-microservices”) built using Laravel/Lumen. It sets up three distinct web services—user, order, and what is referred to as "product" in the README (depicted as the “inventory” service in the file tree)—and an API gateway.
- Docker is used to containerize each service, and Traefik is employed as a reverse proxy. The project emphasizes separation of concerns, unique entry points per service, and the use of Guzzle on the API gateway to interact with the services.

##### File Structure
- Top-level directories include:
- api-gateway: Contains an API that acts as a gateway using Laravel/Lumen and Guzzle to connect to the microservices.
- user, order, inventory: Each of these directories represents an individual web service. They each follow a standard Laravel directory structure with controllers, middleware, providers, and so on.
- docker: Contains Dockerfiles and docker-compose configuration for setting up PHP/Apache containers for each service as well as the Traefik reverse proxy container.
- The file tree reveals that each service is developed in a similar manner (with artisan, bootstrap, routes, and public directories), indicating a consistent architectural approach across the microservices.

##### Components
a. Main Components:
- External Clients: Represent users or systems interacting with the application via web browsers or API calls.
- Traefik Reverse Proxy: Positioned at the front, this routes incoming traffic based on domain rules. Mark it as a critical gateway.
- API Gateway Container: A dedicated container running the API gateway application that uses Guzzle to communicate with downstream services.
- Microservice Containers: Separate containers for each web service—user, order, and inventory (product). Each container encapsulates its own application logic and database layer (if integrated later).
- Docker Environment: Optionally illustrate that all service containers and the proxy are orchestrated through Docker Compose, with containers connected via the ‘traefik_webgateway’ network.

b. Relationships and Interactions:
- That each microservice is an isolated component (with the potential to later add a database container) that communicates only through their API endpoints.

c. Architectural Patterns and Design Principles:
- Microservices Separation: Emphasize that each service is independently managed and containerized.
- API Gateway Pattern: The gateway serves as a façade, encapsulating the complexity of the multiple services.
- Containerization: All components are deployed in Docker, hinting at a clear separation in deployment environments.
- Reverse Proxy: Traefik is used to manage routing and service discovery.
- Use of Laravel/Lumen Frameworks: Each service follows a standard Laravel/Lumen structure, as evident by directories like app, routes, and public.

d. Relevant Technologies:
- Laravel/Lumen for building the web services and API gateway.
- PHP (using the php:7.1-apache image) for runtime.
- Docker and Docker Compose for container orchestration.
- Traefik as the reverse proxy.
- Guzzle HTTP Client for inter-service communication in the API gateway.

- Use clear labels for each component:
- External Clients, Traefik Proxy, API Gateway, User Service, Order Service, Inventory Service, and (optionally) Database or messaging components if augmented later.
- Incoming traffic from clients via Traefik.
- Requests forwarded from the API Gateway to individual microservices.
- Reverse proxy versus microservice containers.
- Infrastructure-level components (Docker, Traefik) versus application-level components (API gateway and individual services).
- Incorporate annotations to explain flows (e.g., “HTTP request via Guzzle” or “Routing by domain names like user.lm.local, order.lm.local, etc.”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Application Layer"
        EC("External Clients"):::external
        TR("Traefik Reverse Proxy"):::proxy
        AG("API Gateway App"):::app
        US("User Service App"):::app
        OS("Order Service App"):::app
        IS("Inventory Service App"):::app
    end

    subgraph "Docker Environment"
        TRC("Traefik Container"):::container
        AGC("API Gateway Container"):::container
        USC("User Service Container"):::container
        OSC("Order Service Container"):::container
        ISC("Inventory Service Container"):::container
    end

    %% Connections within Application Layer
    EC -->|"HTTPRequest"| TR
    TR -->|"RoutesAPI"| AG
    AG -->|"HTTPviaGuzzle"| US
    AG -->|"HTTPviaGuzzle"| OS
    AG -->|"HTTPviaGuzzle"| IS

    %% Connections from Application Layer to Docker Environment
    TR ---|"RunningIn"| TRC
    AG ---|"ContainerizedIn"| AGC
    US ---|"ContainerizedIn"| USC
    OS ---|"ContainerizedIn"| OSC
    IS ---|"ContainerizedIn"| ISC

    %% Click Events for Application Components
    click AG "https://github.com/koutsoumposval/laravel-microservices/tree/master/api-gateway/"
    click US "https://github.com/koutsoumposval/laravel-microservices/tree/master/user/"
    click OS "https://github.com/koutsoumposval/laravel-microservices/tree/master/order/"
    click IS "https://github.com/koutsoumposval/laravel-microservices/tree/master/inventory/"

    %% Click Events for Docker Container Components
    click AGC "https://github.com/koutsoumposval/laravel-microservices/tree/master/docker/api-gateway/php-apache/"
    click USC "https://github.com/koutsoumposval/laravel-microservices/tree/master/docker/user/php-apache/"
    click OSC "https://github.com/koutsoumposval/laravel-microservices/tree/master/docker/order/php-apache/"
    click ISC "https://github.com/koutsoumposval/laravel-microservices/tree/master/docker/inventory/php-apache/"
    click TRC "https://github.com/koutsoumposval/laravel-microservices/blob/master/docker/docker-compose.yml"

    %% Styles
    classDef external fill:#fef2cc,stroke:#d4a017,stroke-width:2px;
    classDef proxy fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef app fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef container fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
```
