high-level domain-keyword organization
rule
- high-level backend business behavior lives under
domains/<keyword>/;<keyword>= the easiest, shortest project-scope word for the concept. lexical home, not a claim of an independent subsystem. - lower-level mechanisms (persistence, providers, mapping, validation) follow layered source organization.
- one word loses a necessary relationship -> shortest exact compound:
workflowStep, notproviderWorkflowStep. - keyword home is earned, not scaffolded: create
domains/<keyword>/when policy, use cases, or flows actually accumulate on the noun — never in advance. - concept gains consumers in another workspace project -> extract a package named by the same keyword; ownership follows pnpm workspace boundaries.
why
- the folder tree is the first map a reader or agent consults.
- business behavior scattered across screen folders, vendor prefixes, or generic buckets -> the concept cannot be named from the tree; domain-noun searches return unrelated locations.
- one lexical home for high-level policy keeps business ownership visible, navigable, safe for concurrent refactors.
goal
- make high-level business concepts navigable and searchable as one vocabulary.
- a reader tracing an outcome starts at the domain noun and reaches policy, use case, or flow without translating screen, vendor, or implementation names.
placement decision
the folder answers "where would a new reader look first for this business decision?" it holds policy, invariant, use case, flow, and domain vocabulary sharing the canonical noun — not every technical mechanism the domain uses.
| candidate location | decision |
|---|---|
domains/<keyword>/ | high-level domain rule, invariant, vocabulary, policy, use case, and flow. |
| workspace package | extract when a keyword-owned concept gains consumers in another project. |
| screen- or vendor-named folder | reject because interface or provider names do not own the business concept. |
generic services/ bucket | reject because it hides the canonical business keyword. |
| lower-level technical category | defer placement to layered source organization. |
workflow
- add the concept to the domain glossary.
- choose the shortest easy word a project reader immediately associates with the concept.
- place policies, use cases, flows, and business vocabulary under that keyword once such code exists.
- extract a keyword-named package when consumers cross project boundaries.
- route lower-level mechanisms to the layered source-organization owner.
do not
- name a context after a screen, vendor, or temporary implementation.
- scaffold
domains/<keyword>/before any policy accumulates on the noun. - put high-level business policy in a generic
services/bucket. - keep a long technically precise name when it makes the domain list harder to navigate than the shortest exact glossary term.
good and bad
bad
order behavior scattered by technical concern, no one high-level owner:
src/screens/orders/OrderListScreen.tsxvendor-portal/orders/VendorOrderList.tsxservices/OrderService.tsservices/OrderValidator.tsadapters/order-api-adapter.tsdomains/reporting/ # scaffolded; no reporting code exists yet
- discovering the outcome requires searching several screen, vendor, and generic technical names.
- the business keyword does not identify one high-level owner.
- the empty
reporting/scaffold spends navigation cost on a decision no code has made yet.
good
order business behavior under one high-level domain keyword:
src/domains/order/submitOrder.tsorderPolicy.tsorderRoutes.ts
rg "order"finds one high-level policy owner.- a new developer tracing business behavior starts at
domains/order/; the lower-level technical tree follows the linked layered source-organization standard.
verification
- list the high-level domain folders without opening files: each must name a business keyword and contain code that earned it — no empty scaffolds.
- search a domain noun afterward: its policy, use cases, and flows should cluster under that lexical home, not under screen, vendor, or generic service folders.