Feature Implementation Pattern
Use this skill when adding a new feature that involves both backend and frontend changes.
1. Backend (NestJS)
- •Module: Ensure a module exists for the domain (e.g.,
plants,devices). If not, create one. - •DTOs: Create Data Transfer Objects (DTOs) for all inputs. Use
class-validatordecorators.- •File:
backend/src/[domain]/dto/create-[entity].dto.ts
- •File:
- •Service: Implement the business logic in the service.
- •File:
backend/src/[domain]/[domain].service.ts
- •File:
- •Controller: Create endpoints in the controller. Use standard HTTP methods and
@Body,@Param,@Querydecorators.- •File:
backend/src/[domain]/[domain].controller.ts
- •File:
- •Prisma: If the database schema changes:
- •Modify
backend/prisma/schema.prisma - •Run
npx prisma migrate dev --name [migration_name] - •Run
npx prisma generate
- •Modify
2. Frontend (Next.js)
- •Types: Update or create TypeScript interfaces to match the backend DTOs/Entities.
- •File:
frontend/src/types/[domain].ts
- •File:
- •API Service: Add methods to
frontend/src/lib/apiService.tsor a domain-specific service (e.g.,deviceService.ts).- •Ensure proper error handling.
- •Components: Create reusable UI components in
frontend/src/components/[domain]/.- •Use
tailwind-merge(cn) for styling.
- •Use
- •Page: Implement the page in
frontend/src/app/[route]/page.tsx.- •Use Server Components for data fetching where possible.
- •Use Client Components for interactivity.
Checklist
- • Backend DTOs have validation.
- • Swagger documentation added (
@ApiTags,@ApiOperation). - • Frontend types match backend response.
- • UI is responsive (Mobile First).