feat: updade workspace

This commit is contained in:
thanhnv
2026-07-11 15:56:31 +09:00
parent 4fc72332f5
commit 193a449829
120 changed files with 868 additions and 350 deletions
+21 -21
View File
@@ -205,13 +205,13 @@ export default {
### Controller Rules:
- **Location:** Must be in `backend/src/[module-name]/[module-name].controller.ts`.
- **Location:** Must be in `apps/okr/backend/src/[module-name]/[module-name].controller.ts`.
- **Responsibility:** Keep controllers "thin". They only receive requests, trigger guards, validate DTOs, and call a single service method.
- **Auth:** Use `@UseGuards(JwtAuthGuard)` and `@Roles()` decorator on all protected routes.
### Service Rules:
- **Location:** Must be in `backend/src/[module-name]/[module-name].service.ts`.
- **Location:** Must be in `apps/okr/backend/src/[module-name]/[module-name].service.ts`.
- **Responsibility:** All business logic lives here.
- **Key Logic:**
- Use Prisma client for all DB operations — **no raw SQL** in application code.
@@ -220,14 +220,14 @@ export default {
### Prisma Schema Rules:
- **Single source of truth:** `backend/prisma/schema.prisma` defines ALL tables.
- **Single source of truth:** `apps/okr/backend/prisma/schema.prisma` defines ALL tables.
- **Migrations:** Use `npx prisma migrate dev --name <migration-name>` — never edit migration files manually.
- **Types:** Always use Prisma-generated types (`Prisma.ObjectiveCreateInput`, `Prisma.KeyResultUpdateInput`).
### Module Structure (OKR Domain):
```
backend/src/
apps/okr/backend/src/
├── auth/ # JWT login, refresh token endpoints
├── users/ # User CRUD (Admin/Manager only)
├── objectives/ # Objective CRUD, filtering by quarter/owner/status
@@ -238,12 +238,12 @@ backend/src/
### Database Seed Management:
- **CRITICAL:** After completing backend code with schema changes, **ALWAYS** update the seed file.
- **Seed file location:** `backend/prisma/seed.ts`
- **Seed file location:** `apps/okr/backend/prisma/seed.ts`
- **Execution:** `npx prisma db seed` (or automatically on container start — always seeded in workshop environment)
- **Idempotency:** Use Prisma `upsert` keyed on stable identifiers — running seed twice must produce no duplicates.
```typescript
// backend/prisma/seed.ts
// apps/okr/backend/prisma/seed.ts
import { PrismaClient } from '@prisma/client';
import * as bcrypt from 'bcrypt';
@@ -324,7 +324,7 @@ main()
### Routing Rules (React Router DOM v6):
```tsx
// frontend/src/App.tsx — route structure
// apps/okr/frontend/src/App.tsx — route structure
<Routes>
<Route path="/login" element={<Login />} />
<Route element={<ProtectedRoute />}>
@@ -340,14 +340,14 @@ main()
### Component & File Location Rules:
- **Route-level pages:** `frontend/src/pages/` (Login, Dashboard, OKRDetail, CreateObjective, KeyResultDetail)
- **Layout components:** `frontend/src/components/layout/` (Sidebar, Header, AppLayout)
- **Reusable UI components:** `frontend/src/components/ui/` (Button, ProgressBar, Badge, Table)
- **Custom hooks:** `frontend/src/hooks/` (useAuth, useObjectives, useKeyResults)
- **API client:** `frontend/src/lib/api.ts` — all Axios calls go here
- **Query client config:** `frontend/src/lib/queryClient.ts`
- **Zod schemas:** `frontend/src/schemas/`
- **TypeScript interfaces:** `frontend/src/types/`
- **Route-level pages:** `apps/okr/frontend/src/pages/` (Login, Dashboard, OKRDetail, CreateObjective, KeyResultDetail)
- **Layout components:** `apps/okr/frontend/src/components/layout/` (Sidebar, Header, AppLayout)
- **Reusable UI components:** `apps/okr/frontend/src/components/ui/` (Button, ProgressBar, Badge, Table)
- **Custom hooks:** `apps/okr/frontend/src/hooks/` (useAuth, useObjectives, useKeyResults)
- **API client:** `apps/okr/frontend/src/lib/api.ts` — all Axios calls go here
- **Query client config:** `apps/okr/frontend/src/lib/queryClient.ts`
- **Zod schemas:** `apps/okr/frontend/src/schemas/`
- **TypeScript interfaces:** `apps/okr/frontend/src/types/`
### Layout Construction Rules:
@@ -389,7 +389,7 @@ main()
### API Call Rules:
- All functions that make network requests must be in `frontend/src/lib/api.ts`.
- All functions that make network requests must be in `apps/okr/frontend/src/lib/api.ts`.
- Components call functions from `lib/api.ts` — they **never** call Axios directly.
- Base URL: `import.meta.env.VITE_API_BASE_URL` (e.g., `http://localhost:3000/api/v1`).
- Auth tokens are in HttpOnly cookies — do **not** manually attach `Authorization` headers.
@@ -397,7 +397,7 @@ main()
### Form Rules (React Hook Form + Zod):
```typescript
// frontend/src/schemas/objective.schema.ts
// apps/okr/frontend/src/schemas/objective.schema.ts
import { z } from 'zod';
export const createObjectiveSchema = z.object({
@@ -455,7 +455,7 @@ const { register, handleSubmit, formState: { errors } } = useForm<CreateObjectiv
meta?: { page: number; limit: number; total: number };
}
// ✅ OKR domain types (frontend/src/types/okr.types.ts)
// ✅ OKR domain types (apps/okr/frontend/src/types/okr.types.ts)
interface Objective {
id: number;
title: string;
@@ -499,11 +499,11 @@ const { register, handleSubmit, formState: { errors } } = useForm<CreateObjectiv
### Type Consistency Rules:
- **Frontend-Backend Alignment:** DTOs in backend must have matching interfaces in `frontend/src/types/`.
- **Frontend-Backend Alignment:** DTOs in backend must have matching interfaces in `apps/okr/frontend/src/types/`.
- **Enum Consistency:** Role (`ADMIN | MANAGER | EMPLOYEE`) and Status (`NOT_STARTED | IN_PROGRESS | COMPLETED`) enums must be identical between frontend and backend.
- **API Response Types:** Every API endpoint must have typed response interfaces matching the standard envelope `{ success, data, meta? }`.
- **Component Props:** Every component must have a properly typed props interface.
- **Zod Schemas:** Schemas in `frontend/src/schemas/` must align with backend `class-validator` rules on the corresponding DTO.
- **Zod Schemas:** Schemas in `apps/okr/frontend/src/schemas/` must align with backend `class-validator` rules on the corresponding DTO.
### Type Verification Checklist:
@@ -511,7 +511,7 @@ Before submitting any code, verify:
- [ ] No `any` types used
- [ ] All component props properly typed
- [ ] API calls have typed parameters and responses
- [ ] DTOs match between frontend/backend
- [ ] DTOs match between apps/okr/frontend/backend
- [ ] Role/Status enum values consistent across codebase
- [ ] Optional vs required properties correctly defined
- [ ] Zod schemas align with backend `class-validator` rules