10-12 Week Implementation Plan
| Phase | Weeks | Focus | Deliverable |
|---|---|---|---|
| 0 | 1 | Architecture & Foundation | Docker, scaffold, base config |
| 1 | 2 | Auth Module | JWT, OAuth, RBAC, rate limiting |
| 2 | 3–4 | Product & Inventory | CRUD, variants, stock, upload |
| 3 | 5–6 | Order + Payment (CORE) | BullMQ pipeline, Stripe, VNPay |
| 4 | 7 | Notification + Caching | Async notify, Redis cache |
| 5 | 8 | Analytics + Admin FE | Dashboard, charts, DLQ UI |
| 6 | 9 | Testing + Security | Unit test, integration test, OWASP |
| 7 | 10 | Deploy + Document | Docker, CI/CD, README, demo video |
| Bonus | 11–12 | Microservice + AI Search | Tách service, pgvector |
- Design ERD (finalize
database-design.md) - Setup monorepo hoặc single repo structure
- Initialize NestJS project với TypeScript strict mode
- Setup Docker Compose: PostgreSQL 16 + Redis 7
- Configure Prisma ORM + initial migration
- Setup project structure:
src/ ├── modules/ │ ├── auth/ │ ├── user/ │ ├── product/ │ ├── inventory/ │ ├── order/ │ ├── payment/ │ ├── notification/ │ └── analytics/ ├── common/ │ ├── decorators/ │ ├── filters/ │ ├── guards/ │ ├── interceptors/ │ ├── pipes/ │ └── utils/ ├── config/ └── prisma/ - Setup global exception filter
- Setup Winston structured logging + correlation ID mid dleware
- Setup environment configuration (ConfigModule)
- Write ADR documents
✅ docker-compose up khởi động PG + Redis
✅ NestJS app chạy, /health endpoint trả OK
✅ Prisma schema compile, migration chạy
✅ Logging middleware hoạt động với correlation ID
- Implement User entity + Prisma schema
- Register endpoint (email + password, bcrypt hash)
- Login endpoint (return JWT access + refresh token)
- JWT access token (15min expiry)
- Refresh token rotation:
- Issue new refresh + access token
- Revoke old refresh token
- Detect token reuse → revoke all family tokens
- Google OAuth 2.0 (Passport.js strategy)
- AuthGuard (JWT verification)
- RolesGuard +
@Roles()decorator -
@Public()decorator for open endpoints -
@CurrentUser()parameter decorator - Rate limiting middleware (Redis sliding window)
- Address CRUD for user
✅ Register/Login/Refresh/Logout flow hoàn chỉnh
✅ Google OAuth login works
✅ Protected routes return 401 without token
✅ Role-based access works (buyer vs seller vs admin)
✅ Rate limiting blocks after threshold
- Category CRUD (admin only) + nested tree
- Product CRUD (seller) + soft delete
- Product Variant CRUD + SKU generation
- Image upload to Cloudflare R2
- Product listing API with filters/pagination/sort
- Full-text search on product name
- Inventory table + 1:1 with variant
- Stock reservation logic (reserve on order)
- Stock release logic (release on payment fail)
- Optimistic locking implementation:
versioncolumn check on UPDATE- Retry on conflict (max 3)
- Low stock alert (threshold-based)
- Seed data script (categories + sample products)
✅ Seller can create/edit/delete products + variants ✅ Image upload works ✅ Search/filter/pagination works ✅ Concurrent stock reservation test passes:
- 2 concurrent requests for 1 remaining item → only 1 succeeds ✅ Stock reserve/release flow works
- Cart module (add/update/remove/clear)
- Checkout flow: cart → validate → create order
- Order number generation (
ORD-YYYYMMDD-XXXX) - Order status state machine
- OrderStatusHistory tracking
- BullMQ setup + queue definitions
- Order pipeline:
OrderCreated → ValidateStock → ReserveStock → ProcessPayment
- Payment Strategy Pattern:
-
PaymentProviderInterface -
StripeProviderimplementation -
VNPayProviderimplementation
-
- Stripe PaymentIntent creation + clientSecret return
- VNPay payment URL generation
- Webhook handlers:
- Stripe:
payment_intent.succeeded/failed - VNPay: return URL + IPN callback
- Stripe:
- Idempotency key for all webhooks
- Payment success flow:
ConfirmOrder → DeductStock → Notify - Payment failure flow:
ReleaseStock → CancelOrder → Notify - Saga compensation on pipeline failure (Đã xử lý rollback synchronous ở Checkout API)
- Dead Letter Queue setup
✅ End-to-end order flow: cart → checkout → payment → confirmed
✅ Stripe test mode payment works
✅ VNPay sandbox payment works
✅ Payment failure → stock release → order cancelled
✅ Webhook idempotency: same event processed once only
✅ DLQ captures failed jobs
✅ Order status history records all transitions
- BullMQ notification queue
- Email notification (Resend.com API)
- Telegram Bot notification (webhook)
- Notification templates:
- Order confirmed
- Payment received
- Payment failed
- Order shipped
- Redis cache layer:
- Product catalog cache (TTL: 5min)
- Category tree cache (TTL: 30min)
- Cache invalidation on product/category update
- Session store in Redis (if needed)
- Scheduled jobs:
cleanup-expired-carts(every 6h)cleanup-idempotency-keys(daily)release-stale-reservations(every 30min)
✅ Order confirmation email sent
✅ Telegram notification works
✅ Cache hit/miss observable in logs
✅ Cache invalidation works (update product → cache cleared)
✅ Scheduled jobs running on time
- Analytics aggregation background job (BullMQ cron, daily)
- Revenue by day/month API
- Best-selling products API
- Order conversion rate API
- Admin dashboard metrics API
- DLQ management API (list, retry, discard)
- Setup Next.js project (App Router)
- Auth flow (login, token storage)
- Dashboard page: metrics cards + charts (Recharts)
- Orders management page: list, filter, detail view
- Products management: list, create/edit, variants
- DLQ viewer: list failed jobs, retry/discard actions
- Basic responsive layout
✅ Admin can login and see dashboard metrics
✅ Charts render revenue/orders data
✅ Admin can manage orders (view, filter)
✅ Admin can manage DLQ jobs
- Unit tests for business logic:
- Order state machine transitions
- Price calculation + coupon application
- Stock reservation + optimistic locking
- Idempotency key validation
- JWT token rotation logic
- Integration tests for critical APIs:
- Auth flow (register → login → refresh → logout)
- Order flow (cart → checkout → webhook → confirm)
- Payment webhook idempotency
- Test coverage report (target: >70% on business logic)
- Input validation on ALL endpoints (class-validator)
- SQL injection prevention (Prisma parameterized queries)
- XSS prevention (sanitize user input)
- CORS configuration
- Helmet.js (security headers)
- Rate limiting verification
- Webhook signature verification (Stripe, VNPay)
- Environment variables: no secrets in code
✅ All unit tests pass
✅ Integration tests for auth + order flow pass
✅ No critical security vulnerabilities
✅ Rate limiting tested under load
- Dockerize NestJS app (multi-stage build)
- Docker Compose for production (PG + Redis + App)
- GitHub Actions CI: lint → test → build → deploy
- Deploy backend to Railway or VPS (Hetzner)
- Deploy admin frontend to Vercel
- Setup domain + SSL
- Environment variables on production
- Sentry error tracking setup
- README.md:
- Project overview + motivation
- Architecture diagram
- Tech stack + rationale
- Setup guide (local dev)
- API documentation link
- Demo account credentials
- Screenshots
- Architecture diagram (export as image)
- Record demo video (3-5 min): key flows
- API docs: Swagger/OpenAPI auto-generated
✅ Production deployment accessible via URL
✅ CI/CD pipeline green
✅ README complete with architecture diagram
✅ Demo video recorded
✅ Sentry capturing errors
- Tách Notification Module → standalone NestJS microservice
- Communication via Redis (NestJS microservice transport)
- Service discovery / health check
- Update architecture diagram
- Setup pgvector extension
- Embed product descriptions via OpenAI API
- Semantic search endpoint: natural language → results
- Example: "tai nghe gaming dưới 1 triệu" → relevant products
- Next.js storefront: product listing, detail, cart, checkout
- Responsive design
- SEO optimization
| Risk | Impact | Mitigation |
|---|---|---|
| Payment integration complexity | 🔴 High | Start with Stripe (better docs), add VNPay after |
| BullMQ pipeline debugging | 🟠 Medium | Add extensive logging, use BullMQ dashboard UI |
| Scope creep | 🟠 Medium | Stick to "depth over breadth" principle |
| AI-generated code not understood | 🔴 High | Write ADR for every pattern, explain in interview |
| Frontend taking too much time | 🟠 Medium | Admin only in Phase 1, minimal UI |