Skip to content
Skills Library
Programming · Planning

react-layered-architecture

/react-layered-architecture

Use when creating, moving, or naming files in a plain React app (Vite or similar SPA, no Next.js/Remix) organized by technical layer (pages, components, hooks, queries). Best for small to mid-size apps. Covers layout, naming, import direction, config, tests, and when to move to react-domain-architecture.

Licence
MIT
Last repository change
02.11.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
4
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 02.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use when creating, moving, or naming files in a plain React app (Vite or similar SPA, no Next.js/Remix) organized by technical layer (pages, components, hooks, queries). Best for small to mid-size apps. Covers layout, naming, import direction, config, tests, and when to move to react-domain-architecture.

Original author description

Use when creating, moving, or naming files in a plain React app (Vite or similar SPA, no Next.js/Remix) organized by technical layer (pages, components, hooks, queries). Best for small to mid-size apps. Covers layout, naming, import direction, config, tests, and when to move to react-domain-architecture.

How it works

  1. Target version
  2. Follow the repo first
  3. Default directory layout
  4. Naming conventions
  5. Dependency direction
  6. Where things live
  7. Tests
  8. Structure at three sizes
  9. Anti-patterns
Original SKILL.md headings · 108 lines, 734 words
SKILL.md preview
---
name: react-layered-architecture
description: Use when creating, moving, or naming files in a plain React app (Vite or similar SPA, no Next.js/Remix) organized by technical layer (pages, components, hooks, queries). Best for small to mid-size apps. Covers layout, naming, import direction, config, tests, and when to move to react-domain-architecture.
license: MIT
---

# React layered architecture

Plain React single-page app, grouped by technical role. Server data is handled with TanStack Query (or a similar query client) in `queries/`. Use for small to mid-size projects.

## Target version

Written for React 19 with TypeScript and Vite on 2026-10-29. Applies to any client-only React setup. Not for meta-frameworks (Next.js, Remix), which have their own routing layout.

## Follow the repo first

Read `src/` before creating files. If the project already has conventions (folder names, casing, import alias), use them. Check `tsconfig.json` for path aliases and the lint config for import rules.

## Default directory layout

```
src/
  main.tsx        # entry: mounts <App />
  app.tsx         # providers and router
  pages/          # one component per route
  components/     # shared UI used by 2+ pages
    ui/           # generic primitives (Button, Modal)
  hooks/          # shared custom hooks
  queries/        # query and mutation hooks, query keys, request functions
  store/          # global client state
  utils/          # pure helper functions
  types/          # shared types
  config/         # env parsing and constants
  styles/         # global CSS and tokens
  test/           # test setup and shared test helpers
```

Read [references/full-tree.md](references/full-tree.md) when you need the expanded tree with every subfolder.

## Naming conventions

- Files and folders: kebab-case for everything, such as `user-card.tsx` and `use-users.ts`. Do not mix casing.
- Exports: use named exports. Avoid default exports.
- Components: one component per file. The export is PascalCase and the file is its kebab-case form: `UserCard` in `user-card.tsx`.
- Hooks: `use-thing.ts`, exporting `useThing`.
- Queries: `user.queries.ts`, one per backend resource. Exports hooks (`useUsers`, `useCreateUser`) and a key factory (`userKeys`).
- Types: `user.types.ts`.
- Routes: pages are `user-list-page.tsx`. URL paths are kebab-case.
- Tests: `user-card.test.tsx` next to the file under test.
- Imports: use the `@/` alias for `src/`. Never import with `../../..`.

## Dependency direction

Higher layers may import lower layers. Lower layers never import higher ones.

```
pages -> components -> queries, hooks -> utils -> types
```

- `pages` import from any layer below.
- `components` import `queries`, `hooks`, `utils`, `types`, and other components. Never `pages`.
- `queries` import `utils`, `types`, `config`, and `queries/api-client.ts`. Never `components`, `pages`, or `store`.
- `hooks` hold UI and generic logic. They may import `queries`, `store`, `utils`, `types`.
- `utils` and `types` import nothing from the app.

