Discussion about this post

User's avatar
Christian Ledermann's avatar

I added this for agents:

## 📏 Code Quality Rule

Don't apply SOLID as a rigid checklist. Judge code by whether it's **composable, does one thing, predictable, idiomatic Python/FastAPI, and mirrors the domain** — not by rule compliance. Before adding an abstraction, ask if it's earning its keep.

Concretely:

- **No premature abstractions.** Don't add a repository interface, base service class, or dependency-injected abstraction for a single DB implementation "in case we swap Postgres for MySQL someday." Write the concrete query/service first; abstract only when a second real implementation exists.

- **No over-splitting.** Don't break a service/endpoint into multiple classes just to satisfy "single responsibility" if a plain function or module-level set of functions is clearer. FastAPI route handlers calling straightforward service functions is idiomatic — don't wrap everything in unnecessary classes.

- **Favor Pydantic/FastAPI idioms over generic OOP patterns.** Use dependency injection (`Depends`) where FastAPI expects it, not homegrown DI containers. Use Pydantic models for validation instead of manual validator classes.

- **DB layer: prefer explicit, readable queries over deep ORM abstraction layers.** Don't hide simple queries behind multiple inheritance layers or generic repository patterns unless the project already has that pattern established and reuses it.

- **Predictability over cleverness.** A teammate should be able to trace a request from route → service → DB call without jumping through interfaces that exist only for theoretical substitutability.

- **Match the codebase's existing idiom.** If the project already uses SQLAlchemy models directly in services, don't introduce a new abstraction layer unilaterally — consistency with existing patterns beats "correct" architecture in isolation.

**Before finalizing:** if an abstraction, interface, or split has no second concrete use case today, cut it.

Pradyumna's avatar

Very insightful Daniel. Great share.

1 more comment...

No posts

Ready for more?