A domain model describes the important concepts in a business and the rules that govern them. In a PHP application, a useful model helps prevent controllers, templates and database queries from becoming the only places where business behavior exists.
Identify domain concepts
Start with the language used by the people who understand the business. Identify entities with identity, value objects defined by their values, and operations that change business state. Avoid creating classes for every database table without first understanding what the concepts mean.
Keep invariants close to the model
An invariant is a rule that must remain true, such as a quantity being positive or a completed order not being edited as if it were a draft. Enforce important rules through explicit methods and validated constructors rather than relying only on form validation.
Separate persistence from business rules
Repositories or data mappers can translate between database records and domain objects. Keep SQL and persistence details out of core business decisions where practical. This separation makes rules easier to test without requiring a live database for every unit test.
Avoid overengineering
A small application may need only a few well-named services and value objects. Introduce richer domain patterns when they clarify real complexity, not because every project needs a large framework.
Checklist
- Use business language consistently in names.
- Identify entities, value objects and domain operations.
- Enforce important invariants in application code.
- Keep persistence details from dominating business rules.
- Add abstractions only when they make change safer.