- Add TOTP-based MFA with setup, verify, disable, backup codes, and challenge flow - Add PII field encryption middleware with AES-256-GCM and deterministic search hashes - Add agents, inquiries, and leads domain modules with entities, events, value objects - Add web dashboard pages for inquiries and leads with detail dialogs - Add 30+ component tests (valuation, charts, listings, search, providers, UI) - Add Prisma migrations for encryption hash columns and MFA TOTP support - Fix all ESLint errors (unused imports, duplicate imports, lint auto-fixes) - Update dependencies and lock file - Clean up obsolete exploration/QA docs, add audit documentation Co-Authored-By: Paperclip <noreply@paperclip.ing>
945 lines
25 KiB
Markdown
945 lines
25 KiB
Markdown
# GoodGo Platform AI - Comprehensive Codebase Audit
|
|
**Audit Date:** April 11, 2026
|
|
|
|
---
|
|
|
|
## 1. PROJECT STRUCTURE OVERVIEW
|
|
|
|
### Directory Organization
|
|
```
|
|
goodgo-platform-ai/
|
|
├── apps/ # Monorepo applications
|
|
│ ├── api/ # NestJS Backend (port 3001)
|
|
│ └── web/ # Next.js Frontend (port 3000)
|
|
├── libs/ # Shared libraries
|
|
│ ├── mcp-servers/ # Model Context Protocol servers
|
|
│ └── ai-services/ # Python AI services (FastAPI)
|
|
├── prisma/ # Database schema & migrations
|
|
│ ├── schema.prisma # 641 lines
|
|
│ └── migrations/ # 13 migrations
|
|
├── e2e/ # End-to-end tests
|
|
│ ├── api/ # API E2E tests (16 spec files)
|
|
│ ├── web/ # Web E2E tests (15 spec files)
|
|
│ └── fixtures/ # Test fixtures
|
|
├── infra/ # Infrastructure configs
|
|
├── monitoring/ # Prometheus, Grafana, Loki, AlertManager
|
|
└── scripts/ # Utility scripts
|
|
```
|
|
|
|
### File Counts
|
|
- **Total TypeScript/TSX Files:** 992 files
|
|
- **Total Lines of Code (apps/):** 70,569 LOC
|
|
- **Configuration-managed:** Turbo monorepo with pnpm
|
|
|
|
---
|
|
|
|
## 2. BACKEND (apps/api)
|
|
|
|
### Technology Stack
|
|
- **Framework:** NestJS 11.0.0
|
|
- **Runtime:** Node.js 22+
|
|
- **Language:** TypeScript 6.0.2 (strict mode enabled)
|
|
- **Database:** PostgreSQL 16 + PostGIS extension
|
|
- **ORM:** Prisma 7.7.0
|
|
- **API Documentation:** Swagger/OpenAPI
|
|
|
|
### Module Architecture (16 modules)
|
|
|
|
| Module | Files | Structure | Status |
|
|
|--------|-------|-----------|--------|
|
|
| **auth** | 108 | Domain ✓ / App ✓ / Infra ✓ / Presentation ✓ | Fully layered |
|
|
| **admin** | 93 | Domain ✓ / App ✓ / Infra ✓ / Presentation ✓ | Fully layered |
|
|
| **listings** | 83 | Domain ✓ / App ✓ / Infra ✓ / Presentation ✓ | Fully layered |
|
|
| **analytics** | 67 | Domain ✓ / App ✓ / Infra ✓ / Presentation ✓ | Fully layered |
|
|
| **search** | 66 | Domain ✓ / App ✓ / Infra ✓ / Presentation ✓ | Fully layered |
|
|
| **notifications** | 49 | Domain ✓ / App ✓ / Infra ✓ / Presentation ✓ | Fully layered |
|
|
| **payments** | 51 | Domain ✓ / App ✓ / Infra ✓ | Fully layered |
|
|
| **subscriptions** | 48 | Domain ✓ / App ✓ / Infra ✓ | Fully layered |
|
|
| **leads** | 41 | Domain ✓ / App ✓ / Infra ✓ | Fully layered |
|
|
| **reviews** | 38 | Domain ✓ / App ✓ / Infra ✓ | Fully layered |
|
|
| **inquiries** | 34 | Domain ✓ / App ✓ / Infra ✓ | Fully layered |
|
|
| **agents** | 29 | Domain ✓ / App ✓ / Infra ✓ | Fully layered |
|
|
| **metrics** | - | Infra-only module | Specialized |
|
|
| **health** | - | Simple controller-based | Status checks |
|
|
| **mcp** | - | Presentation-only | MCP integration |
|
|
| **shared** | - | Cross-cutting infrastructure | Utilities |
|
|
|
|
### Core Module Wiring (app.module.ts)
|
|
|
|
**All 16 modules are properly imported and registered:**
|
|
- SharedModule, HealthModule, AuthModule
|
|
- AgentsModule, InquiriesModule, LeadsModule, ListingsModule
|
|
- ReviewsModule, SearchModule, NotificationsModule, PaymentsModule
|
|
- SubscriptionsModule, AdminModule, AnalyticsModule, MetricsModule, McpIntegrationModule
|
|
|
|
### Architecture Layers
|
|
|
|
All primary modules follow **Hexagonal Architecture**:
|
|
```
|
|
Domain/
|
|
├── Entities (domain models)
|
|
├── Value Objects
|
|
├── Interfaces (repository contracts)
|
|
└── Specifications (business rules)
|
|
|
|
Application/
|
|
├── Commands (command handlers)
|
|
├── Queries (query handlers)
|
|
├── DTOs (data transfer objects)
|
|
└── Services (use case orchestration)
|
|
|
|
Infrastructure/
|
|
├── Database (Prisma repositories)
|
|
├── Cache (Redis)
|
|
├── Services (external integrations)
|
|
├── Subscribers (event handlers)
|
|
└── Specifications (Prisma queries)
|
|
|
|
Presentation/
|
|
├── Controllers (REST endpoints)
|
|
├── Guards (authorization)
|
|
└── Interceptors (cross-cutting concerns)
|
|
```
|
|
|
|
### Key Infrastructure Services (shared/infrastructure)
|
|
|
|
- **PrismaService** - Database ORM wrapper
|
|
- **RedisService** - Caching & rate limiting
|
|
- **LoggerService** - Structured logging (Pino)
|
|
- **CacheService** - Multi-strategy caching
|
|
- **FieldEncryptionService** - PII field encryption
|
|
- **CircuitBreakerService** - Fault tolerance
|
|
- **EventBusService** - CQRS event distribution
|
|
|
|
### Global Configuration
|
|
|
|
**app.module.ts provides:**
|
|
- CQRS Module (command/query pattern)
|
|
- Schedule Module (background jobs)
|
|
- Throttler Module (rate limiting)
|
|
- Default: 60 req/min
|
|
- Auth: 10 req/min
|
|
- Payments: 20 req/min
|
|
- Sentry Integration (error tracking)
|
|
|
|
**main.ts bootstraps:**
|
|
- Global validation pipe (whitelist + transform)
|
|
- Security headers (Helmet)
|
|
- CORS configuration (environment-based)
|
|
- CSRF protection (double-submit cookies)
|
|
- Cookie parser
|
|
- Request logging
|
|
- Graceful shutdown hooks
|
|
- Swagger documentation
|
|
|
|
### API Versioning
|
|
- **Global Prefix:** `/api/v1/`
|
|
- **Health Endpoint:** `/health` (excluded from versioning)
|
|
- **Swagger Docs:** `/api/v1/docs`
|
|
|
|
### Testing Coverage
|
|
|
|
**Backend Tests:**
|
|
- **Unit Tests:** 229 .spec.ts files
|
|
- **Total Test LOC:** 23,886 lines
|
|
- **Test Framework:** Vitest
|
|
- **Integration Tests:** Separate vitest config
|
|
- **E2E Tests:** 16 API endpoint test suites
|
|
|
|
---
|
|
|
|
## 3. FRONTEND (apps/web)
|
|
|
|
### Technology Stack
|
|
- **Framework:** Next.js 15.5.14 (App Router)
|
|
- **Language:** TypeScript 6.0.2 (strict)
|
|
- **UI Framework:** React 18.3.0
|
|
- **Styling:** Tailwind CSS 3.4.0
|
|
- **State Management:** Zustand 5.0.12
|
|
- **Data Fetching:** React Query 5.96.2
|
|
- **Forms:** React Hook Form 7.72.1 + Zod validation
|
|
- **Internationalization:** next-intl 4.9.0
|
|
- **Maps:** Mapbox GL 3.21.0
|
|
|
|
### Page Routes (33 pages + 8 layouts)
|
|
|
|
**Auth Routes:**
|
|
- `/[locale]/(auth)/login` - User login
|
|
- `/[locale]/(auth)/register` - User registration
|
|
- `/[locale]/auth/callback/google` - OAuth callback
|
|
- `/[locale]/auth/callback/zalo` - OAuth callback
|
|
|
|
**Public Routes:**
|
|
- `/[locale]/(public)` - Landing page
|
|
- `/[locale]/(public)/pricing` - Pricing page
|
|
- `/[locale]/(public)/search` - Property search
|
|
- `/[locale]/(public)/compare` - Property comparison
|
|
- `/[locale]/(public)/listings/[id]` - Listing detail
|
|
- `/[locale]/(public)/agents/[id]` - Agent profile
|
|
|
|
**Dashboard Routes (Authenticated):**
|
|
- `/[locale]/(dashboard)/dashboard` - Main dashboard
|
|
- `/[locale]/(dashboard)/dashboard/profile` - User profile
|
|
- `/[locale]/(dashboard)/dashboard/kyc` - KYC verification
|
|
- `/[locale]/(dashboard)/dashboard/subscription` - Subscription mgmt
|
|
- `/[locale]/(dashboard)/dashboard/payments` - Payment history
|
|
- `/[locale]/(dashboard)/dashboard/saved-searches` - Saved searches
|
|
- `/[locale]/(dashboard)/dashboard/valuation` - Property valuation
|
|
|
|
**Listings Routes:**
|
|
- `/[locale]/(dashboard)/listings` - My listings
|
|
- `/[locale]/(dashboard)/listings/new` - Create listing
|
|
- `/[locale]/(dashboard)/listings/[id]/edit` - Edit listing
|
|
|
|
**Agent Routes:**
|
|
- `/[locale]/(dashboard)/leads` - Lead management
|
|
- `/[locale]/(dashboard)/inquiries` - Inquiry management
|
|
- `/[locale]/(dashboard)/analytics` - Analytics dashboard
|
|
|
|
**Admin Routes:**
|
|
- `/[locale]/(admin)/admin` - Admin dashboard
|
|
- `/[locale]/(admin)/admin/users` - User management
|
|
- `/[locale]/(admin)/admin/kyc` - KYC queue
|
|
- `/[locale]/(admin)/admin/moderation` - Content moderation
|
|
|
|
### Component Structure (68 components)
|
|
|
|
**By Domain:**
|
|
| Category | Count | Purpose |
|
|
|----------|-------|---------|
|
|
| **UI Components** | 21 | Design system (buttons, forms, modals, etc.) |
|
|
| **Listings** | 7 | Listing cards, filters, forms |
|
|
| **Comparison** | 7 | Compare properties UI |
|
|
| **Valuation** | 6 | Valuation calculator UI |
|
|
| **Search** | 4 | Search filters, results |
|
|
| **Charts** | 4 | Analytics visualizations |
|
|
| **Inquiries** | 3 | Inquiry forms & lists |
|
|
| **Auth** | 2 | Login/register forms |
|
|
| **Leads** | 4 | Lead management UI |
|
|
| **Providers** | 4 | Auth, Query, Theme providers |
|
|
| **Map** | 1 | Mapbox integration |
|
|
| **Agents** | 1 | Agent display |
|
|
| **SEO** | 2 | Meta tags & OG |
|
|
|
|
### State Management
|
|
|
|
**Zustand Stores:**
|
|
- `auth-store.ts` - User authentication state (3.3 KB)
|
|
- `comparison-store.ts` - Property comparison state (3.9 KB)
|
|
|
|
**API Layers (lib/*.ts):**
|
|
- `admin-api.ts` - Admin operations
|
|
- `agents-api.ts` - Agent data
|
|
- `analytics-api.ts` - Analytics queries
|
|
- `auth-api.ts` - Auth endpoints
|
|
- `payment-api.ts` - Payment operations
|
|
- `subscription-api.ts` - Subscription mgmt
|
|
- `listings-api.ts` - Listing CRUD
|
|
- `leads-api.ts` - Lead management
|
|
- `inquiries-api.ts` - Inquiry management
|
|
- `valuation-api.ts` - Valuation queries
|
|
- `saved-search-api.ts` - Saved searches
|
|
- `comparison-api.ts` - Comparison data
|
|
|
|
### Providers & Integration
|
|
|
|
**Custom Providers:**
|
|
- `auth-provider.tsx` - Session management
|
|
- `theme-provider.tsx` - Dark mode (if enabled)
|
|
- `query-provider.tsx` - React Query setup
|
|
|
|
### Testing Coverage
|
|
|
|
**Frontend Tests:**
|
|
- **Component Tests:** 45 .spec.tsx files
|
|
- **Total Test LOC:** 3,864 lines
|
|
- **Test Framework:** Vitest + React Testing Library
|
|
- **E2E Tests:** 15 Playwright test suites
|
|
|
|
---
|
|
|
|
## 4. DATABASE
|
|
|
|
### Schema Overview
|
|
|
|
**21 Models in Prisma schema.prisma (641 lines):**
|
|
|
|
**Auth & Users:**
|
|
- User (roles: BUYER, SELLER, AGENT, ADMIN)
|
|
- RefreshToken
|
|
- OAuthAccount (providers: GOOGLE, ZALO)
|
|
- Agent
|
|
|
|
**Listings & Properties:**
|
|
- Property (geo-indexed with PostGIS)
|
|
- PropertyMedia (images/media)
|
|
- Listing (property listings with status tracking)
|
|
- SavedSearch (user saved searches)
|
|
|
|
**Transactions & Inquiries:**
|
|
- Transaction (buyer-seller transactions)
|
|
- Inquiry (property inquiries)
|
|
- Lead (agent leads)
|
|
|
|
**Payments & Subscriptions:**
|
|
- Payment (payment records with VNPay integration)
|
|
- Plan (subscription plans)
|
|
- Subscription (active subscriptions)
|
|
- UsageRecord (metering usage)
|
|
|
|
**Analytics:**
|
|
- Valuation (property valuations)
|
|
- MarketIndex (market analytics data)
|
|
|
|
**Logging & Compliance:**
|
|
- NotificationLog (notification history)
|
|
- NotificationPreference (user notification settings)
|
|
- AdminAuditLog (admin action audit trail)
|
|
|
|
**Reviews:**
|
|
- Review (property reviews & ratings)
|
|
|
|
### Key Database Features
|
|
|
|
- **PostGIS Integration:** Geospatial queries (property location)
|
|
- **Indexes:** 30+ query optimization indexes
|
|
- **Compound Indexes:** Optimized for common query patterns
|
|
- **Cascade Delete:** Proper referential integrity
|
|
- **Soft Deletes:** User.deletedAt, User.deletionScheduledAt
|
|
- **Timestamps:** createdAt, updatedAt on all entities
|
|
|
|
### Migrations
|
|
|
|
**13 migrations deployed (from April 7 - April 11):**
|
|
1. Initial schema (`20260407165528_init`)
|
|
2. Foreign key indexes (`20260407210149_add_missing_fk_indexes`)
|
|
3. Payment idempotency (`20260408000000_add_idempotency_key_to_payment`)
|
|
4. Schema integrity fixes (`20260408061200_fix_schema_integrity`)
|
|
5. Analytics/media quotas (`20260408080000_add_analytics_media_quota_fields`)
|
|
6. Review indexing (`20260408160000_add_review_userid_index`)
|
|
7. Notification read status (`20260409000000_add_notification_read_at`)
|
|
8. Compound indexes (`20260409100000_add_compound_indexes_query_optimization`)
|
|
9. Query optimizations (`20260409120000_add_missing_query_indexes`)
|
|
10. Soft deletes (`20260410000000_add_user_soft_delete_fields`)
|
|
11. Admin audit log (`20260410100000_add_admin_audit_log`)
|
|
12. Cascade deletes (`20260411000000_add_cascade_delete_strategies`)
|
|
13. PII encryption (`20260411100000_add_pii_encryption_hash_columns`)
|
|
|
|
### Database Seeding
|
|
|
|
- Custom seed script at `prisma/seed.ts`
|
|
- Seeding command: `pnpm db:seed`
|
|
- Supports test data generation
|
|
|
|
---
|
|
|
|
## 5. INFRASTRUCTURE & DEPLOYMENT
|
|
|
|
### Docker Compose Services
|
|
|
|
**Development Stack (docker-compose.yml):**
|
|
- PostgreSQL 16 + PostGIS
|
|
- Redis 7
|
|
- Typesense 27.1 (full-text search)
|
|
- MinIO (S3-compatible storage)
|
|
- PgBouncer (connection pooling)
|
|
|
|
**Production Stack (docker-compose.prod.yml):**
|
|
- Orchestrated containers
|
|
- Persistent volumes
|
|
- Health checks
|
|
- Network isolation
|
|
|
|
**CI Stack (docker-compose.ci.yml):**
|
|
- Test environment
|
|
|
|
### Monitoring Stack (monitoring/)
|
|
|
|
- **Prometheus** - Metrics collection
|
|
- **Grafana** - Dashboard visualization
|
|
- **Loki** - Log aggregation
|
|
- **Promtail** - Log shipper
|
|
- **AlertManager** - Alert routing
|
|
|
|
### CI/CD Pipelines (.github/workflows)
|
|
|
|
**ci.yml** (Primary Pipeline)
|
|
- Runs on: push to master, PRs
|
|
- Services: PostgreSQL, Redis, Typesense, MinIO
|
|
- Steps:
|
|
1. Lint (ESLint)
|
|
2. Type check (tsc)
|
|
3. Unit tests (pnpm test)
|
|
4. Build (pnpm build)
|
|
- Node version: 22
|
|
|
|
**e2e.yml** (E2E Testing)
|
|
- Depends on: CI passing
|
|
- Services: PostgreSQL, Redis, Typesense, MinIO
|
|
- Browser: Chromium (Playwright)
|
|
- Generates artifact reports
|
|
|
|
**deploy.yml** (Deployment)
|
|
- Conditional deployment based on branch
|
|
- Docker image building & pushing
|
|
- Kubernetes deployment
|
|
- Status notifications
|
|
|
|
**security.yml** (Security Scanning)
|
|
- CodeQL analysis
|
|
- Dependency scanning
|
|
- SAST
|
|
|
|
**load-test.yml** (Performance)
|
|
- Load testing pipeline
|
|
- Performance benchmarking
|
|
|
|
**backup-verify.yml** (Data Protection)
|
|
- Database backup verification
|
|
- Recovery testing
|
|
|
|
---
|
|
|
|
## 6. CODE QUALITY & STANDARDS
|
|
|
|
### TypeScript Configuration
|
|
|
|
**tsconfig.base.json:**
|
|
```
|
|
- Strict mode: ENABLED ✓
|
|
- Target: ES2022
|
|
- Module Resolution: NodeNext
|
|
- Key strict flags:
|
|
- noUncheckedIndexedAccess: true
|
|
- noImplicitOverride: true
|
|
- noPropertyAccessFromIndexSignature: true
|
|
- declaration: true (emit .d.ts)
|
|
- sourceMap: true
|
|
```
|
|
|
|
### ESLint Configuration
|
|
|
|
**eslint.config.mjs:**
|
|
- **Framework:** ESLint 9 with TypeScript support
|
|
- **Import Plugin:** Import ordering with module encapsulation rules
|
|
- **Prettier Integration:** Conflict-free formatting
|
|
|
|
**Rules:**
|
|
- Unused variables: Error (allow leading _)
|
|
- Explicit any: Warn
|
|
- Consistent type imports: Error (inline-type-imports)
|
|
- No console in web app: Error
|
|
- No cross-module internal imports: Error (except tests)
|
|
- Module encapsulation: Enforced (can only import from barrel exports)
|
|
|
|
### Prettier Configuration
|
|
|
|
```
|
|
- Single quotes: true
|
|
- Trailing comma: all
|
|
- Tab width: 2
|
|
- Semi-colons: true
|
|
- Line width: 100
|
|
- Arrow parens: always
|
|
```
|
|
|
|
### Code Cleanliness
|
|
|
|
- **TODO/FIXME/HACK Comments:** 0 found
|
|
- **No Technical Debt Markers:** Clean codebase
|
|
- **Consistent Naming:** Pascal case (Classes), camelCase (functions)
|
|
- **Module Barrel Exports:** Enforced via ESLint
|
|
|
|
---
|
|
|
|
## 7. TESTING FRAMEWORK
|
|
|
|
### Unit Testing
|
|
|
|
**Backend:**
|
|
- Framework: Vitest 4.1.3
|
|
- Format: .spec.ts files co-located with source
|
|
- Coverage: 229 spec files
|
|
- Setup: Supertest for HTTP testing
|
|
|
|
**Frontend:**
|
|
- Framework: Vitest 4.1.3
|
|
- Format: .spec.tsx files in __tests__ directories
|
|
- Coverage: 45 spec files
|
|
- Setup: React Testing Library + jsdom
|
|
|
|
### Integration Testing
|
|
|
|
**Backend:**
|
|
- Separate config: `vitest.integration.config.ts`
|
|
- Command: `pnpm test:integration`
|
|
- Uses test database
|
|
|
|
### E2E Testing
|
|
|
|
**Tool:** Playwright 1.59.1
|
|
- **Web Tests:** 15 test files
|
|
- **API Tests:** 16 test files
|
|
- **Fixtures:** Shared test fixtures
|
|
- **Global Setup:** Database seeding
|
|
- **Global Teardown:** Cleanup
|
|
- **Browser:** Chromium
|
|
- **Reports:** HTML + trace artifacts
|
|
|
|
**E2E Coverage:**
|
|
- Auth (login, register, OAuth)
|
|
- Listings (CRUD, media, moderation)
|
|
- Search & filtering
|
|
- Payments & callbacks
|
|
- Subscriptions
|
|
- Admin operations
|
|
- Responsiveness
|
|
- Navigation flows
|
|
|
|
---
|
|
|
|
## 8. LIBRARIES & DEPENDENCIES
|
|
|
|
### Backend Key Dependencies
|
|
|
|
**Framework & Core:**
|
|
- @nestjs/common@11.0.0
|
|
- @nestjs/core@11.0.0
|
|
- @nestjs/cqrs@11.0.0
|
|
- reflect-metadata@0.2.0
|
|
- rxjs@7.8.0
|
|
|
|
**Database:**
|
|
- @prisma/client@7.7.0
|
|
- @prisma/adapter-pg@7.7.0
|
|
- pg@8.20.0
|
|
|
|
**API & Documentation:**
|
|
- @nestjs/swagger@11.2.7
|
|
- swagger-ui-express@5.0.1
|
|
|
|
**Authentication:**
|
|
- passport@0.7.0
|
|
- passport-jwt@4.0.1
|
|
- passport-google-oauth20@2.0.0
|
|
- @nestjs/jwt@11.0.2
|
|
- bcrypt@6.0.0
|
|
|
|
**Caching & Background Jobs:**
|
|
- ioredis@5.4.0
|
|
- @nestjs/schedule@6.1.1
|
|
- @nestjs/event-emitter@3.0.0
|
|
|
|
**Search:**
|
|
- typesense@3.0.5
|
|
|
|
**Storage:**
|
|
- @aws-sdk/client-s3@3.1026.0
|
|
- @aws-sdk/s3-request-presigner@3.1026.0
|
|
|
|
**Validation:**
|
|
- class-validator@0.15.1
|
|
- class-transformer@0.5.1
|
|
|
|
**Security:**
|
|
- helmet@8.1.0
|
|
- sanitize-html@2.17.2
|
|
- cookie-parser@1.4.7
|
|
|
|
**Monitoring & Logging:**
|
|
- @sentry/nestjs@10.47.0
|
|
- @sentry/profiling-node@10.47.0
|
|
- pino@10.3.1
|
|
- pino-pretty@13.0.0
|
|
- @willsoto/nestjs-prometheus@6.1.0
|
|
- prom-client@15.1.3
|
|
|
|
**Email:**
|
|
- nodemailer@8.0.5
|
|
- handlebars@4.7.9
|
|
|
|
**Cloud:**
|
|
- firebase-admin@13.7.0
|
|
|
|
### Frontend Key Dependencies
|
|
|
|
**Core:**
|
|
- react@18.3.0
|
|
- react-dom@18.3.0
|
|
- next@15.5.14
|
|
|
|
**State Management:**
|
|
- zustand@5.0.12
|
|
- @tanstack/react-query@5.96.2
|
|
|
|
**Forms:**
|
|
- react-hook-form@7.72.1
|
|
- @hookform/resolvers@5.2.2
|
|
- zod@4.3.6
|
|
|
|
**UI & Styling:**
|
|
- tailwindcss@3.4.0
|
|
- tailwind-merge@3.5.0
|
|
- class-variance-authority@0.7.1
|
|
- clsx@2.1.1
|
|
- lucide-react@1.7.0
|
|
|
|
**Internationalization:**
|
|
- next-intl@4.9.0
|
|
|
|
**Maps:**
|
|
- mapbox-gl@3.21.0
|
|
|
|
**Charts:**
|
|
- recharts@3.8.1
|
|
|
|
**Monitoring:**
|
|
- @sentry/nextjs@10.47.0
|
|
|
|
**Performance:**
|
|
- web-vitals@5.2.0
|
|
|
|
---
|
|
|
|
## 9. INFRASTRUCTURE PATTERNS
|
|
|
|
### Shared Module Architecture
|
|
|
|
**Domain Utilities:**
|
|
- Constants, enums, types
|
|
- Decorators (auth, cache, idempotency)
|
|
|
|
**Infrastructure Services:**
|
|
- Database access (PrismaService)
|
|
- Caching (CacheService, RedisService)
|
|
- Encryption (FieldEncryptionService)
|
|
- Logging (LoggerService)
|
|
- Circuit breaker (fault tolerance)
|
|
- PII masking
|
|
- Event bus
|
|
|
|
**Middleware:**
|
|
- CSRF protection
|
|
- Input sanitization
|
|
- Encryption middleware
|
|
|
|
**Guards:**
|
|
- JWT authentication
|
|
- Role-based access control (RBAC)
|
|
- Throttler behind proxy
|
|
|
|
**Filters:**
|
|
- Global exception handling
|
|
- Sentry integration
|
|
|
|
**Pipes:**
|
|
- Validation pipes
|
|
|
|
### Authentication & Authorization
|
|
|
|
**Supported Methods:**
|
|
- JWT (Bearer tokens)
|
|
- Local (email/password)
|
|
- OAuth 2.0 (Google, Zalo)
|
|
|
|
**Token Management:**
|
|
- Access token (15 minutes)
|
|
- Refresh token (7 days)
|
|
- Token families (refresh token rotation)
|
|
- Revocation tracking
|
|
|
|
**Authorization:**
|
|
- Role-based access control (BUYER, SELLER, AGENT, ADMIN)
|
|
- Guard decorators
|
|
- Endpoint-level restrictions
|
|
|
|
### External Integrations
|
|
|
|
- **Payment Gateway:** VNPay (Vietnam)
|
|
- **Search Engine:** Typesense (full-text, geo-search)
|
|
- **Object Storage:** MinIO / AWS S3
|
|
- **Email:** Nodemailer + Handlebars
|
|
- **Push Notifications:** Firebase Cloud Messaging
|
|
- **OAuth Providers:** Google, Zalo
|
|
- **Monitoring:** Sentry, Prometheus, Grafana, Loki
|
|
|
|
---
|
|
|
|
## 10. SECURITY POSTURE
|
|
|
|
### Built-in Security Features
|
|
|
|
✓ **Helmet** - Security headers (CSP, X-Frame-Options, HSTS, etc.)
|
|
✓ **CORS** - Environment-based whitelist
|
|
✓ **CSRF** - Double-submit cookie pattern
|
|
✓ **Rate Limiting** - Per-route throttling
|
|
✓ **Input Sanitization** - XSS prevention
|
|
✓ **SQL Injection** - Parameterized queries (Prisma)
|
|
✓ **Field Encryption** - PII fields encrypted at rest
|
|
✓ **Hash Fields** - Email/phone hashed for lookups
|
|
✓ **Soft Deletes** - GDPR-compliant retention
|
|
✓ **Audit Logging** - Admin action tracking
|
|
✓ **Circuit Breaker** - Fail-safe external calls
|
|
✓ **Password Hashing** - bcrypt (6 rounds)
|
|
✓ **JWT Signing** - HS256 (configurable)
|
|
|
|
### Security Scanning
|
|
|
|
- CodeQL (GitHub Actions)
|
|
- Dependency vulnerability scanning
|
|
- SAST analysis
|
|
|
|
---
|
|
|
|
## 11. PERFORMANCE & SCALABILITY
|
|
|
|
### Caching Strategy
|
|
|
|
- **Redis:** Session cache, rate limit counters, data caching
|
|
- **Application-level:** Field encryption key caching
|
|
- **Query-level:** Prisma query caching
|
|
|
|
### Database Optimization
|
|
|
|
- **Connection Pooling:** PgBouncer (20 pool size, 200 max clients)
|
|
- **Indexes:** 30+ including compound indexes
|
|
- **Query Planning:** Optimized for common patterns
|
|
- **PostGIS:** Geo-spatial indexing for location queries
|
|
|
|
### Search Optimization
|
|
|
|
- **Typesense:** Full-text search engine
|
|
- **Geo-search:** Mapbox GL integration
|
|
- **Filtering:** Faceted search support
|
|
|
|
### Load Balancing
|
|
|
|
- **Behind Proxy:** Trust proxy configuration
|
|
- **Rate Limiting:** Per-endpoint throttling
|
|
- **Circuit Breaker:** Graceful degradation
|
|
|
|
---
|
|
|
|
## 12. TESTING METRICS SUMMARY
|
|
|
|
### Code Coverage by Layer
|
|
|
|
| Aspect | Backend | Frontend |
|
|
|--------|---------|----------|
|
|
| Unit Tests | 229 files | 45 files |
|
|
| Test LOC | 23,886 | 3,864 |
|
|
| E2E Tests | 16 suites | 15 suites |
|
|
| **Total Tests** | **~261** | **~60** |
|
|
|
|
### Test Execution
|
|
|
|
- **Local:** `pnpm test`
|
|
- **Integration:** `pnpm test:integration`
|
|
- **E2E:** `pnpm test:e2e`
|
|
- **Reports:** `pnpm test:e2e:report`
|
|
|
|
---
|
|
|
|
## 13. DEVELOPMENT WORKFLOW
|
|
|
|
### Scripts Available
|
|
|
|
**Development:**
|
|
```bash
|
|
pnpm dev # Start all apps in dev mode
|
|
pnpm dev:api # API only
|
|
pnpm dev:web # Web only
|
|
```
|
|
|
|
**Building:**
|
|
```bash
|
|
pnpm build # Build all apps
|
|
pnpm build:api # API only
|
|
pnpm build:web # Web only
|
|
```
|
|
|
|
**Testing:**
|
|
```bash
|
|
pnpm test # All unit tests
|
|
pnpm test:integration # Integration tests
|
|
pnpm test:e2e # E2E tests
|
|
pnpm test:e2e:report # View report
|
|
```
|
|
|
|
**Code Quality:**
|
|
```bash
|
|
pnpm lint # ESLint
|
|
pnpm format # Prettier
|
|
pnpm format:check # Prettier check
|
|
pnpm typecheck # TypeScript check
|
|
pnpm dep-cruise # Dependency analysis
|
|
```
|
|
|
|
**Database:**
|
|
```bash
|
|
pnpm db:generate # Generate Prisma client
|
|
pnpm db:migrate:dev # Dev migrations
|
|
pnpm db:migrate:deploy # Production migrations
|
|
pnpm db:seed # Seed database
|
|
pnpm db:push # Sync to DB
|
|
pnpm db:reset # Full reset
|
|
pnpm db:studio # Prisma Studio UI
|
|
```
|
|
|
|
### Git Hooks
|
|
|
|
- **Husky:** Pre-commit hooks
|
|
- **Lint-staged:** Run linters on staged files
|
|
- **Pre-push:** Type checking & build validation
|
|
|
|
---
|
|
|
|
## 14. DOCUMENTATION & CONVENTIONS
|
|
|
|
### Documentation Available
|
|
|
|
- `CLAUDE.md` - AI integration guidelines
|
|
- `CONTRIBUTING.md` - Contributing guidelines
|
|
- `.env.example` - Environment setup template
|
|
- Swagger API docs at `/api/v1/docs`
|
|
|
|
### Naming Conventions
|
|
|
|
**TypeScript/Files:**
|
|
- Classes: PascalCase (UserService, ListingRepository)
|
|
- Functions: camelCase (createUser, getListings)
|
|
- Files: kebab-case (user.service.ts, create-user.command.ts)
|
|
- Directories: kebab-case (src/modules/auth)
|
|
|
|
**Database:**
|
|
- Tables: PascalCase (User, Listing, Payment)
|
|
- Columns: camelCase (firstName, phoneHash)
|
|
- Indexes: Explicit naming (e.g., idx_user_role_active)
|
|
|
|
---
|
|
|
|
## 15. PYTHON AI SERVICES (libs/ai-services)
|
|
|
|
### Structure
|
|
|
|
- **Framework:** FastAPI
|
|
- **Language:** Python
|
|
- **Location:** `/libs/ai-services/`
|
|
- **Tests:** pytest in `tests/` directory
|
|
- **Docker:** Containerized
|
|
|
|
### Capabilities
|
|
|
|
- Property valuation/analysis
|
|
- Market analytics
|
|
- AI-powered property search enhancement
|
|
|
|
---
|
|
|
|
## AUDIT FINDINGS - EXECUTIVE SUMMARY
|
|
|
|
### ✓ STRENGTHS
|
|
|
|
1. **Well-Structured Architecture**
|
|
- Hexagonal architecture consistently applied
|
|
- Clear separation of concerns (domain/application/infrastructure/presentation)
|
|
- Module encapsulation enforced via ESLint
|
|
|
|
2. **Enterprise-Grade Security**
|
|
- Multiple security layers (CSRF, CSP, rate limiting, input sanitization)
|
|
- Field-level encryption for PII
|
|
- Audit logging for compliance
|
|
- SAST/CodeQL scanning in CI/CD
|
|
|
|
3. **Comprehensive Testing**
|
|
- 229 backend unit tests (23,886 LOC)
|
|
- 45 frontend component tests (3,864 LOC)
|
|
- 31 E2E test suites (API + Web)
|
|
- Integration test support
|
|
|
|
4. **Modern Tech Stack**
|
|
- NestJS 11 with CQRS pattern
|
|
- Next.js 15 App Router
|
|
- Prisma ORM with PostGIS
|
|
- Typesense for search
|
|
- Zustand for state management
|
|
|
|
5. **DevOps & Monitoring**
|
|
- Multi-environment Docker support
|
|
- Full monitoring stack (Prometheus, Grafana, Loki)
|
|
- CI/CD pipelines with security scanning
|
|
- Load testing capability
|
|
|
|
6. **Code Quality**
|
|
- Strict TypeScript mode
|
|
- ESLint + Prettier enforced
|
|
- Zero TODO/FIXME/HACK comments
|
|
- Dependency cruiser analysis
|
|
|
|
### ⚠ OBSERVATIONS
|
|
|
|
1. **Database**
|
|
- 13 migrations in 4 days indicates schema instability during development
|
|
- Consider data migration strategy for production
|
|
|
|
2. **Testing Coverage**
|
|
- 70,569 LOC with 229+45 test files (~0.4% test file ratio)
|
|
- E2E tests cover happy paths, edge cases may need expansion
|
|
- Consider adding mutation testing
|
|
|
|
3. **Documentation**
|
|
- README limited
|
|
- Module-level documentation could be expanded
|
|
- API examples could be added to docs
|
|
|
|
4. **Monitoring**
|
|
- Monitoring stack deployed but alert rules need verification
|
|
- SLO targets not explicitly documented
|
|
|
|
5. **Authentication**
|
|
- OAuth providers (Google, Zalo) configured but token refresh logic could use additional validation
|
|
- Consider adding 2FA support for admin accounts
|
|
|
|
### RECOMMENDATIONS
|
|
|
|
1. **Pre-Production Checklist**
|
|
- Database schema finalization (halt new migrations)
|
|
- Load testing at scale
|
|
- Disaster recovery drill
|
|
- Security penetration testing
|
|
|
|
2. **Performance Tuning**
|
|
- Cache warm-up strategy
|
|
- Database query analysis (slow log)
|
|
- Frontend bundle analysis
|
|
|
|
3. **Operational Readiness**
|
|
- Runbook creation
|
|
- On-call rotation documentation
|
|
- Incident response procedures
|
|
- Log retention policies
|
|
|
|
4. **Compliance**
|
|
- GDPR compliance verification (soft deletes, data export)
|
|
- Data retention policy implementation
|
|
- Terms of service / Privacy policy
|
|
|
|
---
|
|
|
|
## DEPLOYMENT STATUS
|
|
|
|
**Current State:** Development/Staging
|
|
**Docker Compose:** ✓ Fully configured
|
|
**CI/CD:** ✓ GitHub Actions pipelines ready
|
|
**Database:** ✓ 13 migrations deployed
|
|
**Monitoring:** ✓ Full stack available
|
|
**Security Scanning:** ✓ CodeQL + dependency checks
|
|
|
|
**Ready for Production:** Pending final security audit & load testing
|
|
|
|
---
|
|
|
|
**Report Generated:** April 11, 2026
|
|
**Auditor:** Claude Code
|
|
**Scope:** Complete codebase analysis
|