Slice groups
A slice group places related slices close together within the same layer, making the structure easier to navigate.
It is not a required part of FSD. You can introduce slice groups selectively when the number of slices grows large enough that a flat structure becomes hard to browse.
Overviewβ
It is a structure for making code easier to read and navigate, and does not affect dependency rules between slices.
A slice group is not a slice. It does not have its own segments like model, ui, or api, nor does it have a public API such as index.ts. Shared code used across multiple slices should not be placed in a slice group either.
Each slice remains independent even when it belongs to a slice group. The isolation and dependency rules between slices do not change.
Why it is neededβ
As the number of slices grows, a flat structure can make it hard to locate related code. When slices that share the same context are scattered across a layer, you end up scanning the entire layer multiple times.
A slice group addresses this by bringing related slices closer together, making the structure easier to navigate.
When to consider introducing oneβ
Consider introducing a slice group when there is a grouping criterion that feels obvious at a glance, and splitting the structure actually makes it easier to read.
- Several slices sharing the same business context are scattered across a layer.
- The slice names clearly suggest they belong to the same topic.
- The number of slices in a layer has grown to the point where it is hard to take in at a glance.
Conversely, it may not be needed yet in the following cases.
- Names alone are enough for quick navigation.
- There is no natural grouping criterion.
- Too few slices would end up in the group.
How to apply itβ
entitiesβ
You can group slices that are close from a domain model perspective.
For example, suppose the entities layer has accumulated many payment-related slices.
Without a group:
βββ entities/
βββ invoice/
β βββ model/
β βββ ui/
βββ receipt/
β βββ model/
β βββ ui/
βββ transaction/
β βββ model/
β βββ ui/
βββ user/
β βββ model/
β βββ ui/
βββ product/
β βββ model/
β βββ ui/
βββ ...
To find the payment-related slices (invoice, receipt, transaction), you would need to scan the entire layer and pick them out one by one.
With a group:
βββ entities/
βββ payment/
β βββ invoice/
β β βββ model/
β β βββ ui/
β βββ receipt/
β β βββ model/
β β βββ ui/
β βββ transaction/
β βββ model/
β βββ ui/
βββ user/
β βββ model/
β βββ ui/
βββ product/
β βββ model/
β βββ ui/
βββ ...
Now every payment-related slice can be found directly under payment/.
Not every slice needs to belong to a group. A slice like user/, whose meaning is clear on its own, can remain ungrouped.
pagesβ
You can group related pages in the pages layer in a similar way. This is one possible example and does not represent the default structure for the pages layer.
βββ pages/
βββ order/
β βββ create/
β β βββ ui/
β βββ detail/
β β βββ ui/
β βββ list/
β βββ ui/
βββ customer/
β βββ detail/
β β βββ ui/
β βββ list/
β βββ ui/
βββ settings/
β βββ ui/
βββ ...
This structure helps when there are multiple pages on the same topic, such as list, detail, create, and edit.
Can they be used in features as well?β
Yes, slice groups can be applied to the features layer as well. However, a feature often spans multiple entities rather than being tied to a single domain. This makes it harder to find a natural grouping criterion compared to entities.
If you create a group like features/cart/ without a clear criterion, use cases like add-to-cart and remove-from-cart will end up there, but cart-related DTOs and mappers may start accumulating as well. At that point the group folder stops serving as a navigational structure and begins acting as a home for the entire cart domain, weakening the principle that features should be split by use case.
To introduce a slice group in features, first check whether there are enough slices to warrant a group. If there are only two or three, a flat structure is likely sufficient. You should also check whether the group contains only feature slices, or whether code that belongs in entities has crept in as well.
Referencesβ
- Russian Telegram FSD community β Discussion on structural grouping, slice groups, and layer extension
- Russian Telegram FSD community β Nested vs. flat structure, forms and boundaries of slice groups
- Russian Telegram FSD community β Why there are fewer grouping examples in features, and whether slice groups work in features
- KakaoPay β A case of applying slice grouping in the pages layer