System Architecture
This document provides an overview of the SBM CRM Platform architecture, system components, and design patterns.
Architecture Overview
The SBM CRM Platform is built on a microservices architecture, enabling scalability, maintainability, and independent deployment of services.
System Components
Frontend Applications
- WeChat Mini Program - Customer-facing mobile application
- Admin Web App - Administrative dashboard and management interface
- PWA (Progressive Web App) - Cross-platform web application for booking and reservations
Backend Services
- API Gateway - Single entry point for all API requests
- Authentication Service - Handles user authentication and authorization
- Customer Service - Manages customer profiles and segmentation
- Loyalty Service - Handles points, rewards, and tier management
- Campaign Service - Manages marketing campaigns and promotions
- Notification Service - Handles push notifications and alerts
- Analytics Service - Processes analytics and reporting data
- AI Service - Provides AI segmentation, recommendations, and chatbot functionality
Data Layer
- Primary Database - PostgreSQL for transactional data
- Analytics Database - ClickHouse for analytics and reporting
- Cache Layer - Redis for session management and caching
- Message Queue - RabbitMQ/Kafka for asynchronous processing
External Integrations
- WeChat API - WeChat Official Account and Mini Program APIs
- Payment Gateway - WeChat Pay integration
- POS Systems - Integration with point-of-sale systems
- CDP Platforms - Customer Data Platform integrations
Design Patterns
Microservices Pattern
Each service is independently deployable and scalable:
┌─────────────┐
│ API Gateway│
└──────┬──────┘
│
┌───┴───┬──────────┬──────────┬──────────┐
│ │ │ │ │
┌──▼──┐ ┌──▼──┐ ┌──▼──┐ ┌──▼──┐ ┌──▼──┐
│Auth │ │Cust │ │Loyal│ │Camp │ │Notif│
│Svc │ │Svc │ │Svc │ │Svc │ │Svc │
└──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘
│ │ │ │ │
└───┬───┴──────────┴──────────┴──────────┘
│
┌───▼───┐
│Database│
└───────┘
Event-Driven Architecture
Services communicate through events for loose coupling:
- Customer registration events
- Purchase completion events
- Points earned/redeemed events
- Campaign participation events
API-First Design
All functionality is exposed through RESTful APIs:
- Consistent API design patterns
- Versioned APIs (
/v1,/v2) - OpenAPI/Swagger documentation
- Rate limiting and throttling
Technology Stack
Backend
- Language: Node.js (TypeScript), Python
- Framework: Express.js, FastAPI
- Database: PostgreSQL, ClickHouse
- Cache: Redis
- Message Queue: RabbitMQ
Frontend
- WeChat Mini Program: WeChat Mini Program Framework
- Admin Web App: React, TypeScript
- State Management: Redux Toolkit
Infrastructure
- Containerization: Docker
- Orchestration: Kubernetes
- CI/CD: GitHub Actions
- Monitoring: Prometheus, Grafana
Data Flow
Customer Registration Flow
1. Customer opens WeChat Mini Program
2. WeChat OAuth → Authentication Service
3. Create/Update Customer Profile → Customer Service
4. Initialize Loyalty Account → Loyalty Service
5. Send Welcome Notification → Notification Service
6. Return customer data to Mini Program
Points Earning Flow
1. Purchase completed at POS
2. POS sends event to API Gateway
3. Loyalty Service processes transaction
4. Calculate points based on rules
5. Update customer points balance
6. Trigger notification if milestone reached
7. Update analytics database
Security Architecture
Authentication & Authorization
- OAuth 2.0 / OpenID Connect
- JWT tokens for API authentication
- Role-based access control (RBAC)
- API key management for service-to-service communication
Data Security
- Encryption at rest (AES-256)
- Encryption in transit (TLS 1.3)
- PII data masking
- Audit logging for sensitive operations
Scalability Considerations
Horizontal Scaling
- Stateless services enable easy horizontal scaling
- Load balancing across service instances
- Database read replicas for read-heavy workloads
Caching Strategy
- Redis for frequently accessed data
- CDN for static assets
- Application-level caching for computed results
Performance Optimization
- Database indexing and query optimization
- Async processing for non-critical operations
- Batch processing for analytics
Monitoring & Observability
Logging
- Centralized logging with ELK stack
- Structured logging with correlation IDs
- Log levels: DEBUG, INFO, WARN, ERROR
Metrics
- Application metrics (request rate, latency, error rate)
- Business metrics (registrations, points earned, campaigns)
- Infrastructure metrics (CPU, memory, disk)
Tracing
- Distributed tracing with OpenTelemetry
- Request flow visualization
- Performance bottleneck identification