Data Structure Design
The size chart feature needs to manage numerous size chart data and quickly retrieve the appropriate chart from product information. This page explains the data structure and management methods.
File Structure
Size chart data is managed as JSON files.
Directory for size chart data
Size chart list
Individual size chart data
File Naming Convention
Size chart IDs follow this naming convention:
| Prefix | Category | Examples |
|---|---|---|
| outer- | Outerwear | outer-men-jacket, outer-women-pants |
| ws- | Winter Sports | ws-men-jacket, ws-kids-jacket |
| cycling- | Cycling | cycling-jacket, cycling-gloves |
JSON File Structure
Each size chart JSON file contains an HTML table for display and measurement guides.
{
"id": "outer-men-jacket",
"name": "Outerwear: Jacket (Men's)",
"category": "outerwear",
"itemType": "jacket",
"gender": "men",
"tableHtml": "<table>...</table>",
"measurementGuide": {
"chest": "Chest: Measure horizontally at the fullest part",
"height": "Height: Measure without shoes"
}
}
Normalization Processing
Since Shopify metafields are prone to notation variations, we perform normalization.
category Normalization
gender Normalization
| Input Patterns | Normalized |
|---|---|
| women, woman, female, lady, ladies | women |
| kid, child, junior, kids | kids |
| men, man, male, mens | men |
| Other | unisex |
Mapping Data Management
Mappings are managed in two locations, balancing flexibility and stability.
Default values / Fallback
Dynamic changes from admin panel
References KV → Default values in order
Why Two Layers?
- Default values: Embedded in code ensures service continuity during KV failures
- Vercel KV: Allows immediate mapping changes from admin panel
KV Key Design
sizechart:mapping:{category}:{productType}:{gender}
→ Size chart ID
sizechart:handle:{handle}
→ Dedicated size chart ID (for handle exceptions)
sizechart:sku:{sku}
→ Dedicated size chart ID (for SKU exceptions)
Examples:
sizechart:mapping:outerwear:jackets:men→outer-men-jacketsizechart:handle:special-product-2024→special-product-chart
API Design
Size chart retrieval is done through an API.
API Request Example
GET /api/sizechart/get
?handle=product-abc-001
&sku=ABC-001-M
&category=outerwear
&productType=jackets
&gender=men
API Response Example
{
"success": true,
"chart": {
"id": "outer-men-jacket",
"name": "Outerwear: Jacket (Men's)",
"tableHtml": "<table>...</table>",
"measurementGuide": { ... }
}
}
Caching Strategy
Since size chart data doesn't change frequently, we actively use caching.
| Data | Cache Location | Duration |
|---|---|---|
| JSON Files | Server Memory | Loaded at build time |
| Mapping Data | Vercel KV | No TTL (explicit updates) |
| API Response | CDN Edge | 60 seconds (stale-while-revalidate) |
Summary
The size chart data structure is designed with these key points:
- JSON File Management: Numerous size charts managed as static files
- Normalization: Absorbs notation variations to improve mapping accuracy
- Two-Layer Mapping: Balances flexibility and stability with defaults and KV
- Caching: Achieves fast response times