{"data":{"slug":"github-lobehub-lobehub-agents-skills-compose-atoms-9dd5924f10cc","title":"Compose Atoms for Modular Component Design","summary":"Split heavy domains into capabilities across hosts, sink state, and replace mode flags. Use for modular component design in React.","url":"https:\/\/skillshunter.net\/skills\/github-lobehub-lobehub-agents-skills-compose-atoms-9dd5924f10cc","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-lobehub-lobehub-agents-skills-compose-atoms-9dd5924f10cc","markdown_url":"https:\/\/skillshunter.net\/skills\/github-lobehub-lobehub-agents-skills-compose-atoms-9dd5924f10cc.md","download_url":"https:\/\/skillshunter.net\/skills\/github-lobehub-lobehub-agents-skills-compose-atoms-9dd5924f10cc\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"This skill is intended for splitting heavy domains into capabilities across hosts, sinking state into atoms, and replacing mode flags. It is not suitable for splitting one component into smaller files.","instructions":"---\nname: compose-atoms\ndescription: 'Use for splitting heavy domains into capabilities (\u539f\u5b50\u7ec4\u4ef6) across page, portal, share or micro-app hosts, sinking state (\u72b6\u6001\u4e0b\u6c89) and replacing mode\/readOnly flags. Simple component splits: react.'\nuser-invocable: false\n---\n\n# Compose Atoms\n\nA heavy domain is a **kit**, not a viewer with modes. Each host is an import list. An atom owns the data, actions, and dependencies of one capability. The assembler only chooses what to mount.\n\nThis is a **module-graph** split. Hiding UI does not drop a module. A host that never imports a file is the only host that does not ship it.\n\nDo not use this skill to slice one component into smaller files. That is `react`.\n\n## When\n\nThe folder is a product surface (Conversation, Acceptance, Document, Verify, Task, \u2026) and at least one of these is true:\n\n- One entry owns read + write + workflow + host integration.\n- A second host already exists or is the next change (page, portal, share, mobile, popup, micro-app).\n- The next feature is another boolean \/ `mode` \/ `variant` on the fat tree.\n- Reusing a header, list, or card would import trays, stores, or chat.\n\nIf the file is large but has **one** capability and **one** host, stop. Use `react`.\n\n## Grain\n\nAn atom is the **smallest unit a host is allowed not to mount**.\n\nAsk, for every chunk: _would any host ship the rest and skip this?_ If yes, it is an atom. If no, it stays inside its parent.\n\nThat grain is coarser than a visual section and finer than the whole page.\n\n| Too coarse                         | Right grain                         | Too fine                                      |\n| ---------------------------------- | ----------------------------------- | --------------------------------------------- |\n| One `Viewer` with `readOnly`       | Identity, goal, list, decision, \u2026   | Every badge, row, and icon as a public export |\n| `Chat` as a single import          | List, composer, intervention, \u2026     | Every message sub-row the page then rewires   |\n| `Document` as editor + every panel | Canvas, header, comments as omitted | Internal toolbar buttons                      |\n\nA **workflow** (focus review, thread, publish) is one atom to hosts that skip the whole mode. Inside it, keep splitting only if a host would mount a piece of that workflow alone.\n\n## Sink State\n\nThe split is worthless if the assembler still holds the domain state. **Imports follow the hook.** A `useStore` \/ `useX` \/ `handleAccept` left on the page keeps that module (and everything it imports) on every host that mounts the page.\n\nSink everything the atom needs into the atom:\n\n| Sinks into the atom                        | Stays on the assembler                        |\n| ------------------------------------------ | --------------------------------------------- |\n| Resource fetch                             | The record id \/ scope identity                |\n| Derived view model (counts, labels, scope) | Which atoms are mounted (the import list)     |\n| Transient UI (filter, collapse, pending)   | Host layout state (focused vs overview, rail) |\n| Mutation handlers and their stores\/modals  | Host seams (provider value the runtime owns)  |\n\n```tsx\n\/\/ wrong \u2014 visual split, state still on the page\nconst Page = () => {\n  const { data, mutate } = useX(id);\n  const [filter, setFilter] = useState('all');\n  const accept = () => void mutate(...);\n  return (\n    <>\n      <Identity data={data} \/>\n      <List data={data} filter={filter} onFilter={setFilter} \/>\n      <DecisionBar onAccept={accept} \/>\n    <\/>\n  );\n};\n\n\/\/ right \u2014 each atom reads and acts; page only assembles\nconst Page = () => (\n  <Scope id={id}>\n    <Identity \/>\n    <List \/>\n    <Decision \/>\n  <\/Scope>\n);\n```\n\nDo not lift \"to fetch once\" or \"so siblings share data\". Two atoms calling the same SWR hook share the cache by key. Sibling writes go through that cache (or a store slice the write atom imports), not through page `useState`.\n\nLift only when the state **is** the assembler's job: which workflow is on screen, whether a rail is open. If a value is used to render or mutate one capability, it belongs in that capability.\n\n## Kit\n\n| Piece            | Owns                                              | Must not own                                       |\n| ---------------- | ------------------------------------------------- | -------------------------------------------------- |\n| Domain primitive | Types, predicates, formatters                     | React, stores, services                            |\n| Data access      | One resource, one file                            | Sibling list \/ infinite \/ document hooks           |\n| Read atom        | Present + local UI state + its own fetch          | Mutations, trays, owner services, host stores      |\n| Write atom       | One mutation and its UI                           | Page layout, unrelated writes                      |\n| Workflow atom    | A mode assembled from other atoms                 | Becoming the only entry other hosts can import     |\n| Domain slot      | `ReactNode` hole for another **same-domain** atom | A callback whose implementation lives in this file |\n| Host seam        | Optional host-provided UI, **null by default**    | A fallback that imports the host graph             |\n| Assembler        | Layout + the import list                          | Domain actions; domain fetch except local chrome   |\n\nA visual block that both reads and writes is a read atom + a write atom, joined by a domain slot.\n\nTwo seam types \u2014 do not mix them:\n\n- **Domain slot** \u2014 same feature, optional capability (`editSlot`, `toolbar`). The host imports the write atom and passes it in.\n- **Host seam** \u2014 only some runtimes can resolve it (chat store, topic drawer, Electron). Context default is `null`. The micro-app \/ share page never imports the provider value. See `split-micro-app` for the runtime cut.\n\n## Ownership\n\nState and imports live in the atom that needs them.\n\n- Read atoms call the isolated resource hook. Filter \/ collapse \/ expand stay in the atom.\n- Write atoms call the same hook, then mutate. They import their own modals and services. They return `null` when the record is not writable.\n- Workflow atoms compose other atoms. They still do not become the light host's entry.\n- Assemblers do not fetch in order to push props down. Chrome unique to that host (a title in a shell header) may read the hook.\n- Scope context carries **identity** (`id`, `embedded`). It does not carry actions, stores, or modal openers.\n\nSeveral atoms calling the same SWR hook is expected. SWR dedupes on key. Do not lift data to the assembler \"to fetch once\".\n\nThe shared read hook is **its own file**. A light host imports that file, never a `hooks.ts` \/ store barrel that also exports list, document, or send-message.\n\n```ts\n\/\/ any host:\nimport { useX } from '@\/features\/Domain\/useX';\n\n\/\/ never from a light host:\nimport { useX } from '@\/features\/Domain\/hooks';\nimport { DomainViewer } from '@\/features\/Domain';\n```\n\nA flag that only changes behavior of code already in the atom is fine. A flag whose purpose is to skip importing another module is not \u2014 that module is a slot or a sibling the assembler omits.\n\n`dynamic(() => import(...))` only helps when **no static import** of that module remains on the light graph.\n\n## Assembler\n\nA host is its import list.\n\n```tsx\n\/\/ light host \u2014 deep imports only\n<Scope id={id}>\n  <ReadA \/>\n  <ReadB \/>\n<\/Scope>\n\n\/\/ full host \u2014 same reads, write atoms in slots, workflows as siblings\n<ReadA extra={<WriteA \/>} \/>\n<ReadB toolbar={<WriteB \/>} \/>\n<Workflow \/>\n<WriteC \/>\n```\n\nRoute \/ portal files compose host skeleton (providers, host seams). Do not add a wrapper page whose only job is to sit between the route and the assembler.\n\nThe feature barrel may export the **full** assembler for in-app use. Light hosts must not import that barrel.\n\n## Procedure\n\n1. List **hosts** (page, portal, share, mobile, popup, micro-app \u2014 include the next one).\n2. List **capabilities as verbs** (view identity, edit field, decide, open host thing). Map host \u2192 verbs.\n3. Set **grain**: each verb a host can skip is an atom. Group the rest under a parent.\n4. Extract primitives and the isolated read hook first.\n5. Extract read atoms. Optional same-domain capabilities become `ReactNode` slots, not callbacks that close over write modules.\n6. Extract each write \/ workflow atom into its own file. Heavy deps stay in that file.\n7. **Sink state.** Move fetch, view-model, transient UI, and handlers out of the assembler. If the page still calls a domain hook to feed props, the split is not done.\n8. Rewrite every host as an import list plus layout. Delete `readOnly` \/ `isPublic` \/ `mode` \/ `variant` on the fat tree.\n9. Point light hosts at atoms by **deep path**.\n10. Prove the cut. Grep the light entry's import tree, or trace a module the light host must not ship. A missing button is not proof.\n\n```bash\n# example: light host must not import a write atom\nWORKBENCH_TRACE_MODULE=features\/Acceptance\/Viewer\/Review\/AcceptanceDecision bun run build:rr\n```\n\nIf the light assembler appears on the importer chain, a static import still exists \u2014 usually a barrel, a leftover flag, or actions left on the page.\n\n## Example\n\n`src\/features\/Acceptance\/Viewer\/` is one application of this kit, not the template to copy file-for-file.\n\n| Host                          | Mounts                                                                    |\n| ----------------------------- | ------------------------------------------------------------------------- |\n| In-app `Acceptance\/index.tsx` | Identity, goal, inventory, decision, focus workflow, ledger + write slots |\n| Workbench public detail       | Identity, goal, inventory, discussion with sign-in guidance               |\n| Portal                        | Full assembler + `OriginConversationProvider`                             |\n\nRead `AcceptanceGoal` (read + `editSlot`) and `AcceptanceGoalEdit` (write) for the slot cut. Read `originConversation.tsx` for a host seam. Read workbench `AcceptanceDetail.tsx` for a light assembler.\n\n## Related skills\n\n- **`react`**: single-surface boundaries, styling, memoization.\n- **`split-micro-app`**: worker \/ SSR \/ gateway \/ stubs. This skill is how the shared UI is cut afterwards.\n- **`spa-routes`**: route files stay thin assemblers.\n- **`data-fetching-architecture`**: how the isolated hook fetches, not where a host may import it from.\n- **`zustand`**: narrow selectors inside an atom; do not put the whole store on scope context.\n","use_cases":["Split a `Conversation` domain into `Identity`, `List`, and `DecisionBar` atoms across a page and micro-app host.","Replace `mode` flags with atoms for a `Document` domain across different hosts."],"limitations":["Do not use for splitting one component into smaller files. That is handled by `react`.","The split is only effective if state is sunk into the atom."],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/lobehub\/lobehub\/blob\/99a34fb1a53e4892ebdc25142ccc8bfa749d246b\/.agents\/skills\/compose-atoms\/SKILL.md","source_commit":"99a34fb1a53e4892ebdc25142ccc8bfa749d246b","license":null,"version":null,"listing_approved_at":"2026-11-15","created_at":"2026-11-14T16:35:18.000000Z","updated_at":"2026-11-15T18:51:31.000000Z","seo_title":"Compose Atoms for Modular Component Design","seo_description":"Split heavy domains into capabilities across hosts with Compose Atoms. Replace mode flags and sink state for modular React design.","seo_keywords":["Compose Atoms for React","Split heavy domains into atoms","Replace mode flags with atoms","Sink state into atoms","Modular component design"]}}