Skip to main content

Feature-Sliced Design (FSD)

The architectural pattern enforced by Apex AI Brain.

What is FSD?​

Feature-Sliced Design is an architectural pattern that organizes code by features, not by technical layers.

Structure​

force-app/main/default/classes/
├── leads/
│ ├── domain/ ← Domain model
│ ├── service/ ← Business logic
│ ├── selector/ ← Query layer
│ ├── handler/ ← Event handlers
│ └── test/ ← Tests
├── accounts/
│ ├── domain/
│ ├── service/
│ └── ...
└── shared/
└── utilities/

Benefits​

Clear Organization - Easy to find code Scalability - Add features independently
Testability - Isolated test coverage Collaboration - Teams work independently

Layer Responsibilities​

LayerPurposeExample
SelectorRead dataLeadSelector.getById()
DomainBusiness logicLeadDomain.score()
ServicePublic APILeadService.scoreLeads()
HandlerEvent responseLeadTriggerHandler
TestValidationLeadServiceTest

Dependencies​

Valid dependency directions:

Handler → Service
Service → Domain
Service → Selector
Domain → Selector
Selector → nothing

Handler → Selector ❌ (skip layer)
Domain → Service ❌ (backwards)

See Also: