This extends the global instructions from the specs repository.
- Repository: api
- Purpose: NestJS backend serving REST, GraphQL, and WebSocket endpoints for the LocalStore Platform
- Tech Stack: NestJS 10, TypeScript 5, PostgreSQL 14, Redis 7, TypeORM, Bull Queue
- Spec Version: v1.1-specs
When the user says "continue work", "tiếp tục", or "next task":
Read docs/CURRENT_WORK.md in this repository to understand:
- Current sprint and focus
- Which stories are assigned to this repo
- Current status of each story (🔴 Not Started / 🟡 In Progress / ✅ Done)
- Any blockers or notes from previous session
From CURRENT_WORK.md:
- If any story is 🟡 In Progress → continue that story
- Otherwise, pick the first 🔴 Not Started story
- If all stories are ✅ Done → report completion and suggest next sprint
- Check the "Spec References" section in CURRENT_WORK.md for the spec link
- Fetch and read the relevant specification section
- Also check
docs/SPEC_LINKS.mdfor additional context if needed
- Follow the spec exactly
- Apply code standards from this file (see below)
- Multi-tenant isolation, Vietnamese locale support
After implementation, update docs/CURRENT_WORK.md:
- Change story status from 🔴 to 🟡 (in progress) or ✅ (done)
- Add notes about what was implemented
- Add any blockers or follow-up items
- Update "Last Updated" timestamp
- Create/use feature branch:
feat/<story-description> - Commit with conventional message
- Start Docker and run all tests:
pnpm run docker:up:seed # Start services with sample data pnpm run lint # Check code quality pnpm run test # Run unit tests pnpm run test:api # Run Postman/Newman API tests
- Create PR when story is complete
After completing a story, post an event to #agent-events (channel ID: C0A1VSFQ9SS):
📤 API_READY from api: [Story Title]
---
Details: [What endpoints/features were implemented]
Affected: [contracts, menu, mobile, dashboard]
Action: [What other repos should do - e.g., "Add types", "Integrate API"]
Spec: [Link to relevant spec section]
Use slack_post_message with channel_id C0A1VSFQ9SS.
Tell the user:
- What story you worked on
- What was implemented
- Current status
- What's next
- Event posted to Slack
When the user says "sync events", "check events", or "đồng bộ":
- Read recent messages from
#agent-events(channel ID:C0A1VSFQ9SS) usingslack_get_channel_history - Filter for events affecting this repo (look for "api" in Affected field)
- Report relevant events to user with recommended actions
- If SCHEMA_UPDATED from contracts → suggest updating dependencies
- If SPEC_CHANGED from specs → suggest reviewing spec changes
| Spec File | Sections | Purpose |
|---|---|---|
architecture/api-specification.md |
Lines 80-1200 | REST endpoints |
architecture/api-specification.md |
Lines 1200-1800 | GraphQL schema |
architecture/backend-setup-guide.md |
Lines 1-600 | NestJS setup, TypeORM |
architecture/database-schema.md |
Lines 80-750 | Tables, RLS, indexes |
planning/sprint-0.5-menu-demo.md |
Stories 2.1-2.3 | Current sprint tasks |
Also check docs/SPEC_LINKS.md for curated links with line numbers.
pnpm install # Install dependencies
pnpm run start:dev # Start development server
pnpm run test # Run unit tests
pnpm run test:e2e # Run E2E tests
pnpm run test:api # Run Postman/Newman API tests
pnpm run lint # Lint code
pnpm run build # Build for production# Development (uses docker-compose.dev.yml)
pnpm run docker:up # Start postgres, redis, migrate, and api
pnpm run docker:up:seed # Start with sample data (includes seed)
pnpm run docker:down # Stop and remove containers + volumes
pnpm run docker:reset # Full reset with seed data
pnpm run docker:logs # View API container logs
# Manual Docker Compose
docker compose -f docker-compose.dev.yml up -d # Start dev environment
docker compose -f docker-compose.dev.yml --profile seed up # Include seed data
docker compose -f docker-compose.dev.yml down -v # Stop and clean volumes
# Production (uses docker-compose.yml for EC2)
docker compose up -d # Start production environmentsrc/
├── modules/
│ ├── menu/ # Menu CRUD (Sprint 0.5 focus)
│ ├── auth/ # JWT + OTP authentication
│ ├── location/ # Multi-location management
│ └── analytics/ # Metrics and AI integration
├── common/
│ ├── decorators/ # @CurrentTenant, @Public
│ ├── guards/ # JwtAuthGuard, RolesGuard
│ ├── filters/ # Exception filters (Vietnamese messages)
│ └── interceptors/ # Logging, caching
├── database/
│ ├── migrations/ # TypeORM migrations
│ └── seeds/ # Vietnamese sample data
└── grpc/ # AI service client
- Use modules for feature boundaries (
src/modules/menu/) - Controllers handle HTTP, Services contain business logic
- Use DTOs with class-validator for request/response validation
- Entities mirror database-schema.md exactly
- CRITICAL: Always scope queries by
tenant_id - Use
@CurrentTenant()decorator to get tenant from JWT - RLS policies are set in PostgreSQL, but also validate in application layer
- Entity names: singular, PascalCase (
MenuItem, notMenuItems) - Column names: snake_case in database, camelCase in TypeScript
- Always include
tenant_idin entity definitions - Use migrations for schema changes, never sync
- Use NestJS exception filters
- Return Vietnamese error messages for user-facing errors
- Include error codes for programmatic handling
- Log errors with structured format (Winston)
- Default locale: vi-VN
- Currency: VND with format 75.000₫
- Error messages: Vietnamese for user-facing, English for system logs
CRITICAL: Follow docs/GIT_WORKFLOW.md:
- Always create a new branch for changes
- If currently on
main, checkout to a new branch before committing - Branch naming:
<type>/<short-description>
| Type | Description |
|---|---|
feat |
New feature |
fix |
Bug fix |
chore |
Maintenance, dependencies, tooling |
docs |
Documentation only |
refactor |
Code refactoring |
test |
Adding or updating tests |
- Group related changes into logical commits
- Each commit should represent a single logical change
- Use conventional commit format:
<type>: <short description>
- Detail 1
- Detail 2
Each commit should answer ONE question: "What single feature/fix does this add?"
Rule of thumb: If you need "and" to describe the commit, split it.
- ❌
Add docs and config files→ Split - ✅
Add GitHub PR template and CODEOWNERS→ OK (same purpose: GitHub config)
After committing:
- Push the branch to origin
- Create a PR to
mainbranch - If PR already exists, update the title and description
- Do not wait for confirmation - push and create PR automatically
- Unit tests for all services (Jest)
- E2E tests for API endpoints (Supertest)
- Test multi-tenant isolation
- Mock external services (Redis, AI service)
- Requires:
contractsrepo for shared TypeScript types (@localstore/contracts) - Provides API for:
menuanddashboardrepos - Communicates with:
mlrepo via gRPC (future)
CRITICAL: When implementing features that require new DTOs:
- Do NOT create new DTOs locally without coordinating with contracts
- Post a message to
#agent-events(channel ID:C0A1VSFQ9SS) requesting the DTO:
📋 DTO_REQUEST from api: [DTO Name]
---
Details: [Description of the DTO structure needed]
Endpoint: [The API endpoint that will use this DTO]
Fields: [List of fields with types]
Affected: contracts
Action: Create new DTO in @localstore/contracts
- Wait for contracts to publish a new version with the DTO
- Update @localstore/contracts dependency to the new version
- Import and use the DTO from contracts
This ensures type synchronization across all services (api, menu, mobile, dashboard).