Feature-Based Architecture Best Practices
Comprehensive architecture guide for organizing React applications by features, enabling scalable development with independent teams. Contains 43 rules across 8 categories, prioritized by impact from critical (directory structure, imports) to incremental (naming conventions). When invoked on a real project, the skill produces a project-specific blueprint that anchors every decision in those rules.
Primary Output: The Target Architecture Blueprint
When an agent invokes this skill on a real project, the deliverable is a single
markdown file persisted at docs/architecture/FEATURE-ARCH-TARGET.md (or the
repo's existing docs location). The blueprint contains:
- Project context — framework, state libraries, routing model, current shape.
- Identified features — confirmed with the user, sourced from routes, docs, openspec, and code clusters.
- Target directory tree — literal paths, not pseudo-trees.
- Per-feature public APIs — exact named exports of each
index.ts.
- Import-boundary matrix — N×N table of feature relationships (
allowed / forbidden / via app / via events).
- State & data ownership — server-state and client-state owner per feature.
- Cross-feature communication policy — composition, events, or shared slice — with rationale.
- Numbered migration plan — file-level move/create/delete steps with S/M/L effort estimates.
- Human conformance checklist — for code review and "definition of done".
- Open questions — anything that needs a human decision before migration.
Every section cites the specific rules below that govern its decisions, so the
blueprint stays a projection of this skill — not a parallel authority.
How the agent generates the blueprint
Follow the process in references/_blueprint-process.md. Summary:
- Gather context (package.json, src/ tree, README, CLAUDE.md, openspec/).
- Identify candidate features from routes, docs, and code clusters.
- Confirm the feature list with the user via
AskUserQuestion.
- Record explicit decisions (layer model, comm mechanism, state/routing owner).
- Fill in assets/templates/feature-arch-target.md.template — every
{{placeholder}} replaced with a literal project value.
- Hand off: print path, summarise feature/step counts, list top-3 risks, suggest next action. Do not start executing migration steps in the same turn.
For very small projects (under ~10 source files), produce a one-page seed
structure instead and note that a full blueprint should follow after the 2nd–3rd
feature exists.
When to Apply
Reference these guidelines when:
- A project asks for a feature-based architecture target (generate the blueprint).
- Creating new features or modules.
- Organizing project directory structure.
- Setting up import rules and boundaries.
- Implementing data fetching patterns.
- Composing components from multiple features.
- Reviewing code for architecture violations.
Rule Categories by Priority
| Priority |
Category |
Impact |
Prefix |
| 1 |
Directory Structure |
CRITICAL |
struct- |
| 2 |
Import & Dependencies |
CRITICAL |
import- |
| 3 |
Module Boundaries |
HIGH |
bound- |
| 4 |
Data Fetching |
HIGH |
fquery- |
| 5 |
Component Organization |
MEDIUM-HIGH |
fcomp- |
| 6 |
State Management |
MEDIUM |
fstate- |
| 7 |
Testing Strategy |
MEDIUM |
test- |
| 8 |
Naming Conventions |
LOW |
name- |
Quick Reference
1. Directory Structure (CRITICAL)
struct-feature-folders - Organize by feature, not technical type
struct-feature-self-contained - Make features self-contained
struct-shared-layer - Use shared layer for truly generic code only
struct-flat-hierarchy - Keep directory hierarchy flat
struct-optional-segments - Include only necessary segments
struct-app-layer - Separate app layer from features
struct-domain-folders - Group features into domains at large scale
2. Import & Dependencies (CRITICAL)
import-unidirectional-flow - Enforce unidirectional import flow
import-no-cross-feature - Prohibit cross-feature imports
import-public-api - Export through public API only
import-avoid-barrel-files - Avoid deep barrel file re-exports
import-path-aliases - Use consistent path aliases
import-type-only - Use type-only imports for types
3. Module Boundaries (HIGH)
bound-feature-isolation - Enforce feature isolation
bound-interface-contracts - Define explicit interface contracts
bound-feature-scoped-routing - Scope routing to feature concerns
bound-minimize-shared-state - Minimize shared state between features
bound-event-based-communication - Use events for cross-feature communication
bound-feature-size - Keep features appropriately sized
4. Data Fetching (HIGH)
fquery-single-responsibility - Keep query functions single-purpose
fquery-colocate-with-feature - Colocate data fetching with features
fquery-parallel-fetching - Fetch independent data in parallel
fquery-avoid-n-plus-one - Avoid N+1 query patterns
fquery-feature-scoped-keys - Use feature-scoped query keys
fquery-server-component-fetching - Fetch at server component level
5. Component Organization (MEDIUM-HIGH)
fcomp-single-responsibility - Apply single responsibility to components
fcomp-composition-over-props - Prefer composition over prop drilling
fcomp-container-presentational - Separate container and presentational concerns
fcomp-props-as-data-boundary - Use props as feature boundaries
fcomp-colocate-styles - Colocate styles with components
fcomp-error-boundaries - Use feature-level error boundaries
6. State Management (MEDIUM)
fstate-feature-scoped-stores - Scope state stores to features
fstate-server-state-separation - Separate server state from client state
fstate-lift-minimally - Lift state only as high as necessary
fstate-context-sparingly - Use context sparingly for feature state
fstate-reset-on-unmount - Reset feature state on unmount
7. Testing Strategy (MEDIUM)
test-colocate-with-feature - Colocate tests with features
test-feature-isolation - Test features in isolation
test-shared-utilities - Create feature-specific test utilities
test-integration-at-app-layer - Write integration tests at app layer
8. Naming Conventions (LOW)
name-feature-naming - Use domain-driven feature names
name-file-conventions - Use consistent file naming conventions
name-descriptive-exports - Use descriptive export names
How to Use
Read individual reference files for detailed explanations and code examples:
- Blueprint process - How to derive a project-specific target architecture
- Blueprint template - Template the agent fills in to produce the end-state document
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
- Individual rules:
references/{prefix}-{slug}.md
Related Skills
- For feature planning, see
feature-spec skill
- For data fetching, see
tanstack-query skill
- For React component patterns, see
react-19 skill
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
1---2name: feature-arch3description: React feature-based architecture guidelines for scalable applications. This skill should be used when writing, reviewing, or refactoring React code to ensure proper feature organization. When invoked on a project, the agent produces a concrete target-architecture blueprint at docs/architecture/FEATURE-ARCH-TARGET.md showing the desired directory tree, per-feature public APIs, import-boundary matrix, and a numbered migration plan. Triggers on tasks involving project structure, feature organization, module boundaries, cross-feature imports, data fetching patterns, or component composition.4---5
6# Feature-Based Architecture Best Practices
7
8Comprehensive architecture guide for organizing React applications by features, enabling scalable development with independent teams. Contains 43 rules across 8 categories, prioritized by impact from critical (directory structure, imports) to incremental (naming conventions). When invoked on a real project, the skill produces a project-specific blueprint that anchors every decision in those rules.
9
10## Primary Output: The Target Architecture Blueprint
11
12When an agent invokes this skill on a real project, the deliverable is a single
13markdown file persisted at `docs/architecture/FEATURE-ARCH-TARGET.md` (or the
14repo's existing docs location). The blueprint contains:
15
161. **Project context** — framework, state libraries, routing model, current shape.
172. **Identified features** — confirmed with the user, sourced from routes, docs, openspec, and code clusters.
183. **Target directory tree** — literal paths, not pseudo-trees.
194. **Per-feature public APIs** — exact named exports of each `index.ts`.
205. **Import-boundary matrix** — N×N table of feature relationships (`allowed` / `forbidden` / `via app` / `via events`).
216. **State & data ownership** — server-state and client-state owner per feature.
227. **Cross-feature communication policy** — composition, events, or shared slice — with rationale.
238. **Numbered migration plan** — file-level move/create/delete steps with S/M/L effort estimates.
249. **Human conformance checklist** — for code review and "definition of done".
2510. **Open questions** — anything that needs a human decision before migration.
26
27Every section cites the specific rules below that govern its decisions, so the
28blueprint stays a projection of this skill — not a parallel authority.
29
30### How the agent generates the blueprint
31
32Follow the process in [references/_blueprint-process.md](references/_blueprint-process.md). Summary:
33
341. Gather context (package.json, src/ tree, README, CLAUDE.md, openspec/).
352. Identify candidate features from routes, docs, and code clusters.
363. Confirm the feature list with the user via `AskUserQuestion`.
374. Record explicit decisions (layer model, comm mechanism, state/routing owner).
385. Fill in [assets/templates/feature-arch-target.md.template](assets/templates/feature-arch-target.md.template) — every `{{placeholder}}` replaced with a literal project value.
396. Hand off: print path, summarise feature/step counts, list top-3 risks, suggest next action. Do not start executing migration steps in the same turn.
40
41For very small projects (under ~10 source files), produce a one-page seed
42structure instead and note that a full blueprint should follow after the 2nd–3rd
43feature exists.
44
45## When to Apply
46
47Reference these guidelines when:
48- A project asks for a feature-based architecture target (generate the blueprint).
49- Creating new features or modules.
50- Organizing project directory structure.
51- Setting up import rules and boundaries.
52- Implementing data fetching patterns.
53- Composing components from multiple features.
54- Reviewing code for architecture violations.
55
56## Rule Categories by Priority
57
58| Priority | Category | Impact | Prefix |
59|----------|----------|--------|--------|
60| 1 | Directory Structure | CRITICAL | `struct-` |
61| 2 | Import & Dependencies | CRITICAL | `import-` |
62| 3 | Module Boundaries | HIGH | `bound-` |
63| 4 | Data Fetching | HIGH | `fquery-` |
64| 5 | Component Organization | MEDIUM-HIGH | `fcomp-` |
65| 6 | State Management | MEDIUM | `fstate-` |
66| 7 | Testing Strategy | MEDIUM | `test-` |
67| 8 | Naming Conventions | LOW | `name-` |
68
69## Quick Reference
70
71### 1. Directory Structure (CRITICAL)
72
73- `struct-feature-folders` - Organize by feature, not technical type
74- `struct-feature-self-contained` - Make features self-contained
75- `struct-shared-layer` - Use shared layer for truly generic code only
76- `struct-flat-hierarchy` - Keep directory hierarchy flat
77- `struct-optional-segments` - Include only necessary segments
78- `struct-app-layer` - Separate app layer from features
79- `struct-domain-folders` - Group features into domains at large scale
80
81### 2. Import & Dependencies (CRITICAL)
82
83- `import-unidirectional-flow` - Enforce unidirectional import flow
84- `import-no-cross-feature` - Prohibit cross-feature imports
85- `import-public-api` - Export through public API only
86- `import-avoid-barrel-files` - Avoid deep barrel file re-exports
87- `import-path-aliases` - Use consistent path aliases
88- `import-type-only` - Use type-only imports for types
89
90### 3. Module Boundaries (HIGH)
91
92- `bound-feature-isolation` - Enforce feature isolation
93- `bound-interface-contracts` - Define explicit interface contracts
94- `bound-feature-scoped-routing` - Scope routing to feature concerns
95- `bound-minimize-shared-state` - Minimize shared state between features
96- `bound-event-based-communication` - Use events for cross-feature communication
97- `bound-feature-size` - Keep features appropriately sized
98
99### 4. Data Fetching (HIGH)
100
101- `fquery-single-responsibility` - Keep query functions single-purpose
102- `fquery-colocate-with-feature` - Colocate data fetching with features
103- `fquery-parallel-fetching` - Fetch independent data in parallel
104- `fquery-avoid-n-plus-one` - Avoid N+1 query patterns
105- `fquery-feature-scoped-keys` - Use feature-scoped query keys
106- `fquery-server-component-fetching` - Fetch at server component level
107
108### 5. Component Organization (MEDIUM-HIGH)
109
110- `fcomp-single-responsibility` - Apply single responsibility to components
111- `fcomp-composition-over-props` - Prefer composition over prop drilling
112- `fcomp-container-presentational` - Separate container and presentational concerns
113- `fcomp-props-as-data-boundary` - Use props as feature boundaries
114- `fcomp-colocate-styles` - Colocate styles with components
115- `fcomp-error-boundaries` - Use feature-level error boundaries
116
117### 6. State Management (MEDIUM)
118
119- `fstate-feature-scoped-stores` - Scope state stores to features
120- `fstate-server-state-separation` - Separate server state from client state
121- `fstate-lift-minimally` - Lift state only as high as necessary
122- `fstate-context-sparingly` - Use context sparingly for feature state
123- `fstate-reset-on-unmount` - Reset feature state on unmount
124
125### 7. Testing Strategy (MEDIUM)
126
127- `test-colocate-with-feature` - Colocate tests with features
128- `test-feature-isolation` - Test features in isolation
129- `test-shared-utilities` - Create feature-specific test utilities
130- `test-integration-at-app-layer` - Write integration tests at app layer
131
132### 8. Naming Conventions (LOW)
133
134- `name-feature-naming` - Use domain-driven feature names
135- `name-file-conventions` - Use consistent file naming conventions
136- `name-descriptive-exports` - Use descriptive export names
137
138## How to Use
139
140Read individual reference files for detailed explanations and code examples:
141
142- [Blueprint process](references/_blueprint-process.md) - How to derive a project-specific target architecture
143- [Blueprint template](assets/templates/feature-arch-target.md.template) - Template the agent fills in to produce the end-state document
144- [Section definitions](references/_sections.md) - Category structure and impact levels
145- [Rule template](assets/templates/_template.md) - Template for adding new rules
146- Individual rules: `references/{prefix}-{slug}.md`
147
148## Related Skills
149
150- For feature planning, see `feature-spec` skill
151- For data fetching, see `tanstack-query` skill
152- For React component patterns, see `react-19` skill
153
154## Full Compiled Document
155
156For the complete guide with all rules expanded: `AGENTS.md`