AI Rules Hub
AI Rules Hub
Log In

React feature-based architecture rules

No description provided.

Install via CLI
$ npx @airuleshub/cli@latest add react-feature-based-architecture-rules

Rule Content

šŸŽÆ RULE: FEATURE-BASED STRUCTURE IS MANDATORY

All code MUST be organized by feature. Each feature MUST be self-contained and isolated.


šŸ“ FOLDER STRUCTURE (REACT)

src/ā”‚ā”œā”€ā”€ app/                          # App entry (providers, routing setup)│   ā”œā”€ā”€ App.tsx│   ā”œā”€ā”€ providers.tsx│   └── routes.tsxā”‚ā”œā”€ā”€ features/│   ā”œā”€ā”€ auth/│   │   ā”œā”€ā”€ components/│   │   │   ā”œā”€ā”€ LoginForm.tsx│   │   │   └── RegisterForm.tsx│   │   ││   │   ā”œā”€ā”€ hooks/│   │   │   ā”œā”€ā”€ useLogin.ts│   │   │   └── useRegister.ts│   │   ││   │   ā”œā”€ā”€ queries/│   │   │   ā”œā”€ā”€ auth.queries.ts│   │   │   └── auth.mutations.ts│   │   ││   │   ā”œā”€ā”€ services/│   │   │   └── auth.api.ts│   │   ││   │   ā”œā”€ā”€ types/│   │   │   └── auth.types.ts│   │   ││   │   ā”œā”€ā”€ utils/│   │   │   └── auth.utils.ts│   │   ││   │   ā”œā”€ā”€ constants/│   │   │   └── auth.constants.ts│   │   ││   │   └── index.ts│   ││   ā”œā”€ā”€ products/│   │   ā”œā”€ā”€ components/│   │   ā”œā”€ā”€ hooks/│   │   ā”œā”€ā”€ queries/│   │   ā”œā”€ā”€ services/│   │   ā”œā”€ā”€ types/│   │   ā”œā”€ā”€ utils/│   │   ā”œā”€ā”€ constants/│   │   └── index.tsā”‚ā”œā”€ā”€ shared/│   ā”œā”€ā”€ components/               # reusable UI (Button, Modal)│   ā”œā”€ā”€ hooks/                    # generic hooks│   ā”œā”€ā”€ lib/                      # api client, query client│   │   ā”œā”€ā”€ api.ts│   │   └── query-client.ts│   ā”œā”€ā”€ utils/│   ā”œā”€ā”€ constants/│   └── types/ā”‚ā”œā”€ā”€ providers/│   └── QueryProvider.tsx         # TanStack setupā”‚ā”œā”€ā”€ styles/│   └── globals.cssā”‚ā”œā”€ā”€ assets/│   ā”œā”€ā”€ images/│   └── icons/ā”‚ā”œā”€ā”€ config/│   └── env.tsā”‚ā”œā”€ā”€ types/                        # global types (rare)│└── main.tsx

⚔ REACT RULES

  • Features MUST NOT import from other features
  • Components MUST NOT call APIs directly
  • All server state MUST use TanStack Query
  • Hooks MUST encapsulate all business logic
  • Shared layer MUST remain generic (no domain logic)
  • Query keys MUST be structured and typed

🚫 COMMON FORBIDDEN

  • API calls inside components
  • Cross-feature imports
  • Global business logic
  • useEffect for fetching
  • Monolithic folders

Command Palette

Search for a command to run...