| name | best-practices |
| description | Read when adding a new function, module, or component, or when a file is growing large enough that splitting it is worth considering. Covers SOLID design principles, minimal interfaces, composition over inheritance, and the size and complexity limits for functions, files, and nesting depth. |
Best Practices
Design Principles
Apply SOLID principles to create maintainable, scalable components.
Single Responsibility
A function or module should have one reason to change. If it has two, split it.
Do not mix data fetching, business logic and presentation in the same component.
Small files are welcome.
Minimal Interfaces
Components should only accept the data that they actually use. Avoid passing entire objects
when a few fields suffice. Create an abstracted interface that only exposes what the component
needs.
Composition over Inheritance
Don't create deep class hierarchies. Build complex behavior by combining small, focused units.
Use dependency injection and dependency inversion.
Managing Complexity
Split Large Units
When adding new code, always consider splitting the logic into a new function, component or a file.
As a rule of thumb:
- Functions should be under 20 lines
- Files should be under 400 lines
Reducing Complexity
Keep logic easy to understand by reducing horizontal, vertical and cyclomatic complexity.
As a rule of thumb:
- Nesting depth should be under 3 levels - use early returns to flatten
- Conditional branches per function should be limited - extract complex logic into separate functions
- Extract helper variables instead of writing complex inline expressions