Chapter
08 · Entity-First Feature Design
One folder = one entity. Logic lives with the entity, routes are UX-only.
Mental Model
- Entity folder is a mini-repo: actions, components, context, types, lib.
- Routes can move; entity internals stay portable and self-contained.
Canonical Structure
app/(index)/projects/
actions/
components/
context/
lib/
types/
page.tsx
layout.tsx
index.tsPortability Rules
- No cross-entity imports; expose a barrel if needed.
- No hard-coded routes in internals; routes are UX concerns.
- Public surface = actions + types; keep UI assumptions out.
Never Do
- Nested routes dictating logic placement.
- Shared state between entities; communicate via IDs/calls.
- Cross-entity Prisma access; keep boundaries strict.