Skip to content

Commit 11c7c7c

Browse files
committed
Update the best practices section
Signed-off-by: Anton Fedurtsya <anton@fedurtsya.com>
1 parent d6f3a00 commit 11c7c7c

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,39 @@ We would like to encourage following ideas and principles in module development:
5858
* Separate contexts into their own folders (e.g. Greeting, Tracker, ProductVote)
5959
* Basics of DDD in module development
6060
* Controllers are our use cases and entry points
61+
* No business logic should be in controllers except proxying the request data to services and preparing responses
6162
* Services contain business logic
62-
* Infrastructure contains shop framework/database related code
63-
* Layered architecture within those contexts (e.g. Infrastructure, Service, Controller, Subscriber)
63+
* Infrastructure contains:
64+
* legacy/traditional shop framework related code, like Models
65+
* database related code
66+
* third party integrations that dont have clean interfaces
67+
* the interface itself could go to higher level in this case
68+
* Layered architecture within those contexts (e.g. Infrastructure, Service, Controller, Subscriber, Command)
6469
* Changing the implementation should not affect other layers
6570
* Interfaces are the contracts between layers
66-
* Data Transfer Objects (DTOs) used for data exchange between layers
67-
* Factories are responsible for creating DTOs (e.g. from database rows)
71+
* Data Transfer Objects (DTOs) used for data exchange between layers - not arrays
72+
* Data Objects are entities or value objects - put together.
73+
* No suffixes are going to DTOs and Data Objects - just use namespaces and folders to distinguish them
74+
* Factories could be used for creating DTOs and Data Objects (e.g. from database rows)
6875
* Centralizes mapping logic and makes it reusable and testable
76+
* Repositories are used for persisting and retrieving Data Objects/DTOs
6977
* Hexagonal architecture ideas
70-
* Ports(interfaces here) and adapters(implementations here)
71-
* Adapters depend on ports, not the other way round
78+
* Implementations should depend on interfaces
7279
* Application core is independent of external systems (as much as possible in the current context)
7380
* Dependency injection
7481
* Allows awesome testability and flexibility
7582
* Avoids usage of global state (Registry, oxNew, static calls)
7683
* Use factories to create model objects instead of oxNew directly
84+
* Static calls are still possible for simple utilities
7785
* SOLID principles
78-
* SRP and DIP in focus
86+
* SRP, DIP and OCP in focus
7987
* Clean architecture ideas
8088
* Dependencies point inwards
81-
* Business logic is independent of frameworks, databases, UIs
82-
* Avoid the extension of shop core classes as much as possible
89+
* eg. dont call the services that are in higher layers from the Infrastructure layer
90+
* you could skip the service layer to access the Repository from Controller if there are no additional logic needed
91+
* Business logic (Services) is independent of frameworks, databases, UI
92+
* eg. dont inject the request to the Service layer, but give only what service needs, from the Controller
93+
* Avoid the extension of the shop core classes as much as possible
8394
* Prefer event listeners, DI service decoration/replacement
8495
* If extension is necessary, follow minimal invasion principle
8596
* Tests are a good example of Unit usage

0 commit comments

Comments
 (0)