Vertical slice feature
Put everything one feature needs in one folder, so the agent can read the whole feature in one pass and change it without hunting through layers. The folder is the unit of change, review and deletion.
When to use
- Adding a feature, endpoint, page or screen.
- A change that would otherwise touch five or more folders.
- Splitting a large feature into smaller ones.
Steps
-
Read the conventions. Check AGENTS.md and two existing features for the folder name (
features/,modules/,app/(group)/), file naming and test placement. Match them exactly; consistency beats preference. -
Name the slice after the user’s verb or noun:
invite-member,billing,export-csv. Not after a technical layer. -
Create the folder with only the files this feature needs:
src/features/invite-member/ invite-member.route.ts # or page / screen / handler: the entry point invite-member.schema.ts # input and output validation invite-member.ts # the logic and data access, plain functions invite-member.test.ts # tests for the behaviour, next to the code InviteMemberForm.tsx # UI, if the feature has anyFramework routing that must live elsewhere (
app/,pages/) stays a thin file that imports from the slice. -
Write the test first for the behaviour the user asked for (see
tests-as-spec), then implement until it passes. -
Keep the boundary narrow. Other features may import only the slice’s public entry (an
index.tsor the route). Shared code moves tolib/only when a second slice needs it, not before. -
Register the slice in the one place the framework requires (router, module list, navigation) and nowhere else.
-
Run the verify command and fix everything it reports.
Rules
- No new layer folders (
services/,repositories/,dto/) for a single feature. A slice may have more files, never more folders than it needs. - Duplication between two slices is fine; a premature shared abstraction is not. Extract on the third use.
- Database schema changes still go through the project’s migration tool, with the migration in the same change.
- Deleting a feature should mean deleting its folder plus one registration line. If it does not, the slice leaks.
Output
The new folder and files, the one registration change, the test that describes the feature, and the verify result.