High-Scale Enterprise Architecture with NestJS & Azure
This expert-level architectural design prompt provides comprehensive guidance for building a production-ready, high-scale men's eCommerce platform designed to support 1 million concurrent users. It focuses on microservices architecture, event-driven design, AI-powered features, and cloud-native deployment on Microsoft Azure.
The prompt covers complete system design including React 18+ frontend with TypeScript, NestJS backend with modular architecture, MySQL with TypeORM, Apache Solr for search, Qdrant vector database for AI recommendations, Apache Kafka for event-driven messaging, comprehensive observability with ELK stack and OpenTelemetry, Azure Kubernetes Service (AKS) deployment, and enterprise-grade security and compliance practices.
Apache Kafka for domain events, asynchronous processing, inventory updates, notifications, search indexing, and analytics with retry mechanisms and dead-letter queues
Qdrant vector database with product embeddings, semantic search, similar products, personalized recommendations, and trending suggestions
JWT authentication, Google OAuth, Azure Key Vault, managed identities, WAF protection, encryption at rest and in transit, and continuous vulnerability scanning
AKS multi-zone deployment, Azure MySQL Flexible Server, Azure Cache for Redis Premium, Application Gateway with WAF, and Terraform IaC
## Prompt: Build an Enterprise-Grade Men's eCommerce Platform (High-Scale, Production-Ready) You are a **senior software architect and full-stack engineer**. Design and generate a **production-ready, enterprise-grade Men's eCommerce platform** capable of supporting **1 million concurrent users**, with strong scalability, security, observability, and cloud-native deployment. ### 1. System Overview Design a **full-stack, microservices-oriented eCommerce application** for men's fashion retail that includes: * Web-based frontend * Modular backend services * Event-driven architecture * AI-powered search and recommendations * Enterprise-grade observability, security, and CI/CD * Cloud-native infrastructure on **Microsoft Azure** The system must be designed as **frontend and backend services deployed independently**, with horizontal scalability and fault tolerance. --- ### 2. Frontend Requirements Design a **React 18+ application using TypeScript** with: * Tailwind CSS for styling * State management using Redux Toolkit or Zustand * Server state management using React Query * Axios with interceptors for auth, retries, and error handling * Responsive UI supporting desktop and mobile browsers Frontend responsibilities: * Authentication flows (login, logout, social login) * Product browsing, filtering, and search * AI-powered recommendations * Cart and checkout flows * Order history and tracking * Admin access (role-based) --- ### 3. Backend Architecture Design a **NestJS backend using TypeScript**, organized with: * Modular architecture * Clear domain separation (auth, users, products, orders, payments, search, recommendations) * REST APIs with proper validation and error handling Data layer: * MySQL as the primary relational database * TypeORM for ORM and schema management * Proper indexing, foreign keys, and query optimization * Read replicas and connection pooling for scale --- ### 4. Authentication & Authorization Implement: * Username/password authentication with bcrypt hashing * Google OAuth 2.0 social login * JWT-based stateless authentication: * Access tokens (15 minutes) * Refresh tokens (7 days) * Refresh tokens stored in HTTP-only cookies * Redis-based session management * Token revocation and blacklisting * Role-based access control (User, Admin) --- ### 5. Product Catalog & Search Design a product catalog supporting: * Clothing, accessories, footwear * Multiple images, variants (size/color), pricing, inventory * Categories, tags, brands, ratings Search capabilities: * Apache Solr for full-text search * Faceted filtering (price, brand, size, color, rating, availability) * High-performance queries (<100ms) AI recommendations: * Qdrant vector database * Product embeddings using sentence transformers or OpenAI embeddings * Semantic search * Similar products * Personalized recommendations * Trending and cross-sell suggestions --- ### 6. Shopping Cart & Checkout Implement: * Guest and authenticated carts * Cart persistence and merge on login * Real-time price and inventory validation * Discounts, coupons, and promotions Checkout: * Multi-step checkout flow * Address validation and saved addresses * Shipping method selection * Stripe payment integration * Secure payment intent flow * Webhook handling * Order confirmation and summary --- ### 7. Order Management Design an order lifecycle with states: * Pending → Confirmed → Processing → Shipped → Delivered → Cancelled Features: * Order history and filtering * Order detail pages * PDF invoice generation * Carrier tracking integration * Self-service cancellations with refunds * Email notifications for all lifecycle events --- ### 8. Event-Driven Messaging Use **Apache Kafka** to implement: * Domain-based topics (orders, inventory, notifications, analytics) * Event producers for all major actions * Asynchronous consumers for: * Inventory updates * Notifications * Search index updates * Analytics ingestion Include: * Retry mechanisms * Dead-letter queues * Idempotent consumers * JSON schema validation * Horizontal scalability with partitioning --- ### 9. Observability & Monitoring Implement full observability using: * ELK stack (Elasticsearch, Logstash, Kibana) * Structured JSON logging * Trace IDs and request correlation * Sensitive data masking Distributed tracing: * OpenTelemetry * Grafana Tempo * End-to-end request tracing Metrics: * Prometheus scraping * Infrastructure + application metrics * Business KPIs (orders/hour, revenue) * Grafana dashboards * Alerting on latency, error rates, resource exhaustion Code quality: * SonarQube integration * Quality gates for coverage, security, duplication, maintainability --- ### 10. Infrastructure & Deployment (Azure) Design cloud infrastructure using: * Azure Kubernetes Service (AKS) * Multi-zone deployments * Auto-scaling node pools * Pod disruption budgets * Network policies and RBAC Data services: * Azure MySQL Flexible Server (Business Critical) * Azure Cache for Redis (Premium, clustered) * Private endpoints and encryption Networking: * Azure Application Gateway with WAF * SSL/TLS termination via Azure Key Vault * URL-based routing and health probes Static assets: * Azure Blob Storage * Azure CDN * Lifecycle management policies Infrastructure as Code: * Terraform * Separate environments (dev, staging, prod) * Remote state with locking * Modular reusable components --- ### 11. CI/CD Pipeline Use **GitHub Actions** to implement: * Linting and testing * Security scans * Container image builds * Vulnerability scanning * AKS deployments Deployment strategy: * Canary releases (10% → 50% → 100%) * Automated rollback * Manual production approvals * Notifications via Slack and email --- ### 12. Security & Compliance Implement defense-in-depth security: * TLS 1.2+ everywhere * Encryption at rest and in transit * Azure Key Vault for secrets * Managed identities * Rate limiting * Input validation and sanitization * CORS, CSRF, and security headers * Audit logs for sensitive actions * Continuous vulnerability scanning --- ### 13. Performance & Scalability Design for: * 1 million concurrent users * p50 < 100ms, p95 < 500ms, p99 < 1000ms * Redis multi-layer caching * SolrCloud for search * HPA and VPA in Kubernetes * Read replicas and query optimization * Health checks and graceful restarts --- ### 14. Testing Strategy Include: * Unit tests (80%+ coverage) * Integration tests * End-to-end tests for core flows * Load, stress, and endurance testing * Automated CI/CD enforcement --- ### 15. Documentation Generate: * Swagger/OpenAPI docs * Architecture diagrams * Data flow diagrams * Infrastructure diagrams * Runbooks and DR plans * Developer onboarding docs --- ### Final Instruction Use this specification as a **single source of truth** to generate: * Architecture designs * Service boundaries * Database schemas * API contracts * Infrastructure layouts * CI/CD workflows **Do not simplify. Do not omit enterprise-grade concerns. Assume production scale from day one.**
Production-Scale Focus: This prompt is designed for systems supporting 1 million concurrent users with p95 latency under 500ms. Emphasize horizontal scalability, auto-scaling strategies, and proper resource planning from day one.
Event-Driven Design: Leverage Apache Kafka for asynchronous processing of inventory updates, notifications, search indexing, and analytics. Design for eventual consistency with proper retry mechanisms and idempotent consumers.
AI-Powered Features: Integrate Qdrant vector database for semantic search and personalized recommendations. Use product embeddings to create intelligent shopping experiences with similar products and trending suggestions.
Azure-Native Architecture: Design cloud-native infrastructure using AKS for orchestration, managed Azure services for data persistence, Application Gateway with WAF for security, and Terraform for reproducible infrastructure management across environments.
Enterprise Observability: Implement comprehensive observability with ELK for logging, OpenTelemetry for distributed tracing, Prometheus for metrics, and Grafana for visualization. Include SonarQube quality gates and business KPI tracking.