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
Web Application (Next.js 15)
  • User-facing interface with interactive charts and analytics
  • Blog functionality with LLM-generated content
  • Server-side rendering for optimal performance
  • Real-time analytics tracking
Documentation Site (Mintlify)
  • 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
Types Package
  • Shared TypeScript interfaces
  • API request/response types
  • Domain model definitions
Utils Package
  • 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
DNS Management (Cloudflare)
  • 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
Cars Data Workflow
  • LTA DataMall integration for vehicle registration data
  • CSV processing and data transformation
  • Database updates with duplicate detection
COE Data Workflow
  • COE bidding results processing
  • Prevailing Quota Premium (PQP) data handling
  • Conditional blog generation when bidding cycles complete
Blog Generation Workflow
  • 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
Social Media Platforms
  • Discord: Webhook-based notifications
  • LinkedIn: API-based business updates
  • Telegram: Bot-based channel messaging
  • Twitter: API-based social media posts

Data Flow

  1. Data Ingestion: Scheduled workflows fetch data from LTA DataMall
  2. Data Processing: CSV files are parsed, validated, and transformed
  3. Data Storage: Processed data is stored in PostgreSQL with Redis caching
  4. Content Generation: AI generates blog posts from processed data
  5. Distribution: Updates are published to social media platforms
  6. 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
Serverless Infrastructure
  • Cost-effective scaling based on usage
  • Minimal infrastructure management overhead
  • Regional deployment for low latency
Workflow-Based Processing
  • Reliable data processing with error recovery
  • Atomic operations with state management
  • Scheduled execution with manual override capability
Multi-Platform Social Integration
  • Diversified content distribution
  • Platform-specific content formatting
  • Graceful degradation with error notifications