Laravel Brick Architecture Documentation
Overview
This documentation provides an overview of the Laravel project structure following the Brick architecture. It outlines the purpose of each folder and how different components interact within the system.
Folder Structure
1. Domain/
- This directory contains the core business logic and domain entities.
2. DTOs/ (Data Transfer Objects)
- Used for structuring data between different layers.
- Ensures data consistency when transferring information between controllers, services, and repositories.
- Helps in enforcing a clear contract for data exchange.
3. Http/
- Houses controllers, middleware, and request handling logic.
- Divided into:
- Controllers/: Handles user requests and responses.
- Requests/: Defines validation and authorization rules for incoming requests.
4. Models/
- Contains Eloquent models, representing database tables.
- Defines relationships, scopes, and accessors/mutators.
- Strictly used for database interactions and mapping.
5. Repositories/
- Manages data access and encapsulates query logic.
- Implements repository patterns to separate business logic from database queries.
- Works as an abstraction layer between Models and Services.
6. Services/
- Contains the business logic of the application.
- Acts as a bridge between controllers and repositories.
- Handles complex operations and orchestrates multiple dependencies.
Initialization Variables
The system includes configurable initialization variables:
vars:
init_app:
type: boolean
default: false
prompt: Initialize your project?
feature_name:
type: string
description: Your feature name
default: template
prompt: What is your feature name?
Explanation of Variables:
- init_app: Determines whether the project should be initialized during setup.
- feature_name: Defines the name of the feature being created, defaulting to "template".
Best Practices
- Follow the Separation of Concerns principle to keep layers distinct and maintainable.
- Use DTOs to ensure consistent data flow between layers.
- Keep Repositories independent of Laravel-specific features to enhance flexibility.
- Write Services that handle core logic and avoid bloating controllers with business rules.
This documentation serves as a guide to understanding and using the Laravel Brick architecture efficiently. π