A practical guide to structuring Next.js/React applications using feature-based architecture with layered data flow (app, features, domains, core).
This repo contains two artifacts:
An installable skill for Cursor and OpenAI Codex agents that guides code generation to follow feature-based architecture patterns.
Location: skills/feature-based-frontend/
What it does:
- Enforces 4-layer import rules (app → features → domains → core)
- Provides checklists for adding new domains (5 steps) and features (4 steps)
- Guides server vs client component decisions
- Ensures proper data fetching patterns (thin domain hooks + rich feature hooks)
Copy or symlink the skill folder to your Cursor skills directory:
# Personal skill (available in all projects)
cp -r skills/feature-based-frontend ~/.cursor/skills/
# Or project-level skill (shared via repo)
cp -r skills/feature-based-frontend .cursor/skills/Then invoke with: Use $feature-based-frontend to add a new frontend domain and feature with proper layer boundaries.
The skill includes agents/openai.yaml for Codex compatibility. Place the skill folder where your Codex agent can discover it.
skills/feature-based-frontend/
├── SKILL.md # Main instructions (procedural, < 500 lines)
├── agents/
│ └── openai.yaml # Codex agent interface metadata
└── references/
├── layer-rules.md # Import boundaries and enforcement
├── domains-layer.md # API, types, mappers, thin hooks
├── features-layer.md # Components, hooks, stores, shared
└── testing.md # Vitest, component tests, hook tests
- Four-Layer Architecture -- app, features, domains, core with strict import direction
- Feature Isolation -- independent UI modules that never cross-import
- Thin Domain Hooks --
useQuery/useMutationwrappers with no business logic - Rich Feature Hooks -- compose domain hooks with UI state and business logic
- Server-First Components -- default to Server Components, add
"use client"only when needed - Layer Testing -- each layer mocks the layer below it
MIT