Architecture Layers (The AEP Pyramid)
AT4DX supports a layered package architecture in which shared policy moves downward and application-specific behavior is added through injection. The important detail is that a layer is not necessarily one package. In particular, Business Common is a category containing any number of purpose-scoped common packages.
Package Graph
flowchart TB
SALES[Sales App]
MARKETING[Marketing App]
SERVICE[Service App]
SM[sales-marketing-common\nshared only by Sales + Marketing]
SS[sales-service-common\nshared only by Sales + Service]
ORG[org-common\none selector + one domain per SObject]
FRAMEWORKS[fflib · force-di · AT4DX]
SALES --> SM
SALES --> SS
MARKETING --> SM
SERVICE --> SS
SM --> ORG
SS --> ORG
ORG --> FRAMEWORKS
marketing-app does not depend on sales-service-common, and service-app does not depend on sales-marketing-common. A new common package is justified only by a real shared dependency boundary; there is no singular package named business-common that every application must consume.
Dependencies point downward. Lower packages never reference their consumers.
The Layers
1. Frameworks
Framework packages provide reusable infrastructure:
- fflib selectors, domains, mocks, and Unit of Work
- force-di bindings and injector
- AT4DX application factories, selector injection, and domain process injection
Org-specific schema and policy do not belong here. Org-agnostic helpers (test builders, validation utilities, abstract conventions) also live at this level.
2. Org Common
Org Common owns org-wide SObject infrastructure. For each SObject there is exactly:
- one selector class, such as
AccountsSelector; - one domain class, such as
AccountDomain; - one selector factory binding; and
- one domain constructor binding.
The selector contains queries that are truly common to all consumers, such as selectById. The domain contains invariants that apply everywhere. Neither is subclassed to create Sales, Marketing, or Service variants.
public interface IAccountsSelector extends IApplicationSObjectSelector {
List<Account> selectById(Set<Id> accountIds);
}
public with sharing class AccountsSelector
extends ApplicationSObjectSelector
implements IAccountsSelector {
public static IAccountsSelector newInstance() {
return (IAccountsSelector)
Application.Selector.newInstance(Account.SObjectType);
}
public Schema.SObjectType getSObjectType() {
return Account.SObjectType;
}
public override List<Schema.SObjectField> getSObjectFieldList() {
return new List<Schema.SObjectField>{
Account.Id,
Account.Name,
Account.Type,
Account.AnnualRevenue,
Account.OwnerId
};
}
private List<Schema.SObjectField> getAdditionalSObjectFieldList() {
return new List<Schema.SObjectField>();
}
public List<Account> selectById(Set<Id> accountIds) {
return (List<Account>) selectSObjectsById(accountIds);
}
}
The corresponding binding remains stable:
ApplicationFactory_SelectorBinding__mdt
BindingSObject__c: Account
To__c: AccountsSelector
Priority__c: 10
public with sharing class AccountDomain extends ApplicationSObjectDomain {
public AccountDomain(List<SObject> records) {
super(records);
}
public class Constructor implements fflib_SObjectDomain.IConstructable {
public fflib_SObjectDomain construct(List<SObject> records) {
return new AccountDomain(records);
}
}
}
ApplicationFactory_DomainBinding__mdt
BindingSObject__c: Account
To__c: AccountDomain.Constructor
3. Business Common Packages
Business Common packages contain schema and contracts shared by a specific set of business packages. Their names should expose that boundary:
sales-marketing-commoncontains schema and contracts used by both Sales and Marketing.sales-service-commoncontains schema and contracts used by both Sales and Service.
For example, sales-marketing-common might own Account.EngagementSegment__c because both applications compile against it. sales-service-common might own Account.CustomerTier__c because Sales and Service share that concept. Marketing receives no dependency on CustomerTier__c, and Service receives no dependency on EngagementSegment__c.
Business Common packages do not add alternate selector or domain classes. Shared fields are added to queries with Selector Field Injection. A query needed only by one consumer is added with Selector Method Injection. Business rules are added to the one domain through Criteria and Action bindings.
4. Business Packages
Business packages contain application-specific orchestration and behavior:
- selector method injectable classes;
- domain Criteria and Action classes;
- service implementations;
- application-specific fieldsets and injection metadata; and
DomainProcessBinding__mdtrecords.
For example, Sales can add a large-account query without creating SalesAccountsSelector:
SelectLargeAccountsSelectorMethod.Parameters params =
new SelectLargeAccountsSelectorMethod.Parameters();
params.minimumRevenue = 1000000;
List<Account> accounts = AccountsSelector.newInstance().selectInjection(
SelectLargeAccountsSelectorMethod.class,
params
);
Likewise, Sales adds LargeAccountCriteria and MarkStrategicAccountAction to AccountDomain using DomainProcessBinding__mdt; it does not create SalesAccountDomain.
Two Kinds of Selector Extension
Field and method injection solve different package-boundary problems:
| Need | Mechanism | Owner |
|---|---|---|
| Add downstream fields to every Account query | Fieldset + SelectorConfig_FieldSetInclusion__mdt |
Package that owns the fields |
| Add an application-specific Account query | AbstractSelectorMethodInjectable + selectInjection(...) |
Consuming business package |
| Run an existing common query | Method on IAccountsSelector / AccountsSelector |
Org Common |
Common selector methods are called directly without storing a selector local:
List<Account> accounts = AccountsSelector.newInstance().selectById(accountIds);
Application-specific methods are injected:
List<Account> accounts = AccountsSelector.newInstance().selectInjection(
SelectBySloganSelectorMethod.class,
params
);
Runtime Account Update
- The Org Common Account trigger invokes
AccountDomain. ApplicationSObjectDomainautomatically asksDomainProcessCoordinatorfor matching bindings.- Sales-owned Criteria and Actions run when their Sales bindings match.
- Marketing-owned Criteria and Actions run when their Marketing bindings match.
- Both sets of behavior use the same
AccountDomain; neither package subclasses it. - A service uses
AccountsSelector.newInstance().selectById(...)for common queries orselectInjection(...)for its own query method. - Changes are staged with AT4DX
uow.register(...)and committed in metadata-defined order.
Placement Decision
flowchart TD
Q1{Reusable with no org schema?} -->|yes| FW[Frameworks]
Q1 -->|no| Q2{Selector/domain infrastructure or an<br/>invariant for one SObject, org-wide?}
Q2 -->|yes| OC[Org Common<br/>the singular selector/domain]
Q2 -->|no| Q3{Schema or contract shared by a<br/>specific set of business packages?}
Q3 -->|yes| BC[A purpose-named Business Common package<br/>for exactly those consumers]
Q3 -->|no| BP[The Business Package, using<br/>selector-method or domain-process injection]
Start application-specific behavior in the business package. Move schema or contracts into a newly named Business Common package only when another business package genuinely shares them.