Claude-skill-registry component-patterns
Guidelines for organizing React components in Shadow Master. Use when creating new components, deciding between single-file vs subfolder structure, or understanding the component architecture.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/component-patterns" ~/.claude/skills/majiayu000-claude-skill-registry-component-patterns && rm -rf "$T"
skills/data/component-patterns/SKILL.mdComponent Organization Patterns
Guidelines for structuring React components in the Shadow Master codebase.
Component Directory Overview
/components/ # 130+ components total ├── index.ts # Root exports (DiceRoller only) ├── *.tsx # 6 standalone utility components ├── action-resolution/ # 3 components - dice pool building ├── auth/ # 1 component - email verification ├── character/ # 12 components - character sheet display ├── combat/ # 4 components - combat tracking UI ├── creation/ # 83 components - character creation │ ├── *.tsx # 14 top-level cards │ ├── shared/ # 14 reusable utilities │ └── {feature}/ # 17 feature subfolders ├── cyberlimbs/ # 6 components - augmentation UI ├── sync/ # 2 components - ruleset sync status └── ui/ # 2 components - BaseModal, Tooltip
Decision Flowchart
Does the component have modals? ├─ Yes → Create subfolder, extract modals └─ No → Does it have reusable Row/ListItem components? ├─ Yes, used elsewhere → Create subfolder └─ No → Keep as single file with internal helpers
When to Use a Subfolder
Create a subfolder with
index.ts when:
- Component has one or more modals (selection dialogs, forms, etc.)
- Component has reusable row/list item components used in multiple places
- Component exceeds ~600 lines with clear separable concerns
- Component has distinct UI pieces that could be tested independently
Subfolder structure:
/components/{area}/{feature}/ ├── FeatureCard.tsx # Main component ├── FeatureModal.tsx # Selection/edit modal ├── FeatureRow.tsx # Optional: if row is complex/reusable ├── constants.ts # Optional: magic values, options arrays ├── types.ts # Optional: feature-specific types ├── utils.ts # Optional: feature-specific helpers ├── index.ts # Re-exports public API
Index file pattern:
// index.ts - export only public API export { FeatureCard } from "./FeatureCard"; export { FeatureModal } from "./FeatureModal"; // Only if used externally
When to Keep as Single File
Keep as a single file when:
- Component is self-contained with only internal helper components
- Internal components are tightly coupled and only make sense within the parent
- Component is under ~400 lines with straightforward structure
- No modals or independently reusable pieces
Component Areas
Root-Level Components (6 files)
Standalone utility components that don't fit a specific feature area:
| Component | Purpose |
|---|---|
| Dice rolling UI with edge rerolls |
| Generic augmentation display |
| Essence tracking visualization |
| Dark/light mode context |
| Environment indicator (dev/staging) |
| Notification center UI |
/components/ui/
- Shared UI Primitives
/components/ui/Low-level accessible components used across the app. Built on React Aria.
| Component | Exports |
|---|---|
| BaseModal, ModalHeader, ModalBody, ModalFooter |
| Tooltip, TooltipTrigger, TooltipContent, InfoTooltip |
When to add here: Generic UI primitives with no business logic.
/components/auth/
- Authentication Components
/components/auth/| Component | Purpose |
|---|---|
| Prompts user to verify email |
/components/action-resolution/
- Dice Pool Building
/components/action-resolution/Components for building and displaying action resolution dice pools.
| Component | Purpose |
|---|---|
| List of past action rolls |
| Construct dice pools for actions |
| Edge point tracking and spending |
Note: No index.ts - import directly from files.
/components/character/
- Character Sheet Display
/components/character/Components for viewing active characters (not creation). No index file - import directly.
| Component | Purpose |
|---|---|
| Display adept powers and PP |
| Manage vehicle/drone autosofts |
| Cyberdeck attribute configuration |
| RCC drone network management |
| Vehicle/drone jump-in interface |
| Magic rating, tradition, drain |
| Matrix action buttons and state |
| Matrix attributes and programs |
| Running programs management |
| Rigging stats and VCR mode |
| Spell list with casting interface |
| Vehicle action buttons |
/components/combat/
- Combat Tracking
/components/combat/Components for running combat encounters. Has index.ts and co-located tests.
| Component | Purpose |
|---|---|
| Initiative order and turn management |
| Action selection with categories |
| Health/damage tracking |
| Opposed test dice rolling |
/components/cyberlimbs/
- Cyberlimb Management
/components/cyberlimbs/Components for cyberlimb augmentation display and modification.
| Component | Purpose |
|---|---|
| Individual cyberlimb display |
| List all installed cyberlimbs |
| Detailed cyberlimb info panel |
| Install new cyberlimb |
| Add attribute enhancements |
| Add accessories to limb |
/components/sync/
- Ruleset Synchronization
/components/sync/Components for displaying ruleset sync status and migration.
| Component | Purpose |
|---|---|
| Visual sync status indicator |
| Guide user through ruleset migration |
/components/creation/
- Character Creation
/components/creation/The largest component area (83 components). Organized by feature with shared utilities.
Top-Level Cards (14 files)
Single-file cards without complex modals:
| Card | Purpose |
|---|---|
| Priority table selection |
| Attribute allocation |
| Active skills management |
| Spell selection for mages |
| Adept power selection |
| Technomancer complex forms |
| Cyberware/bioware selection |
| Vehicle/drone acquisition |
| Weapon purchases |
| Tabbed gear interface |
| Calculated stats display |
| Name, background, description |
| Edition selection dropdown |
| Error boundary for creation |
Feature Subfolders (17 directories)
| Folder | Components | Pattern |
|---|---|---|
| 4 | Panel + Row + PurchaseModal + ModModal |
| 4 | 4 specialized modals |
| 3 | Card + Modal + KarmaConfirm |
| 2 | Card + Modal |
| 4 | Panel + Row + 2 Modals |
| 6 | Card + Identity + 3 modal types |
| 5 | Card + 2 Row types + 2 Modals |
| 2 | Card + Modal + utilities |
| 2 | Card + Modal |
| 2 | Card + Modal |
| 3 | Card + SelectionModal + DetailCard |
| 14 | Reusable utilities and hooks |
| 10 | Panel + ListItem + 8 specialized modals |
| 2 | ListItem + Modal |
| 4 | 4 specialized modals |
| 4 | Row + 3 Modals |
Shared Utilities (/creation/shared/
)
/creation/shared/| Component | Purpose |
|---|---|
| Standard card wrapper |
| Resource budget display |
| Loading skeleton |
| Empty list state |
| Nuyen ↔ Karma conversion |
| 1-6 rating picker |
| +/- increment control |
| Card summary footer |
| Validation status indicator |
| Quantity picker for bulk items |
| Lifestyle mod picker |
| Lifestyle subscription picker |
| Hook for karma conversion modal |
Adding Components by Area
Adding a Creation Card
- Determine structure using the decision flowchart
- Create in
or/components/creation//components/creation/{feature}/ - Use
wrapper fromCreationCard/components/creation/shared/ - Add to
in appropriate columnSheetCreationLayout.tsx - Update
type inCreationState
if needed/lib/types/creation.ts - Export from
/components/creation/index.ts
Adding a Combat Component
- Create in
/components/combat/ - Export from
/components/combat/index.ts - Add co-located test in
/components/combat/__tests__/
Adding a Character Sheet Component
- Create in
/components/character/ - Import directly from file (no index.ts)
- Add to relevant page in
/app/characters/[id]/
Adding a Cyberlimb Component
- Create in
/components/cyberlimbs/ - Export from
/components/cyberlimbs/index.ts - Export types if needed for external use
Adding a UI Primitive
- Create in
/components/ui/ - Build on React Aria for accessibility
- Export from
/components/ui/index.ts - No business logic - pure presentation
Adding a New API Endpoint
- Create
/app/api/{path}/route.ts - Export HTTP method handlers (GET, POST, PUT, DELETE)
- Follow authentication pattern (getSession → validate user)
- Call storage layer functions
- Return JSON responses
Adding a New Ruleset Module
- Define module type in
/lib/types/edition.ts - Add module to book payload in
/data/editions/{editionCode}/ - Update merge logic in
if special handling needed/lib/rules/merge.ts - Create hook in
for easy accessRulesetContext.tsx
Key Reference Files
- Accessible modal foundationcomponents/ui/BaseModal.tsx
- Card wrapper patterncomponents/creation/shared/CreationCard.tsx
- Modal-based editing examplecomponents/creation/SkillsCard.tsx
- Combat component with testscomponents/combat/CombatTracker.tsx
- Feature folder export patterncomponents/cyberlimbs/index.ts
- Three-column layoutapp/characters/create/sheet/components/SheetCreationLayout.tsx
Component Diagram Generation
Mermaid diagrams are auto-generated from the component structure.
Commands
# Preview all areas to stdout pnpm generate-diagrams # Generate specific area pnpm generate-diagrams --area=combat pnpm generate-diagrams --area=creation # Update documentation files pnpm generate-diagrams --output=files # Verbose mode with component counts pnpm generate-diagrams --verbose
Output Locations
| Mode | Location |
|---|---|
| Prints to terminal (default) |
| Writes to |
Diagram Color Key
| Color | Hex | Component Type | Naming Pattern |
|---|---|---|---|
| Blue | | Container | , , |
| Purple | | Modal | |
| Green | | Row | , |
| Orange | | Hook | , |
| Gray | | Shared | Everything else |
When to Regenerate
Run
pnpm generate-diagrams --output=files after:
- Adding a new component folder
- Adding/removing modals or cards
- Reorganizing component structure
- Before major documentation updates
Validation
# Validate creation docs structure (doesn't regenerate) pnpm validate-creation-docs --verbose
Documentation Structure
Hand-Written (detailed)
/docs/architecture/creation-components/ - Detailed creation component docs with:
- Component descriptions
- Props documentation
- Usage patterns
- Context dependencies
Auto-Generated (overview)
/docs/architecture/components/ - Generated hierarchy diagrams:
- Mermaid component trees
- Summary tables
- Color-coded by type
Index File Conventions
| Area | Has index.ts? | Reason |
|---|---|---|
| Yes | Stable public API |
| Yes | Cohesive feature set |
| Yes | Cohesive feature set |
| Yes | Cohesive feature set |
| Yes | Organized by phases |
| No | Loosely coupled, import directly |
| No | Loosely coupled, import directly |
| No | Single component |