This project is a microservices-based architecture that consists of two main services:
- Login Service: Handles user authentication and communicates with the Log Service to fetch recent login logs.
- Log Service: Stores and retrieves logs related to various services.
These services are built with Laravel and Docker, with RabbitMQ facilitating communication between them. Each service is isolated within its own Docker network and has access to its own database.
- Login Service: Handles user authentication and retrieves logs related to user actions.
- Log Service: Collects and stores logs for various microservices. It provides APIs to query logs based on service names and filters.
- RabbitMQ: Facilitates asynchronous communication between services.
- MySQL: Each service has its own MySQL database, ensuring data isolation.
- Laravel: PHP framework used for building both services.
- Docker: Containerization of services for easy deployment and management.
- RabbitMQ: Message broker used for asynchronous communication.
- MySQL: Relational database for persistent data storage.
- Postman: For API documentation and testing.
-
URL:
http://localhost:8000
-
Responsibilities:
- User authentication.
- Fetching recent login logs from the Log Service.
-
Key Endpoints:
POST /api/login
: Authenticate a user.GET /api/logs
: Retrieve recent login logs (requires authentication).
-
Responsibilities:
- Storing and retrieving logs for various services.
- Providing filtered log data based on service name, identifier, type, etc.
-
Key Endpoints:
GET /api/logs
: Retrieve logs based on filters.
- Docker: Ensure Docker is installed on your system.
- Docker Compose: Make sure Docker Compose is available.
-
Clone the Repository:
git clone https://github.com/winkersco/laravel-microservices cd laravel-microservices
-
Build and Start the Services:
docker-compose up --build -d
-
Run Migrations:
Run the following commands inside the
login-service
andlog-service
containers to set up the databases:docker exec -it login-service php artisan migrate docker exec -it log-service php artisan migrate
-
(Optional) Seed the Database:
docker exec -it login-service php artisan db:seed
- Login Service: Accessible at
http://localhost:8000
- Log Service: Is not accessible by public
Both services are running inside Docker containers, and you can interact with them using the provided endpoints.
Each service has its own .env
file. The most critical variables are:
DB_CONNECTION=mysql
DB_HOST=login-db
DB_PORT=3306
DB_DATABASE=login_db
DB_USERNAME=login
DB_PASSWORD=secret
RABBITMQ_HOST=rabbitmq
RABBITMQ_PORT=5672
DB_CONNECTION=mysql
DB_HOST=log-db
DB_PORT=3306
DB_DATABASE=log_db
DB_USERNAME=log
DB_PASSWORD=secret
RABBITMQ_HOST=rabbitmq
RABBITMQ_PORT=5672
Detailed API documentation is available via Postman. You can view the documentation at the following link:
You can also download the Postman collection directly from the repository:
This documentation includes all available endpoints, request/response examples, and necessary authentication details. The Postman collection provides a comprehensive guide to interacting with the APIs for both the Login Service and the Log Service, including examples for authentication, logging actions, and querying logs.
- Database Connection Issues: Ensure that each service's
.env
file points to the correct database container. - RabbitMQ Communication Issues: Ensure that both services are connected to the
microservices
network and that RabbitMQ is running.
Contributions are welcome! Please fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.