Introducing Mojura Architecture
In the ever-evolving world of web development, maintaining a scalable and readable codebase is crucial. Enter Mojura Architecture, a set of principles designed to enhance your development workflow by promoting scalability, maintainability, and readability. Inspired by the Japanese word "モジュラ" (module), Mojura Architecture breaks down your application into manageable units, making it easier to scale, maintain, and understand.
Key Benefits
Scalability
By breaking down your application into smaller, manageable units, Mojura Architecture allows you to easily scale your project as it grows. This modular approach ensures that each part of your application can be developed and scaled independently.
Maintainability
With a clear separation of concerns, Mojura Architecture makes it easier to maintain and update your codebase. This reduces the risk of bugs and improves overall code quality, making your application more robust and reliable.
Readability
The structured approach of Mojura Architecture ensures that your code is organized and easy to understand. This makes it simpler for new developers to get up to speed and contributes to a more efficient development process.
Concept
-
Route
- Call Controller functions
-
Controller
- Serve the Features
- Return Response received from Feature to the Request
-
Feature
- Validate the Request
- Run the Job by passing the request parameters
- Collect Return Data from Job
- Prepare Response Data
- Return the HTTP Response to the Controller Method
-
Request
- Authorize the Request (Optional)
- Implement HTTP Request validating
-
Job
- Do the actual work by implementing the business logic
Principles
- Feature Serves a Single Purpose: Keep features simple and focused.
- Job Executes a Single Responsibility: Ensure each job handles one responsibility, even if it involves multiple related functions.
- Modules Shouldn’t Cross: Each module should be self-contained and should not perform tasks that belong to other modules.
- Apply Decoupling Techniques: Use shared helper classes to enhance code reusability and maintainability.
- Features Shall Not Call Other Features: Maintain feature independence.
- Jobs Shall Not Call Other Jobs: Keep business logic concise and organized.
- Write Code That Humans Can Read: Prioritize readability for easier maintenance and collaboration.
Naming Conventions
Consistent naming for files and classes is encouraged for clarity and readability. Here are some examples:
- Module: [Subject]Module (e.g., UserModule)
- Controller: [Subject]Controller (e.g., UserController)
- Feature: [Operation][Subject]Feature (e.g., CreateUserFeature)
- Job: [Operation][Subject]Job (e.g., CreateUserJob)
- Request: [Operation][Subject]Request (e.g., CreateUserRequest)
Directory Structure
Mojura Architecture promotes a clear and organized directory structure:
laravel-project/
├── app/
│ ├── Modules/
│ │ ├── YourModule1/
│ │ │ ├── Features/
│ │ │ ├── Http/
│ │ │ │ ├── Controllers/
│ │ │ │ └── Requests/
│ │ │ └── Jobs/
│ │ ├── YourModule2/
│ │ │ ├── Features/
│ │ │ ├── Http/
│ │ │ │ ├── Controllers/
│ │ │ │ └── Requests/
│ │ │ └── Jobs/
│ │ ├── YourModuleN/
│ │ │ ├── Features/
│ │ │ ├── Http/
│ │ │ │ ├── Controllers/
│ │ │ │ └── Requests/
│ │ │ └── Jobs/
├── routes/
│ ├── api/
│ └── web/
└── .env
Mojura Laravel Package
A lightweight Laravel Package that implements the Mojura Architecture principles.
Installation
To install the Mojura package into your Laravel 10+ application using Composer:
composer require innoaya/mojura
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=mojura-config
Generating Components
- Route:
php artisan mojura:route [RouteFileName] [VersionDirectory] [--web] [--force]
- Controller:
php artisan mojura:controller [Controller] [Module] [Directory] [--force]
- Request:
php artisan mojura:request [Request] [Module] [Directory] [--force]
- Feature:
php artisan mojura:feature [Feature] [Module] [Directory] [--force]
- Job:
php artisan mojura:job [Job] [Module] [Directory] [--force]
Documentation
Source Code
https://github.com/innoaya/mojura
Starter Kit
This starter kit provides a fully implemented backend solution based on the Mojura Architecture concepts, designed to speed up your development process. It includes robust features for authentication, authorization, user management, and security, making it a comprehensive starting point for building scalable applications.
https://github.com/innoaya/mojura-laravel-starter
Top comments (0)