15/11/2019
Code decoupling
Problems
Our code is:
- Hard to refactor. Impossible to refactor a specific module separately.
- Any refactor is very likely to break something without us knowing.
- Hard to learn, understand and use.
- Hard to reuse some of its parts.
- Hard to test, tests run slow and coverage is little. Changes inside a module force rewriting tests outside of it.
Solution
Make use of:
- Modularizing the app further. More small modules. Most important ones are: transactions, payments, timelines, packages.
- Creating module APIs and implementing them (using existing code at first)
- Events and listeners instead of hardcoding dependencies
- Lowering the amount of cross-dependencies
Tight coupling

- Cohesion (связность) - inside of the modules. Can be low or high.
- Coupling (зацепление) - between modules. Must be low.
Module API
Components:
- Interfaces for any external APIs (services, repositories etc)
- Enums that are used in the API
- Events that can be listened externally
- Transformers
- Models
Discussion
Code decoupling
By TenantCloud
Code decoupling
PHP/Laravel code decoupling
- 150