|
| 1 | +--- |
| 2 | +applyTo: "**" |
| 3 | +--- |
| 4 | + |
| 5 | +## Architecture Overview |
| 6 | + |
| 7 | +React SPA built with Vite using feature slice architecture with clean architecture principles. |
| 8 | + |
| 9 | +### Core Technologies |
| 10 | + |
| 11 | +- **React 19** with TypeScript |
| 12 | +- **Vite 7** for build tooling |
| 13 | +- **React Query (TanStack Query)** for data fetching |
| 14 | +- **React Router 7** for routing |
| 15 | +- **i18next** for internationalization |
| 16 | +- **MSW 2** for API mocking |
| 17 | +- **Vitest 4** for unit and component testing |
| 18 | +- **Storybook 10** for component development |
| 19 | +- **Playwright** for E2E testing |
| 20 | +- **Zustand** for state management |
| 21 | +- **Chakra UI** for components |
| 22 | +- **XState** for state machines |
| 23 | + |
| 24 | +### Project Structure |
| 25 | + |
| 26 | +``` |
| 27 | +. |
| 28 | +├── e2e/ # End-to-end tests with Playwright |
| 29 | +└── src/ |
| 30 | + ├── app/ # App-level configuration (App.tsx, Providers.tsx) |
| 31 | + ├── features/ # Feature modules using feature slice architecture |
| 32 | + │ ├── auth/ # Authentication feature |
| 33 | + │ ├── carts/ # Shopping cart feature |
| 34 | + │ ├── products/ # Product catalog feature |
| 35 | + ├── lib/ # Shared libraries and utilities |
| 36 | + │ ├── api/ # Centralized API layer (queries, commands, DTOs) |
| 37 | + │ ├── components/ # Reusable UI components |
| 38 | + │ ├── http/ # HTTP client and error handling |
| 39 | + │ ├── i18n/ # Internationalization setup |
| 40 | + │ ├── router/ # Routing utilities |
| 41 | + │ └── theme/ # Theme configuration |
| 42 | + ├── pages/ # Route-level page components composing feature components & logic |
| 43 | + └── test-lib/ # Testing utilities and fixtures |
| 44 | +``` |
| 45 | + |
| 46 | +### Feature Architecture |
| 47 | + |
| 48 | +Each feature follows feature slice architecture patterns with three layers: |
| 49 | + |
| 50 | +- **presentation/** - UI components, UI-wise hooks |
| 51 | +- **application/** - Business logic, state management, logic-wise hooks |
| 52 | +- **infrastructure/** - Data fetching, external APIs, contracts, DTOs |
| 53 | +- **types/** - Type definitions |
| 54 | + |
| 55 | +### Key Patterns |
| 56 | + |
| 57 | +| Pattern | Description | |
| 58 | +| --------------------- | ---------------------------------------------------------------- | |
| 59 | +| Co-location | Related files (component + story + test) grouped together | |
| 60 | +| MSW handlers | API mocking centralized in `test-lib/handlers/` | |
| 61 | +| Fixture pattern | Test data generation in `test-lib/fixtures/` | |
| 62 | +| Strong typing | Comprehensive TypeScript with branded types | |
| 63 | +| Component Composition | Features export composed components for pages | |
| 64 | +| Centralized API | All API logic in `src/lib/api/` with endpoint-based organization | |
| 65 | + |
| 66 | +### State Management |
| 67 | + |
| 68 | +| Type | Use Case | |
| 69 | +| -------------- | ------------------------------------------------------------------------------------------------------------- | |
| 70 | +| XState | State orchestration with explicit states and constrained transitions (e.g., auth flows, multi-step processes) | |
| 71 | +| Zustand stores | Complex local state (auth, modals, etc.) | |
| 72 | +| React Query | Server state and caching | |
| 73 | +| React state | Simple component state | |
| 74 | + |
| 75 | +XState is preferred for business processes where states must be explicit and transitions constrained. |
| 76 | + |
| 77 | +### Routing |
| 78 | + |
| 79 | +- **File-based routing** - Pages in `src/pages/` with corresponding loaders |
| 80 | +- **Strong typing** - Route paths defined in `lib/router/routes.ts` |
| 81 | +- **Lazy loading** - Components loaded on demand with error boundaries |
| 82 | + |
| 83 | +### Error Handling |
| 84 | + |
| 85 | +- Using `react-error-boundary` for unexpected component runtime errors |
| 86 | + |
| 87 | +### Build Optimization |
| 88 | + |
| 89 | +- Lazy loading and code splitting based on `react-router` |
| 90 | +- Using direct imports instead of default exports |
0 commit comments