Download the PHP package yntech/domain-forge without Composer
On this page you can find all versions of the php package yntech/domain-forge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yntech/domain-forge
More information about yntech/domain-forge
Files in yntech/domain-forge
Package domain-forge
Short Description Hexagonal architecture generator for Laravel. Provides Artisan commands for structuring domains following the principles of DDD and Screaming Architecture.
License MIT
Informations about the package domain-forge
Domain Forge
Domain Forge is a powerful Laravel package that streamlines the creation of domain modules following Hexagonal Architecture (Ports & Adapters) and Domain-Driven Design (DDD) principles. Generate complete, production-ready domain structures with a single command.
π Features
- β Complete DDD Structure - Automatically generates Application, Domain, and Infrastructure layers
- β Value Objects - Rich domain models with validation and type safety
- β Native PHP Enums - First-class support for PHP 8.1+ enums with helper methods
- β Auto-generated IDs - Smart UUID/ULID generation for entity identifiers
- β Type Safety - Nullable types, primitives, and enum support
- β Customizable Stubs - Publish and modify templates to fit your needs
- β Automatic Mappers - Eloquent β Domain entity mappers
- β Smart Validation - Password hashing, timestamp handling, and more
- β Rollback Support - Automatic cleanup on errors
- β Permission Checks - Validates write permissions before generation
π Requirements
- PHP 8.1 or higher
- Laravel 10.x or 11.x or higher
- Composer
π Installation
Install the package via Composer:
βοΈ Configuration
1. Configure Base Structure
Run the installation command to set up the base structure:
2. Update Composer Autoload
Add the following to your composer.json in the autoload.psr-4 section:
3. Refresh Autoload
π Usage
Basic Domain Generation
Create a simple domain module:
This generates:
Domain with Properties
Generate a domain with value objects:
Generated Value Objects:
ProductName(string)ProductPrice(float)ProductStock(int)ProductDescription(nullable string)
Entity Structure:
π― Property Types
Supported Types
| Type | Example | Value Object Method |
|---|---|---|
string |
name:string |
fromString(string) |
int |
age:int |
fromInt(int) |
float |
price:float |
fromFloat(float) |
bool |
active:bool |
fromBool(bool) |
?string |
description:?string |
fromNullableString(?string) |
?int |
quantity:?int |
fromNullableInt(?int) |
?float |
discount:?float |
fromNullableFloat(?float) |
?bool |
verified:?bool |
fromNullableBool(?bool) |
Nullable Types
Add ? prefix for nullable properties:
Generated Value Object:
π’ Enum Support
Creating Enums
Use the enum[value1|value2|value3] syntax:
Generated Enum Structure
File: src/Contexts/Order/Domain/Enums/OrderStatus.php
Using Enums in Your Code
Enum Examples
π Auto-Generated IDs
String IDs (UUID)
When you define an id:string property, Domain Forge automatically generates UUID methods:
Generated UserId Value Object:
Entity create() method excludes ID:
Integer IDs (Auto-increment)
For database auto-increment IDs:
Generated ProductId Value Object:
π Special Property Types
Password Fields
Properties containing "password" get special hashing methods:
Generated UserPassword Value Object:
Usage:
Timestamp Fields
Properties ending with _at are treated as timestamps:
These use fromString() or fromNullableString() methods automatically in fromPrimitives().
ποΈ Command Flags
--props
Define entity properties with their types:
--skip-model
Skip Laravel Eloquent model and migration generation:
Use case: When you don't need database persistence or already have the model.
π¨ Customization with Stubs
Publishing Stubs
Publish stub templates to your project:
This creates:
Customizing Stubs
Edit any stub file to change the generated code structure. For example, add timestamps to all entities:
Edit: stubs/domain-forge/entity.stub
Available Stub Variables
Each stub supports different replacement variables:
entity.stub:
{{ namespace }}- Full namespace{{ className }}- Class name{{ imports }}- Value Object/Enum imports{{ constructorParams }}- Constructor parameters{{ getters }}- Getter methods{{ createParams }}- create() parameters{{ createArgs }}- create() arguments{{ fromPrimitivesParams }}- fromPrimitives() parameters{{ fromPrimitivesArgs }}- fromPrimitives() arguments
value-object.stub:
{{ namespace }}{{ className }}{{ type }}- Property type{{ additionalMethods }}- Generated methods
enum.stub:
{{ namespace }}{{ className }}{{ cases }}- Enum cases{{ allMethod }}- all() method{{ fromStringMethod }}- Conversion methods
Force Overwrite Stubs
πΊοΈ Generated Mappers
When generating a domain with properties (and without --skip-model), Domain Forge creates a mapper:
File: src/Contexts/User/Infrastructure/Persistence/Mappers/UserMapper.php
Usage in Repository:
π Real-World Examples
E-Commerce Product
User Management System
Blog Post
Support Ticket System
Invoice System
π‘οΈ Error Handling & Rollback
Domain Forge includes automatic rollback on errors:
Output:
Permission Validation
Before generating, Domain Forge checks:
- Write permissions on
src/Contexts/ - Write permissions on
bootstrap/providers.php - Directory creation capabilities
Example error:
π Generation Summary
After successful generation, you'll see a detailed summary:
π§ Advanced Usage
Foreign Keys
Use *_id properties for foreign keys (they won't auto-generate):
author_id:stringβ UsesfromString()(nogenerate())category_id:intβ UsesfromInt()(nogenerate())
Combining Features
This creates:
- β
Auto-generated
id - β
Foreign key
customer_id(no generation) - β
Enum
status - β
Nullable
notesandpaid_at - β
Timestamp
created_at - β No Eloquent model
π Best Practices
1. Property Naming
2. Enum Values
3. Nullable Usage
Use nullable only when truly optional:
4. ID Strategy
Choose consistent ID strategy per project:
π― Domain-Driven Design Tips
Aggregates
Create separate domains for aggregates:
Value Objects
Rich domain models emerge from proper value objects:
Domain Events
Add events to your domain entities (manual step):
π Troubleshooting
Error: "No write permissions"
Error: "Class not found"
Enum ValueError
Property validation errors
Ensure property names follow rules:
- Start with lowercase letter
- Only alphanumeric and underscores
- No spaces or special characters
π§ Roadmap
v3.1 (Planned)
- [ ]
--dry-runflag for preview - [ ] Duplicate module detection
- [ ] Controller generation
- [ ] DTO generation
- [ ] Smart validations in ValueObjects
v3.2 (Planned)
- [ ] Test generation
- [ ] Event generation
- [ ] Command/Query handlers
- [ ] GraphQL support
Future
- [ ] Multi-language support
- [ ] Custom templates per project
- [ ] Migration generator from props
- [ ] Interactive mode
π€ Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
Running Tests
π License
This project is licensed under the MIT License. See the LICENSE file for details.
π Credits
Created and maintained by Allmacht.
π Support
- π§ Email: [email protected]
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
β Show Your Support
If you find this package helpful, please consider giving it a β on GitHub!
Made with β€οΈ by Allmacht
All versions of domain-forge with dependencies
illuminate/support Version ^12.2|^13.0
illuminate/console Version ^12.2|^13.0