u/Comfortable_Tax8338

I'm building a FastAPI backend with a layered architecture (routes, services, CRUD, models).

Right now:

- CRUD handles direct DB operations

- Services contain business logic (like stock adjustments and auth flows)

My question is:

How do you decide what belongs in services vs CRUD?

For example, stock updates:

- Should validation logic (like preventing negative stock) live in the service layer only?

- Or should some constraints also be enforced at the DB/model level?

Here is a snippet of my structure:

https://github.com/matnoren/inventory-api/tree/main/app

I’d really appreciate guidance on best practices for structuring this cleanly.

reddit.com
u/Comfortable_Tax8338 — 24 days ago