How koutsoumposval/laravel-microservices works
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.”).