## Where things live

- Config: `src/config/`. Read `import.meta.env` only in `config/env.ts`.
- Env vars: prefix with `VITE_`. List every var in `.env.example` at the repo root.
- Shared types: `src/types/`. Keep a type next to its only user until a second file needs it.
- Global state: `src/store/`. Keep server data in the query cache, not in `store/`. Keep UI state local.
- Query client: create it in `src/config/query-client.ts`. Mount the provider in `app.tsx`.
- HTTP client: `src/queries/api-client.ts`. Only `queries/` files call it.

## Tests

- Put unit and component tests next to the file: `button.tsx`, `button.test.tsx`.
- Put test setup and shared helpers in `src/test/`.
- Put end-to-end tests in `e2e/` at the repo root.

## Structure at three sizes

Read [references/growth-stages.md](references/growth-stages.md) when deciding whether to restructure.

### Prototype

Use `main.tsx`, `app.tsx`, and `components/`. Add `hooks/` and `queries/` on first use.
Signal to move up: a second page, or an API call.

### Mid-size

Use the default layout above. Add subfolders inside a layer when it passes about 10 files, for example `components/forms/`.
Signal to move up: `components/` or `hooks/` passes about 30 files, one feature change touches 4+ top-level folders, or several people collide in the same folders.

### Large

Switch to the `react-domain-architecture` skill. Move one feature at a time. Do not rewrite.

## Anti-patterns

Read [references/anti-patterns.md](references/anti-patterns.md) when reviewing a layout or before moving files.

- Do not call `fetch` or an API client inside a component. Use a hook from `queries/`.
- Do not write query keys inline. Use the key factory from the resource's `queries/` file.
- Do not import React components in `queries/` or `utils/`.
- Do not import `pages/` from `components/`.
- Do not put a component in `components/` if only one page uses it. Keep it next to that page.
- Do not create a `common/`, `misc/`, or `helpers/` folder.
- Do not add an `index.ts` barrel to every folder.
- Do not copy query data into `useState` or `store/`.
- Do not use deep relative imports. Use `@/`.
- Do not use PascalCase or camelCase file names, or rename a file only to change its case.
Files in this package (4)
  • SKILL.md 5 KB
  • references/anti-patterns.md 2 KB
  • references/full-tree.md 2 KB
  • references/growth-stages.md 1 KB

Versions

The database has no other skills named react-layered-architecture.

Database snapshot: 13.11.2026 · package version 68a20e0361c9 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 1 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100nextjs-layered-architecture
    Use when creating, moving, or naming files in a full-stack Next.js App Router app organized by technical layer (components, actions, services, queries, db). Best for small to mid-size apps. Covers layout, naming, import direction, server actions, TanStack Query, route handler…
  • 100react-domain-architecture
    Use when creating, moving, or naming files in a plain React app (Vite or similar SPA, no Next.js/Remix) organized by business domain, with a modules/ folder and a core/ folder outside it. Best for mid to large apps and teams. Covers module layout, public APIs, import boundaries,…
  • 100react
    Use when building or reviewing a client-side React SPA bundled by Vite (React 19.2): components, where state lives, hooks, server data fetching, client routing, re-render and effect bugs. NOT App Router / server components / SSR (that is `nextjs`); NOT native screens (that is `react-native`).
  • 100fe-build
    Implements frontend components and pages for React / Next.js / Vite SPA + TypeScript projects. Use when: starting implementation after feature.md or a spec is approved, writing components, building pages. Do NOT load for: writing specs, code review, bug analysis.
  • 100vite-react-best-practices
    Comprehensive React 19 and Vite 8 SPA performance, architecture, and deployment guidelines. Use this skill when building, reviewing, or refactoring React applications built with Vite (SPA). Covers Vite 8 build and static hosting requirements, React Router 8 route-level code…
  • 100react-best-practices
    React component patterns, hooks, state management, and performance best practices. Use when building or reviewing React components.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.