There is no single architecture that is correct for every Laravel application. A small CRUD application can remain close to Laravel's conventional structure. A complex system may introduce service classes, actions, domain objects, DTOs, policies, jobs, repositories, or modules where they solve real complexity.
A practical flow can be:
Request
-> Controller
-> Service/Action
-> Eloquent or Repository
-> Database
-> Event/Job
-> Response
The key principle is separation of responsibilities.
Scenario:
An order workflow may need inventory reservation, payment authorization, order creation, event publishing, email, and asynchronous fulfillment. Keeping all of that inside one controller makes testing and maintenance difficult.
Interview-level answer:
Architecture should follow complexity. Do not add layers simply to appear "enterprise." Add an abstraction when it isolates a changing concern, improves testability, or makes the domain easier to understand.
0 comments:
Post a Comment
Thanks