Think Throo is in Beta — Some features are still evolving. Expect improvements and the occasional rough edge.
Toucan Codebase Architecture
1 chapter
Toucan Codebase Architecture
A comprehensive architecture skill for production-grade React SPAs. Guides AI agents through a feature-driven architecture built with React, Vite, React Query, Zustand, and React Hook Form — covering the full vertical slice from API to UI. Apply this skill when scaffolding new features, deciding where a file belongs, wiring up API hooks, managing state with Zustand stores, protecting routes, handling errors, optimising performance, or setting up tests and CI/CD pipelines. Rules span project structure, API layer design, security, component patterns, state management, error handling, performance, testing, and deployment.
Install
SKILL.md
/--- name: toucan-codebase-architecture description: > React SPA codebase architecture guide. Use when scaffolding a new feature, placing files, wiring up an API hook, adding a Zustand store, protecting a route, handling errors, or optimising performance. Covers the complete vertical slice from API to UI using a feature-driven architecture. Triggers on any task involving project structure, API design, state management, security, components, error handling, performance, deployment, or testing in a React + Vite + React Query codebase. license: MIT metadata: author: thinkthroo version: "1.0.0" series: amazon-rainforest /---
Toucan — Codebase Architecture
A comprehensive architecture guide for production-grade React SPAs, demonstrated through a feature-driven architecture with React, Vite, React Query, Zustand, and React Hook Form.
All code examples use generic
Resource,createResource,useResources, etc. so the patterns transfer cleanly to any domain — swap the entity name for your own.
When to Apply
Reference these guidelines when:
- Scaffolding a new feature end-to-end (API hook → store → UI)
- Deciding where a new file belongs
- Writing or reviewing React Query hooks and API clients
- Creating or refactoring Zustand stores
- Protecting routes or implementing authorization
- Adding error handling and observability
- Optimising re-renders or bundle size
- Setting up tests or CI/CD pipelines
Rule Categories by Priority
| Priority | Category | Impact | Prefix | Rule file |
|----------|----------|--------|--------|-----------|
| 1 | Project Structure | CRITICAL | struct- | rules/project-structure.md |
| 2 | API Layer | CRITICAL | api- | rules/api-layer.md |
| 3 | Security | HIGH | sec- | rules/security.md |
| 4 | State Management | MEDIUM-HIGH | state- | rules/state-management.md |
| 5 | Component Structure | MEDIUM | comp- | rules/component-structure.md |
| 6 | Error Handling | MEDIUM | err- | rules/error-handling.md |
| 7 | Performance | LOW-MEDIUM | perf- | rules/performance.md |
| 8 | Project Standards | LOW-MEDIUM | standards- | rules/project-standards.md |
| 9 | Deployment | LOW | deploy- | rules/deployment.md |
| 10 | Testing | LOW | test- | rules/testing.md |
Quick Reference
1. Project Structure (CRITICAL)
struct-directory-layout— Feature-driven layout withsrc/features/as the corestruct-data-flow— Unidirectional: shared → features → appstruct-feature-modules— One self-contained module per featurestruct-no-cross-feature— Features never import from other featuresstruct-file-placement— Decision table for where every type of file belongs
2. API Layer (CRITICAL)
api-single-client— One pre-configured Axios instance insrc/lib/api-client.tsapi-interceptors— Auth headers, response unwrapping, and error notifications globallyapi-query-pattern— Fetcher function + queryOptions factory + useQuery hookapi-mutation-pattern— Zod schema + mutation function + cache invalidation hookapi-prefetching— Prefetch query data on hover for snappy navigation
3. Security (HIGH)
sec-token-storage— Tokens stored in HttpOnly cookies; never localStoragesec-auth-config—react-query-authwraps all auth mutations and statesec-protected-routes—ProtectedRouteguard wraps all authenticated routessec-rbac— Role-based access withuseAuthorizationhook andAuthorizationcomponentsec-pbac— Policy-based access for resource-level permission checkssec-xss-prevention— Always sanitize user-generated HTML with DOMPurify
4. State Management (MEDIUM-HIGH)
state-categories— Five distinct categories: component, application, server cache, form, URLstate-component-state— Start withuseState/useReducer; elevate only when neededstate-global-ui— Zustand for global UI state (notifications, modals, theme)state-server-cache— React Query exclusively for all server data; never Zustand for API datastate-form-state— React Hook Form + Zod for all form state and validationstate-url-state— React Router params and search params for bookmarkable statestate-decision-tree— Decision tree for choosing the right state tool
5. Component Structure (MEDIUM)
comp-shared-vs-feature— Shared insrc/components/, feature-scoped insrc/features/<f>/components/comp-no-nested-render— Never write nested render functions; extract into componentscomp-composition-pattern— Use children/slots instead of excessive propscomp-tailwind-cn— Tailwind CSS +cn()helper for all stylingcomp-shadcn-pattern— ShadCN UI for component library; components are owned codecomp-form-pattern— AbstractedFormcomponent built on React Hook Form
6. Error Handling (MEDIUM)
err-central-interceptor— All API errors caught in Axios response interceptorerr-error-boundaries— App-level, route-level, and component-level error boundarieserr-query-errors— React QueryisErrorstate for inline error displayerr-sentry— Sentry for production error tracking with source maps
7. Performance (LOW-MEDIUM)
perf-code-splitting— Route-level lazy() imports for bundle splittingperf-state-optimizations— Split state, keep state local, lazy initializersperf-children-optimization— Pass stable children to avoid re-rendersperf-image-optimization— Lazy loading, WEBP format, responsive srcsetperf-prefetching— Prefetch on hover; route loaders for data-before-render
8. Project Standards (LOW-MEDIUM)
standards-eslint— ESLint with import restriction rules and naming conventionsstandards-prettier— Prettier with format-on-savestandards-typescript— TypeScript strict mode; noanystandards-husky— Husky + lint-staged pre-commit hooksstandards-absolute-imports—@/prefix for allsrc/imports
9. Deployment (LOW)
deploy-platform— Recommended platforms (Vercel, Netlify, AWS CloudFront)deploy-env-vars— Validated env module; neverimport.meta.envdirectlydeploy-ci-cd— CI/CD pipeline: lint → typecheck → test → build → E2E → deploydeploy-caching— Long-lived static assets; no-cache HTMLdeploy-preview— Preview deployments for every pull request
10. Testing (LOW)
test-strategy— Integration-first: unit < integration < E2Etest-unit— Pure functions, utilities, and complex isolated componentstest-integration— Every feature route tested with MSW-mocked APItest-e2e— Critical user journeys with Playwrighttest-msw— MSW for HTTP-level mocking; never mock modules directly
How to Use
Read a rule file for the detailed explanation and code examples:
rules/project-structure.md — struct-* rules
rules/api-layer.md — api-* rules
rules/security.md — sec-* rules
rules/state-management.md — state-* rules
rules/component-structure.md — comp-* rules
rules/error-handling.md — err-* rules
rules/performance.md — perf-* rules
rules/project-standards.md — standards-* rules
rules/deployment.md — deploy-* rules
rules/testing.md — test-* rules
Each rule contains:
- Why it matters — the problem it prevents
- Bad example — what not to do, with explanation
- Good example — the correct pattern, with explanation
Full Compiled Document
For all rules expanded in one flat document: AGENTS.md