//_blog

Brewtiful Beans Learns AT4DX, Part 3: The Bean Hierarchy

Joe has a shared Account selector and a way to obtain it. Now Sales and Service need a field that Marketing does not use. Where should it live? Putting everything in Org Common would make every team carry everyone else’s dependencies.

The package hierarchy gives Joe a way to keep shared foundations stable while placing specialized code closer to its owners.

After this post, you can:

  • Name the four layers of an AT4DX package graph, from frameworks down to business packages.
  • Decide where an SObject and its selector and domain belong.
  • Use the placement decision tree to decide where a new class goes.

The Single Origin Rule

Brewtiful keeps one selector and one domain for an SObject where those components are needed. The question is who needs the object?

Account is a core object used across the org, so Org Common owns AccountsSelector and AccountDomain. Contact, Opportunity, and Case are other candidates for that shared foundation. Team-specific fields, queries, and rules still belong with the apps that supply them.

Now suppose Service creates Service_Request__c for its own work, and no other team uses it. The object and its selector belong in the Service app, not Org Common. If Sales and Service share a different object, its schema and selector can live in their sales-service-common package. The same placement principle applies to its domain when one is needed.

The factory bindings point to the appropriate implementations. Part 4 shows how.

The Four Layers

Here’s the stack, bottom to top:

  1. Frameworks. fflib selectors, domains, mocks, and Unit of Work; force-di; and the AT4DX factories and injection. This layer is reusable infrastructure. Org-specific schema doesn’t belong here.
  2. Org Common. Core objects shared across the org, their selectors and domains, and rules that apply across teams.
  3. Business Common. Objects, selectors, domains, schema, and contracts shared by a specific set of business packages.
  4. Business packages. Objects and selectors used by one application, plus its services, Criteria, Actions, and injection metadata.

Dependencies only point down. Frameworks don’t know about Org Common, and Org Common doesn’t know about any business package.

Business Common Is a Category

Here’s a detail that trips people up: Business Common isn’t one package. It’s a category, and any number of purpose-named packages can fit in it.

Brewtiful has two:

  • sales-marketing-common holds schema that only Sales and Marketing share. Say, Account.EngagementSegment__c.
  • sales-service-common holds schema that only Sales and Service share. Say, Account.CustomerTier__c.

Marketing doesn’t depend on sales-service-common, and Service doesn’t depend on sales-marketing-common. A package exists only where a real shared boundary exists. There’s no all-purpose business-common that every app must install.

A Business Common package can own an object and its selector and domain when those are shared by its consumers. For a core object already owned by Org Common, teams extend the existing selector and domain through injection instead of creating competing copies.

Typing Tax: Each new Business Common package needs its own sfdx-project.json entry, package version, dependency declarations, and deployment order. That’s real overhead, which is why the decision tree below says to create one only when two or more packages truly share the schema.

Where Does This Class Go?

Here’s the decision tree. Start at the top and stop at the first yes:

flowchart TD
    accTitle: Where does this code belong?
    accDescr: Follow the questions from top to bottom. A yes selects a package, and a no leads to the next question.
    Q1{Reusable without org-specific schema?} -->|Yes| FW[Frameworks]
    Q1 -->|No| Q2{Core object, its selector or domain, or an org-wide rule?}
    Q2 -->|Yes| OC[Org Common]
    Q2 -->|No| Q3{Object, code, schema, or contract shared by specific business packages?}
    Q3 -->|Yes| BC[Business Common package]
    Q3 -->|No| BP[Owning business package]

Start in the business package. Move code into a shared layer when another package genuinely needs it; each new shared package adds dependency and deployment overhead.

Check Your Brew

1. Service creates Service_Request__c for its own app. No other team uses it. Where should the object and its selector live?

  • A. The Service business package
  • B. Org Common, because every selector belongs there
  • C. A shared package that every team must install
  • D. The framework layer
Reveal the answer

A. The object and its selector serve Service alone, so Service can own them. Org Common holds core objects such as Account that are shared across the org.

2. Sales and Service share a CustomerTier__c field, but Marketing doesn’t use it. Where does the field go?

  • A. Org Common, so every package can see it
  • B. The Marketing package
  • C. A purpose-named Business Common package such as sales-service-common
  • D. The framework layer
Reveal the answer

C. The field is shared by exactly two packages, so it goes in a purpose-named package for those two consumers. Marketing doesn’t depend on it.

3. Which statement about dependencies is correct?

  • A. Lower layers may reference the business packages above them
  • B. Frameworks depend on Org Common
  • C. Business packages must depend on every Business Common package
  • D. Dependencies point downward, and lower packages never reference their consumers
Reveal the answer

D. Dependencies point down. A lower package never reaches up to a consumer, which keeps dependencies directed toward shared foundations.

Next up: Part 4, The Four Factories, walks through the bindings behind the newInstance() calls from Part 2. Joe will see how those bindings connect each request to an implementation.