System Architecture Overview
This document provides a high-level overview of the SG Cars Trends platform architecture, illustrating how the various components interact to deliver Singapore vehicle registration data and COE bidding results.Architecture Diagram
System Components
Applications Layer
API Service (Hono Framework)- RESTful endpoints for data access (
/v1/cars
,/v1/coe
,/v1/months
) - tRPC integration for type-safe API calls
- Workflow orchestration endpoints
- Social media webhook handlers
- Bearer token authentication
- User-facing interface with interactive charts and analytics
- Blog functionality with LLM-generated content
- Server-side rendering for optimal performance
- Real-time analytics tracking
- Comprehensive API documentation
- Developer guides and examples
- Interactive API exploration
Shared Packages
Database Package- Drizzle ORM schema definitions
- Type-safe database queries
- Migration management
- Shared database client configuration
- Shared TypeScript interfaces
- API request/response types
- Domain model definitions
- Common utility functions
- Redis client configuration
- Date formatting and calculations
Infrastructure Layer
AWS Services (Singapore Region - ap-southeast-1)- Lambda Functions: Serverless compute for API and web applications
- CloudFront: Global content delivery network
- API Gateway: RESTful API routing and management
- RDS PostgreSQL: Primary data storage
- Upstash Redis: Caching and session management
- Domain routing and SSL termination
- Global DNS resolution
- DDoS protection and security features
Data Processing Workflows
QStash Orchestration- Scheduled data updates (hourly during business hours)
- Workflow state management and error handling
- Message queue processing
- LTA DataMall integration for vehicle registration data
- CSV processing and data transformation
- Database updates with duplicate detection
- COE bidding results processing
- Prevailing Quota Premium (PQP) data handling
- Conditional blog generation when bidding cycles complete
- Google Gemini AI integration for content creation
- Market analysis and insights generation
- SEO optimization and metadata creation
External Integrations
Data Sources- LTA DataMall: Official Singapore vehicle and COE data
- Google Gemini AI: LLM for automated blog content generation
- Discord: Webhook-based notifications
- LinkedIn: API-based business updates
- Telegram: Bot-based channel messaging
- Twitter: API-based social media posts
Data Flow
- Data Ingestion: Scheduled workflows fetch data from LTA DataMall
- Data Processing: CSV files are parsed, validated, and transformed
- Data Storage: Processed data is stored in PostgreSQL with Redis caching
- Content Generation: AI generates blog posts from processed data
- Distribution: Updates are published to social media platforms
- User Access: Web application and API serve data to end users
Key Architectural Decisions
Monorepo Structure- Centralized codebase with shared packages
- Consistent tooling and development experience
- Type safety across application boundaries
- Cost-effective scaling based on usage
- Minimal infrastructure management overhead
- Regional deployment for low latency
- Reliable data processing with error recovery
- Atomic operations with state management
- Scheduled execution with manual override capability
- Diversified content distribution
- Platform-specific content formatting
- Graceful degradation with error notifications