Overall System Architecture
Relevant source files
The following files were used as context for generating this wiki page:
MarketSage is an AI-powered financial analytics and intelligent shopping assistant platform designed primarily as a Chrome Extension for Chinese marketplaces (Temu, AliExpress, DHgate). The system integrates real-time marketplace monitoring, social commerce analytics, and advanced threat detection to provide users with a secure and optimized shopping experience.
The architecture follows a modular service-oriented design, leveraging TypeScript and React for the frontend, with a robust backend service layer managed via a ServiceContainer for dependency injection. The system utilizes machine learning (TensorFlow.js) for scam detection and price prediction, while employing RxJS for reactive data streams and real-time monitoring.
Sources: WHATAMI.txt:1-10, package.json:28-40, src/manifest.json:1-30
Extension Core Structure
The system is built on the Manifest V3 standard, utilizing a service worker for background processing and content scripts for marketplace interaction.
Component Breakdown
| Component | Path / Implementation | Description |
|---|---|---|
| Background Service | background.js | Handles long-running tasks, API communication, and core logic orchestration. |
| Content Scripts | content.js | Injected into supported domains to extract product data and modify the DOM. |
| Action Popup | popup.html | The primary UI interface for user interaction and dashboard visualization. |
| Permissions | storage, activeTab, scripting | Required for data persistence, tab interaction, and dynamic analysis. |
Sources: src/manifest.json:6-25
Host Permissions
The system is architected to operate specifically on the following domains:
*.temu.com*.aliexpress.com*.dhgate.com
Sources: src/manifest.json:10-14
Core Service Layers
The architecture is divided into specialized service modules that handle distinct aspects of the platform's intelligence.
1. Smart Shopping Assistant
This module provides natural language processing (NLP) capabilities to interpret user queries and provide recommendations. It integrates with the PricePredictionEngine and AdvancedThreatDetection to ensure suggestions are both economical and safe.
Key features include:
- Intent Patterns: Identification of intents such as
find_product,compare_products, andsafety_check. - Entity Extraction: Automatic parsing of brands, price ranges, and product attributes from natural language.
- Context Management: Maintenance of user sessions and shopping history.
Sources: src/core/ai/SmartShoppingAssistant.ts:80-150
2. Security and Threat Detection
The SecurityAnalyzer and ScamDetectionModel form the protective layer of the architecture. They utilize a weighted scoring system to evaluate the risk of marketplace listings.
| Metric | Weight | Description |
|---|---|---|
| Seller History | 0.4 | Evaluation of seller ratings and account age. |
| Price Anomaly | 0.3 | Detection of prices significantly below market average (Z-score analysis). |
| Listing Quality | 0.3 | Analysis of images, description length, and suspicious keywords. |
Sources: src/background/services/protect/securityAnalyzer.ts:13-20, src/popup/components/education/WeightingSystemExplainer.tsx:50-65
3. Marketplace Monitoring and Analytics
The system maintains real-time streams of marketplace data using RxJS BehaviorSubject and Observable patterns.
The MarketplaceMonitoringDashboard provides:
- Performance Metrics: Tracking response times and error rates.
- Trend Metrics: Analyzing popular categories and search growth.
- Alert Engine: Triggering notifications for high-risk activity or price drops.
Sources: src/core/monitoring/MarketplaceMonitoringDashboard.ts:160-220
Social Commerce Integration
The SocialCommerceAnalytics service handles community-driven data, providing insights into viral content, influencer impact, and community health.
Analytics Flow
- Metric Collection: Real-time tracking of daily/weekly/monthly active users and engagement scores.
- Influence Mapping: Calculating
UserInfluencebased on follower counts, engagement rates, and community impact. - Viral Detection: Identifying "viral" content through growth rates and amplification factors.
- Revenue Attribution: Mapping purchases to social touchpoints (direct social, influencer-driven, or community-driven).
Sources: src/core/social/SocialCommerceAnalytics.ts:258-350
Security Utilities and Data Integrity
The system enforces strict data handling through the SecurityUtils class, which provides:
- XSS Protection: Sanitization of all input strings and object properties.
- CSRF Protection: Generation and validation of secure tokens.
- Domain Validation: Ensuring URLs belong to allowed marketplace domains.
- Constant-time Comparison: Preventing timing attacks during token validation.
Sources: src/common/security/SecurityUtils.ts:15-110
Build and Verification Lifecycle
The project utilizes a custom build verification script (verify-build.js) to ensure architectural integrity before deployment. It validates:
- Manifest Integrity: Presence of required Chrome extension fields.
- Dependency Presence: Ensuring
react,rxjs, and@tensorflow/tfjsare available. - Strict Typing: Verification of
tsconfig.jsonstrict mode. - Core File Presence: Ensuring critical components like
StateManager.tsandErrorHandler.tsexist.
Sources: scripts/verify-build.js:25-80
Summary
The MarketSage architecture is a multi-layered system that combines browser extension capabilities with advanced AI services. By decoupling data extraction (Content Scripts), core logic (Background Services), and user interaction (React Popup), the system provides a scalable framework for financial analytics. The heavy reliance on reactive programming (RxJS) and weighted risk models ensures that users receive real-time, accurate, and safe marketplace insights.
Sources: WHATAMI.txt:1-12, package.json:1-15