|
| 1 | +# Project Guidelines for Agentic Coding |
| 2 | + |
| 3 | +## Build & Commands |
| 4 | + |
| 5 | +```bash |
| 6 | +# Development |
| 7 | +bun dev # Start dev server with hot reload |
| 8 | +bun build # Production build |
| 9 | +bun preview # Preview production build |
| 10 | + |
| 11 | +# Code Quality |
| 12 | +bun check # Run Biome linter (auto-fixes with --write) |
| 13 | +bun pretty # Run Prettier formatter (auto-fixes) |
| 14 | +bun format # Custom format script |
| 15 | + |
| 16 | +# Utilities |
| 17 | +bun i18n:gen # Generate i18n translations |
| 18 | +bun assets:gen # Generate assets |
| 19 | +``` |
| 20 | + |
| 21 | +No test framework is currently configured in this project. |
| 22 | + |
| 23 | +## Code Style |
| 24 | + |
| 25 | +### Imports |
| 26 | + |
| 27 | +- Use `@/*` path alias for internal imports (configured in tsconfig.json) |
| 28 | +- External imports first, then internal imports |
| 29 | +- Use `import type` for type-only imports |
| 30 | + |
| 31 | +```typescript |
| 32 | +import { useState } from 'react'; |
| 33 | +import { useListTodos } from '@/services/hooks/todo/use-list-todos'; |
| 34 | +import type { TodoDto } from '@/types/dto/todo.dto'; |
| 35 | +``` |
| 36 | + |
| 37 | +### Formatting |
| 38 | + |
| 39 | +- Spaces for indentation (Biome configured) |
| 40 | +- Single quotes for strings and imports |
| 41 | +- Biome organizes imports automatically (`bun check`) |
| 42 | +- Prettier for additional formatting (`bun pretty`) |
| 43 | + |
| 44 | +### TypeScript |
| 45 | + |
| 46 | +- Strict mode enabled |
| 47 | +- Use `interface` for DTOs and object shapes |
| 48 | +- Use `enum` for fixed constants |
| 49 | +- Define types before implementation |
| 50 | + |
| 51 | +```typescript |
| 52 | +// ✅ Good |
| 53 | +export interface TodoDto { |
| 54 | + id: number; |
| 55 | + title: string; |
| 56 | + completed: boolean; |
| 57 | +} |
| 58 | + |
| 59 | +// ❌ Avoid |
| 60 | +export const todoDto = { ... }; |
| 61 | +``` |
| 62 | + |
| 63 | +### Naming Conventions |
| 64 | + |
| 65 | +- **Components**: PascalCase (e.g., `RouteComponent`, `ToastProvider`) |
| 66 | +- **Files**: kebab-case (e.g., `use-list-todos.ts`, `todo.dto.ts`) |
| 67 | +- **Functions/Variables**: camelCase (e.g., `formatTime`, `isEnabled`) |
| 68 | +- **Constants**: UPPER_SNAKE_CASE (e.g., `TOKEN_STORAGE_TYPE`) |
| 69 | +- **Custom Hooks**: `use` prefix (e.g., `useToast`, `useListTodos`) |
| 70 | +- **Types/Interfaces**: PascalCase, descriptive names (e.g., `TodoDto`, `ToastContextType`) |
| 71 | + |
| 72 | +### File Structure |
| 73 | + |
| 74 | +``` |
| 75 | +src/ |
| 76 | +├── helpers/ # Utilities (axios, i18n, utils, constants) |
| 77 | +├── services/ |
| 78 | +│ ├── hooks/ # Custom React hooks (grouped by feature) |
| 79 | +│ └── endpoints.ts # API endpoint definitions |
| 80 | +├── types/ |
| 81 | +│ ├── dto/ # Data Transfer Objects |
| 82 | +│ └── enums/ # Enum definitions |
| 83 | +├── providers/ # React context providers |
| 84 | +├── routes/ # TanStack router routes |
| 85 | +└── locales/ # i18n translation files |
| 86 | +``` |
| 87 | + |
| 88 | +### Error Handling |
| 89 | + |
| 90 | +- Use i18n for user-facing messages: `i18n.t('errorKey', { ns: 'exception' })` |
| 91 | +- Global error handling via axios interceptors (see `axios-instance.ts`) |
| 92 | +- Throw descriptive errors in hooks: |
| 93 | + |
| 94 | +```typescript |
| 95 | +if (!context) { |
| 96 | + throw new Error('useToast must be used within a ToastProvider'); |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +### React Patterns |
| 101 | + |
| 102 | +- Use TanStack Router for routing with file-based routes |
| 103 | +- Use TanStack Query for data fetching with custom hooks |
| 104 | +- Store feature hooks in `src/services/hooks/{feature}/` |
| 105 | +- Export `Route` component from route files: |
| 106 | + |
| 107 | +```typescript |
| 108 | +export const Route = createFileRoute('/')({ |
| 109 | + component: RouteComponent, |
| 110 | +}); |
| 111 | +``` |
| 112 | + |
| 113 | +### Routing Configuration |
| 114 | + |
| 115 | +- TanStack Router plugin configured in `rsbuild.config.ts` for file-based routing |
| 116 | +- Route tree auto-generated to `src/route-tree.gen.ts` |
| 117 | +- Route files with `___` prefix are ignored (e.g., `__root.tsx`) |
| 118 | +- Auto code splitting enabled for performance |
| 119 | +- Server base path configured via `envConfig.base` |
| 120 | +- All routes defined in `src/routes/` with pattern `*.tsx` |
| 121 | +- **Route generation happens automatically** when running `bun dev` or `bun build` - no separate command needed |
| 122 | + |
| 123 | +#### Layouts |
| 124 | + |
| 125 | +- Layouts use `_route.tsx` suffix (e.g., `/home/_route.tsx` for home layout) |
| 126 | +- Layout components export an `<Outlet />` to render child routes (similar to Next.js `_layout.tsx`): |
| 127 | + |
| 128 | +```typescript |
| 129 | +// src/routes/home/_route.tsx (layout) |
| 130 | +import { createFileRoute, Outlet } from '@tanstack/react-router'; |
| 131 | + |
| 132 | +export const Route = createFileRoute('/home/_route')({ |
| 133 | + component: HomeLayout, |
| 134 | +}); |
| 135 | + |
| 136 | +function HomeLayout() { |
| 137 | + return ( |
| 138 | + <div> |
| 139 | + <header>Home Layout</header> |
| 140 | + <Outlet /> {/* Child routes render here */} |
| 141 | + </div> |
| 142 | + ); |
| 143 | +} |
| 144 | +``` |
| 145 | + |
| 146 | +```typescript |
| 147 | +// src/routes/home/index.tsx (child route) |
| 148 | +import { createFileRoute } from '@tanstack/react-router'; |
| 149 | + |
| 150 | +export const Route = createFileRoute('/home/')({ |
| 151 | + component: HomeComponent, |
| 152 | +}); |
| 153 | +``` |
| 154 | + |
| 155 | +### Environment & Config |
| 156 | + |
| 157 | +- Environment vars in `.env` (see `.env.example`) |
| 158 | +- Config object via `envConfig` from `@/helpers/constants/env-config` |
| 159 | +- Never commit secrets or actual `.env` files |
| 160 | + |
| 161 | +### Committing Changes |
| 162 | + |
| 163 | +1. Run `bun check` to fix linting issues |
| 164 | +2. Run `bun pretty` to format code |
| 165 | +3. Verify build with `bun build` |
| 166 | +4. Commits only when explicitly requested |
| 167 | + |
| 168 | +### Key Dependencies |
| 169 | + |
| 170 | +- **Build**: Rsbuild, Bun, TypeScript |
| 171 | +- **Styling**: Tailwind CSS |
| 172 | +- **Routing**: @tanstack/react-router |
| 173 | +- **Data**: @tanstack/react-query, axios |
| 174 | +- **UI**: Ant Design (antd) |
| 175 | +- **Internationalization**: react-i18next |
| 176 | +- **Linting**: Biome, Prettier |
0 commit comments