---
title: "Group code by feature · Agent Wranglers"
url: https://agentwranglers.se/playbook/architecture/structure/group-by-feature
updated: 2026-10-20
licence: "All rights reserved"
---

# Group code by feature

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Recommended
- Chapter: [Structure](https://agentwranglers.se/playbook/architecture/structure)
- Rule: Put the code for one feature together, such as `orders/` or `invoices/`, instead of spreading it across folders named `controllers/`, `models/` and `services/`.
- How: Give each feature folder its own types, rules, storage and tests. Share code between features only through each folder's public entry point. A change to one feature then touches one folder.
- Check: In review, a change to one feature touches at most one feature folder plus shared code. An import rule blocks imports of another feature's internal files.

Example:

```text
Bad                          Good
src/controllers/Order.ts     src/orders/OrderController.ts
src/models/Order.ts          src/orders/Order.ts
src/services/Order.ts        src/orders/placeOrder.ts
src/tests/Order.test.ts      src/orders/placeOrder.test.ts
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/structure/group-by-feature`.

- Previous: [Allow no dependency cycles](https://agentwranglers.se/playbook/architecture/structure/no-dependency-cycles)
- Next: [Name files after what they hold](https://agentwranglers.se/playbook/architecture/structure/consistent-file-names)
- [Structure](https://agentwranglers.se/playbook/architecture/structure)
