{
_id: ObjectId,
metadata: {
name: "Octahedron Assembly",
version: "2.0",
created: ISODate,
lastModified: ISODate,
author: ObjectId, // Reference to users
description: "Optimized octahedron assembly...",
difficulty: "intermediate",
estimatedTime: 1800,
tags: ["geometry", "3d", "stem"],
category: "geometric-shapes",
featured: false
},
// Template-based architecture
templates: {
materials: [
{id: "plastic_green", source: "/templates/materials/plastic_green.json"},
{id: "plastic_red", source: "/templates/materials/plastic_red.json"}
],
components: [
{id: "green_11_2", source: "/templates/straws/green_11_2.json"},
{id: "3leg_red", source: "/templates/connectors/3leg_red.json"}
]
},
// Optimized instances
instances: {
straws: [
{
templateId: "green_11_2",
instances: [
{id: "straw_1", transform: {position: {x:0,y:0,z:0}, rotation: {x:0,y:0,z:0}}}
]
}
],
connectors: [
{
templateId: "3leg_red",
instances: [
{id: "conn_1", transform: {position: {x:0,y:0,z:0}, rotation: {x:0,y:0,z:0}}}
]
}
]
},
// Connection definitions
connections: {
"base_square": [
{strawId: "straw_1", endpoint: "start", connectorId: "conn_1", port: 0}
]
},
// Interactive actions
actions: [
{
id: "action_1",
name: "Build Base",
type: "connect",
targets: ["straw_1", "conn_1"],
duration: 2.0,
validation: {type: "connection", criteria: {}}
}
],
// Learning activities
activities: [
{
id: "activity_1",
name: "Octahedron Lab",
objectives: ["Understand geometry", "Practice construction"],
steps: [
{actionId: "action_1", title: "Build Base", hints: ["Use connectors"]}
]
}
],
// Performance data
performance: {
compressionRatio: "5.4:1",
originalSize: 1616,
optimizedSize: 300,
loadTime: 0.8, // seconds
targetFPS: 60
},
// Access control
permissions: {
isPublic: true,
allowedRoles: ["student", "teacher"],
restrictedFeatures: []
},
// Indexing for search
searchKeywords: ["octahedron", "geometry", "3d", "assembly"],
// Analytics
analytics: {
viewCount: 1250,
completionRate: 0.87,
averageTime: 1650,
difficultyRating: 3.2
}
}{
_id: ObjectId,
templateId: "green_11_2", // Unique identifier
name: "Green Straw 11.2cm",
category: "straw",
type: "cylindrical",
// Physical properties
geometry: {
length: 11.2,
diameter: 0.6,
wallThickness: 0.1
},
material: {
type: "plastic",
color: "#c1e500",
flexibility: 75,
opacity: 1.0,
roughness: 0.3
},
// 3D model data
model: {
url: "/models/straws/green_straw.glb",
size: 15840, // bytes
format: "glb",
compressionLevel: 7
},
// LOD configurations
lod: {
high: {
geometryComplexity: "detailed",
polyCount: 128,
textureResolution: 512
},
medium: {
geometryComplexity: "standard",
polyCount: 64,
textureResolution: 256
},
low: {
geometryComplexity: "basic",
polyCount: 16,
textureResolution: 128
}
},
// Physics properties
physics: {
mass: 0.05,
friction: 0.4,
elasticity: 0.2
},
// Connection points
endpoints: {
start: {localPosition: {x: 0, y: -5.6, z: 0}},
end: {localPosition: {x: 0, y: 5.6, z: 0}}
},
// Version control
version: "1.2",
created: ISODate,
lastModified: ISODate,
// Usage statistics
usage: {
usedInAssemblies: 45,
popularityScore: 8.7
}
}{
_id: ObjectId,
userId: ObjectId,
assemblyId: ObjectId,
// Progress tracking
progress: {
currentStep: 3,
totalSteps: 5,
completedSteps: [1, 2],
startedAt: ISODate,
lastActiveAt: ISODate,
estimatedCompletion: ISODate
},
// Performance metrics
metrics: {
timeSpent: 1200, // seconds
hintsUsed: 2,
errorsCount: 1,
retryCount: 0,
efficiencyScore: 0.85
},
// Step-by-step details
stepHistory: [
{
stepId: 1,
actionId: "action_prepare_connectors",
startTime: ISODate,
endTime: ISODate,
duration: 45,
attempts: 1,
hintsUsed: 0,
success: true
}
],
// Real-time performance data
performanceData: {
avgFPS: 58.4,
memoryUsage: 125, // MB
deviceSpecs: {
browser: "Chrome 120",
gpu: "RTX 3060",
ram: "16GB"
}
},
// Learning analytics
learningMetrics: {
conceptsLearned: ["geometric-symmetry", "3d-construction"],
skillsImproved: ["spatial-reasoning", "problem-solving"],
difficultyAdaptation: "increasing"
}
}{
_id: ObjectId,
assemblyId: ObjectId,
// Aggregated performance data
performance: {
averageLoadTime: 0.75,
averageFPS: 59.2,
averageMemoryUsage: 118,
compressionEfficiency: 0.847
},
// Device compatibility
deviceMetrics: {
"mobile": {avgFPS: 45.2, loadTime: 1.2},
"desktop": {avgFPS: 59.8, loadTime: 0.6},
"tablet": {avgFPS: 52.1, loadTime: 0.9}
},
// Geographic distribution
regionPerformance: {
"asia": {avgLoadTime: 0.65, cdnHitRate: 0.92},
"europe": {avgLoadTime: 0.71, cdnHitRate: 0.89},
"america": {avgLoadTime: 0.68, cdnHitRate: 0.94}
},
// Optimization recommendations
recommendations: [
{
type: "lod_adjustment",
description: "Reduce LOD distance for mobile devices",
impact: "15% FPS improvement",
priority: "high"
}
],
lastUpdated: ISODate
}Technologies: Node.js + Express/Fastify + MongoDB Responsibilities:
- Assembly CRUD operations
- Template validation & compilation
- Real-time collaboration
- Version control
API Endpoints:
// RESTful APIs
GET /api/v1/assemblies // List assemblies
GET /api/v1/assemblies/:id // Get assembly
POST /api/v1/assemblies // Create assembly
PUT /api/v1/assemblies/:id // Update assembly
DELETE /api/v1/assemblies/:id // Delete assembly
// Advanced endpoints
POST /api/v1/assemblies/:id/optimize // Optimize assembly
POST /api/v1/assemblies/:id/validate // Validate structure
GET /api/v1/assemblies/:id/performance // Performance metrics
POST /api/v1/assemblies/:id/duplicate // Duplicate assembly
// Real-time WebSocket
WS /api/v1/assemblies/:id/collaborate // Real-time editingTechnologies: Node.js + MongoDB + Redis Responsibilities:
- Component template library
- Material management
- Template versioning
- Dependency resolution
API Endpoints:
GET /api/v1/templates/components // List component templates
GET /api/v1/templates/materials // List material templates
POST /api/v1/templates/components // Create component template
GET /api/v1/templates/:id // Get template details
PUT /api/v1/templates/:id // Update template
POST /api/v1/templates/:id/validate // Validate template
// Template optimization
POST /api/v1/templates/optimize // Batch optimize templates
GET /api/v1/templates/dependencies/:id // Get dependencies
POST /api/v1/templates/resolve // Resolve template dependenciesTechnologies: Node.js + S3/MinIO + Redis Responsibilities:
- 3D asset storage & delivery
- Asset compression & optimization
- CDN integration
- Progressive loading
API Endpoints:
// Asset management
POST /api/v1/assets/upload // Upload 3D assets
GET /api/v1/assets/:id // Get asset
POST /api/v1/assets/:id/optimize // Optimize asset
DELETE /api/v1/assets/:id // Delete asset
// Progressive loading
GET /api/v1/assets/:id/stream // Stream asset chunks
GET /api/v1/assets/:id/lod/:level // Get LOD version
POST /api/v1/assets/preload // Preload asset bundle
// CDN integration
GET /api/v1/cdn/status // CDN cache status
POST /api/v1/cdn/invalidate // Invalidate CDN cache// Redis Cache Layers
interface CacheStrategy {
// Level 1: Hot data (1-minute TTL)
hotData: {
popularAssemblies: "assemblies:popular",
userSessions: "sessions:*",
realtimeMetrics: "metrics:realtime:*"
},
// Level 2: Warm data (1-hour TTL)
warmData: {
assemblyMetadata: "assemblies:meta:*",
templateDefinitions: "templates:*",
userProfiles: "users:profile:*"
},
// Level 3: Cold data (24-hour TTL)
coldData: {
performanceAnalytics: "analytics:*",
searchIndexes: "search:*",
staticContent: "static:*"
}
}interface CDNStrategy {
// Global distribution
regions: ["us-east", "eu-west", "asia-pacific"],
// Asset optimization
compression: {
gltf: "draco", // 90% compression
textures: "webp", // 25-50% smaller
json: "gzip", // 70% compression
},
// Progressive delivery
streaming: {
chunkSize: "1MB",
preloadRadius: 50,
priority: "distance-based"
},
// Cache policies
cacheTTL: {
models: "7d", // 3D models rarely change
templates: "24h", // Templates change occasionally
assemblies: "1h", // Assemblies change frequently
userProgress: "0" // Never cache user data
}
}interface ScalingStrategy {
// MongoDB sharding
sharding: {
shardKey: "assemblyId",
chunks: {
"shard-1": "assemblies:0-1000",
"shard-2": "assemblies:1001-2000",
"shard-3": "assemblies:2001+"
}
},
// Read replicas
readReplicas: {
primary: "write-operations",
secondary1: "analytics-queries",
secondary2: "user-progress-reads"
},
// Indexing strategy
indexes: {
assemblies: ["searchKeywords", "category", "difficulty"],
templates: ["templateId", "category", "usage.popularityScore"],
userProgress: ["userId", "assemblyId", "lastActiveAt"]
}
}interface AuthStrategy {
// JWT-based authentication
jwt: {
accessToken: "15min", // Short-lived
refreshToken: "7d", // Longer-lived
signingAlgorithm: "RS256"
},
// Role-based access control
roles: {
student: ["view", "interact", "progress"],
teacher: ["create", "edit", "assign", "analytics"],
admin: ["all"]
},
// API security
rateLimiting: {
general: "100req/min",
upload: "10req/min",
realtime: "1000req/min"
}
}interface MonitoringStrategy {
// Service health
healthChecks: {
assemblies: "/health",
templates: "/health",
content: "/health"
},
// Performance metrics
metrics: {
responseTime: "p95 < 200ms",
throughput: "> 1000 rps",
errorRate: "< 0.1%",
uptime: "> 99.9%"
},
// Business metrics
analytics: {
userEngagement: "time-spent, completion-rate",
contentPerformance: "view-count, ratings",
systemPerformance: "load-time, fps"
}
}# docker-compose.yml
version: '3.8'
services:
# API Gateway
api-gateway:
image: nginx:alpine
ports: ["80:80", "443:443"]
# Core services
assembly-service:
image: node:18-alpine
environment:
- DATABASE_URL=mongodb://mongo:27017/assemblies
- REDIS_URL=redis://redis:6379
scale: 3
template-service:
image: node:18-alpine
scale: 2
content-service:
image: node:18-alpine
scale: 2
# Databases
mongodb:
image: mongo:6
volumes: ["./data/mongo:/data/db"]
redis:
image: redis:alpine
# Storage
minio:
image: minio/minio
environment:
- MINIO_ACCESS_KEY=minioaccess
- MINIO_SECRET_KEY=miniosecretDựa trên chiến lược này, thứ tự triển khai nên là:
- Phase 1: Assembly Management Service + MongoDB setup
- Phase 2: Template Management Service + Redis caching
- Phase 3: Content Management Service + S3/MinIO storage
- Phase 4: API Gateway + Load balancing
- Phase 5: Analytics & Monitoring services
- Phase 6: CDN integration + Global deployment
Bạn muốn tôi chi tiết về phase nào trước, hoặc có muốn tôi implement demo cho service nào cụ thể không? 🚀