|
| 1 | +--- |
| 2 | +name: building-blocks |
| 3 | +description: Frontend building block catalog — typed patterns for components, hooks, queries, mutations, stores, and models used across the project. Use this skill whenever implementing, reviewing, or planning feature code, API integrations, state management, component patterns, or data modeling within src/features/ or src/lib/. Also triggers for architectural decisions about where code should live or which pattern to apply. |
| 4 | +--- |
| 5 | + |
| 6 | +# Frontend Building Blocks |
| 7 | + |
| 8 | +Typed catalog of building blocks used in this project. Each block has a fixed name, layer, composition rules, and canonical example. |
| 9 | + |
| 10 | +## How to Use |
| 11 | + |
| 12 | +Read the rule file for each block you are about to implement. The summaries below are for routing — the rule files contain the full pattern. |
| 13 | + |
| 14 | +## Block Catalog |
| 15 | + |
| 16 | +### Data Fetching |
| 17 | + |
| 18 | +| Block | Layer | Summary | File | |
| 19 | +| ----------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------- | -------------------------------- | |
| 20 | +| `mutation-hook` | `providers/` | Server write via `useMutation` with domain error translation and cache invalidation. Returns `[handler, isPending]`. | `rules/mutation-hook.md` | |
| 21 | +| `query-options-factory` | `lib/api/` | Reusable `queryOptions()` factories — no hooks, no `useQuery`. Hook composition belongs in `providers/`. | `rules/query-options-factory.md` | |
| 22 | +| `query-keys-factory` | `lib/api/` | Hierarchical `as const` key tuples per resource. Single source of truth for cache invalidation. | `rules/query-keys-factory.md` | |
| 23 | +| `dto-model` | `lib/api/` | TypeScript interfaces mirroring the raw API wire format. No transformations. | `rules/dto-model.md` | |
| 24 | + |
| 25 | +### State Management |
| 26 | + |
| 27 | +| Block | Layer | Summary | File | |
| 28 | +| ---------- | -------------- | -------------------------------------------------------------------------------------------------- | ------------------- | |
| 29 | +| `store` | `application/` | Zustand store — small, focused, selector-only subscriptions. Actions live inside the store. | `rules/store.md` | |
| 30 | +| `provider` | `providers/` | Thin React Context wrapper for dependency injection. No logic — delivers state, doesn't manage it. | `rules/provider.md` | |
| 31 | + |
| 32 | +### App Orchestration |
| 33 | + |
| 34 | +| Block | Layer | Summary | File | |
| 35 | +| --------------- | -------------- | ------------------------------------------------------------------------------------------------ | ------------------------ | |
| 36 | +| `use-case-hook` | `application/` | Orchestrates mutation + notification into one feature-level operation. The feature's public API. | `rules/use-case-hook.md` | |
| 37 | + |
| 38 | +### Component Patterns |
| 39 | + |
| 40 | +| Block | Layer | Summary | File | |
| 41 | +| -------------------- | -------------- | -------------------------------------------------------------------------------------------------- | ----------------------------- | |
| 42 | +| `notification-hook` | `application/` | Maps operation outcomes to toast notifications. One hook per use case. | `rules/notification-hook.md` | |
| 43 | +| `pure-component` | `components/` | Props in, JSX out. No side effects, no internal state beyond `useMemo`. | `rules/pure-component.md` | |
| 44 | +| `compound-component` | `components/` | Dot-notation sub-components. Composition over configuration — no boolean prop toggles. | `rules/compound-component.md` | |
| 45 | +| `hoc` | `components/` | Component in → enhanced component out. For render-level decisions (auth gates, suspense wrappers). | `rules/hoc.md` | |
| 46 | +| `page` | `pages/` | Route-level orchestrator. Only place where router coupling is acceptable. | `rules/page.md` | |
| 47 | +| `facade-hook` | `components/` | Private logic extraction for a single component. Defined below the component, not exported. | `rules/facade-hook.md` | |
| 48 | +| `named-effect` | `components/` | Named function expressions in `useEffect`. Intent visible at a glance. | `rules/named-effect.md` | |
| 49 | + |
| 50 | +### Data Modeling |
| 51 | + |
| 52 | +| Block | Layer | Summary | File | |
| 53 | +| ---------------- | -------------- | ------------------------------------------------------------------------------------------ | ------------------------- | |
| 54 | +| `frontend-model` | `models/` | UI-friendly domain objects mapped from DTOs. Skip if DTO shape is identical. | `rules/frontend-model.md` | |
| 55 | +| `value-object` | `application/` | Static-method classes grouping domain logic for a single concept. Namespace, not instance. | `rules/value-object.md` | |
| 56 | + |
| 57 | +## Rules |
| 58 | + |
| 59 | +- Block files live in `rules/` — one file per block. |
| 60 | +- Each file contains: description, constraints, and a canonical code example. |
| 61 | +- Block names are stable identifiers referenced in specs and task breakdowns. |
0 commit comments