A Laravel 11-based system for managing restaurant orders, tracking ingredient stock levels, and automating low-stock alerts.
- Order placement with stock deduction
- Ingredient stock management
- Automatic low-stock email alerts
- Unit tests for repositories and core functionality
git clone https://github.com/hakeem23/restaurant-system.git
cd restaurant-systemcomposer installCopy the example environment file:
cp .env.example .envThen update .env with your database credentials.
To use Docker for MySQL and Laravel services, run:
docker-compose up -dThis will create restaurant_system and restaurant_system_test databases.
If not using Docker, manually create the databases:
CREATE DATABASE restaurant_system;
CREATE DATABASE restaurant_system_test;php artisan migrate --seedphp artisan servePOST /api/ordersRequest Body:
{
"products": [
{
"product_id": 1,
"quantity": 2
}
]
}To run unit tests, execute:
php artisan testTo run tests using the testing database:
php artisan test --env=testing- Ensure the
.envfile is correctly configured for both local and testing environments. - If using Docker, confirm the database containers are running.
- Debug logs can be found in
storage/logs/laravel.log.
- The Repository Pattern is used to abstract database queries and promote separation of concerns.
- Each model has its corresponding repository handling data interactions (e.g.,
OrderRepository,ProductRepository,IngredientRepository). - Benefits:
- Keeps controllers clean and focused on business logic.
- Improves testability by allowing dependency injection.
- Encapsulates complex queries in dedicated classes.
- A Service Layer is introduced to handle business logic, making controllers lightweight.
- Example:
OrderServiceprocesses order creation, stock deduction, and low-stock alerts.
- Dependencies such as repositories and services are injected into controllers, improving modularity and testability.
- Each class has a single responsibility:
- Repositories handle database interactions.
- Services handle business logic.
- Controllers handle request validation and response formatting.
- The system is open for extension but closed for modification.
- Example: New notification methods (e.g., SMS, Slack) can be added without modifying existing email alerts.
- Uses a normalized relational schema:
productstable stores product information.ingredientstable tracks stock levels.orderstable records customer orders.order_productpivot table maintains many-to-many relationships between orders and products.
- Events and Listeners are used for handling asynchronous tasks like sending email notifications.
- Example: When an order is placed, an event triggers an email alert if stock is low.
- Unit and feature tests are written for repositories, services, and controllers.
- Mocks and fakes are used to isolate dependencies.
This project follows best practices in design patterns, SOLID principles, and software architecture to ensure maintainability, scalability, and testability.