# Dokumentasi Folder `public/` ## Gambaran Umum Folder `public/` berisi semua static assets yang dapat diakses langsung dari browser tanpa processing. File-file di folder ini di-serve oleh Next.js dari root path `/`. --- ## ๐Ÿ“ Struktur Direktori ``` public/ โ”œโ”€โ”€ models/ # Machine Learning Models โ”‚ โ””โ”€โ”€ xgb_activity_model.json # XGBoost activity classifier (2.1 MB) โ”œโ”€โ”€ favicon.svg # App icon (browser tab) โ”œโ”€โ”€ file.svg # File icon asset โ”œโ”€โ”€ globe.svg # Globe icon asset โ”œโ”€โ”€ next.svg # Next.js logo โ”œโ”€โ”€ vercel.svg # Vercel logo โ””โ”€โ”€ window.svg # Window icon asset ``` --- ## ๐Ÿ“„ File-File Utama ### **1. `models/xgb_activity_model.json`** ๐Ÿค– **Path**: `/public/models/xgb_activity_model.json` **Fungsi**: XGBoost Machine Learning Model untuk Human Activity Recognition **Purpose**: - Classify pose menjadi 3 kategori: 1. **Standing** (Berdiri) 2. **Sitting** (Duduk) 3. **Fall Detected** (Jatuh terdeteksi) **Size**: **2.1 MB** (Very Large!) **Format**: JSON serialization dari XGBoost model - Berisi tree structures, weights, dan thresholds - trained model dari Python exported ke JavaScript-compatible format **How It's Used**: ```typescript // lib/pose/XGBoostPredictor.ts import modelData from "../public/models/xgb_activity_model.json"; class XGBoostPredictor { predict(features: number[]): number[] { // Load model from JSON // Execute XGBoost inference // Return [standingProb, sittingProb, fallProb] } } ``` **Access URL**: `http://localhost:3000/models/xgb_activity_model.json` **Tech Details**: - Input: 141 features (33 landmarks ร— 4 + 9 derived) - Output: 3-class probability distribution - Algorithm: Gradient Boosted Decision Trees **Performance**: - Inference: ~5-10ms per frame - Memory: ~2 MB loaded in browser - Accuracy: Depends on training data quality --- ### **2. `favicon.svg`** ๐ŸŽจ **Path**: `/public/favicon.svg` **Fungsi**: App icon yang muncul di browser tab **Size**: ~1.1 KB **Design**: - SVG icon dengan gambar dumbbells (barbel) - Color: Blue (`#1E40AF` - blue-700) - Viewbox: 24ร—24 - Rendered size: 48ร—48 pixels **SVG Structure**: ```svg ``` **Visual**: Representing fitness/strength training **Browser Display**: - Favicon di tab browser - Bookmark icon - Desktop shortcut icon (PWA) **Access**: Automatically loaded oleh Next.js dari `` --- ### **3. Icon Assets** (SVG Icons) #### **`file.svg`** **Size**: ~391 bytes **Fungsi**: Generic file icon - Bisa digunakan untuk file upload UI - Document representation - Attachment icons **Use Case**: UI components yang butuh file icon --- #### **`globe.svg`** **Size**: ~1 KB **Fungsi**: Globe/world icon - Public/internet representation - Language selection - Global settings **Possible Uses**: - Language switcher (future feature) - Public profile indicators - Network status --- #### **`window.svg`** **Size**: ~385 bytes **Fungsi**: Window/application icon - UI element representation - Modal/dialog indicators - Application layout icons **Use Case**: - Dashboard widgets - Window management UI - Layout switching --- ### **4. Brand Logos** #### **`next.svg`** **Size**: ~1.4 KB **Fungsi**: Next.js official logo - Used in default Next.js templates - Brand attribution - Developer credits **Current Usage**: Likely not displayed in production - Default Next.js boilerplate file - Can be removed if not used --- #### **`vercel.svg`** **Size**: ~128 bytes **Fungsi**: Vercel deployment platform logo - Hosting provider logo - Deployment attribution **Current Usage**: Likely not displayed - Boilerplate file - Can be removed if deploying elsewhere --- ## ๐Ÿ”— How Public Files Are Accessed ### **In Code**: ```typescript // Direct path from root Logo // Model import (if using import) import model from '@/public/models/xgb_activity_model.json'; // Or fetch at runtime const response = await fetch('/models/xgb_activity_model.json'); const model = await response.json(); ``` ### **In Browser**: - `http://localhost:3000/favicon.svg` - `http://localhost:3000/models/xgb_activity_model.json` - `http://localhost:3000/next.svg` **Important**: - โœ… NO `/public` prefix in URL - โœ… Files served from root `/` - โŒ Don't use `/public/favicon.svg` (404!) --- ## ๐Ÿ“Š File Analysis | File | Size | Type | Purpose | Status | | ------------------------- | ------ | -------- | ----------------------- | ---------------- | | `xgb_activity_model.json` | 2.1 MB | ML Model | Activity classification | โœ… **Critical** | | `favicon.svg` | 1.1 KB | Icon | App branding | โœ… **Active** | | `file.svg` | 391 B | Icon | UI asset | โš ๏ธ Likely unused | | `globe.svg` | 1 KB | Icon | UI asset | โš ๏ธ Likely unused | | `window.svg` | 385 B | Icon | UI asset | โš ๏ธ Likely unused | | `next.svg` | 1.4 KB | Logo | Boilerplate | โš ๏ธ Can remove | | `vercel.svg` | 128 B | Logo | Boilerplate | โš ๏ธ Can remove | **Total Size**: ~2.1 MB **Largest File**: `xgb_activity_model.json` (99% of total) --- ## ๐ŸŽฏ Optimization Recommendations ### **1. Model Optimization** โšก **Current**: 2.1 MB JSON file **Options**: - โœ… **Lazy Load**: Only load saat dibutuhkan - โœ… **Compression**: Gzip/Brotli (automatic by Next.js) - โœ… **CDN**: Host di CDN untuk faster global access - โš ๏ธ **Quantization**: Reduce precision (may affect accuracy) - โš ๏ธ **ONNX Format**: Convert ke binary format (smaller) **Lazy Load Example**: ```typescript // Load only when needed const loadModel = async () => { const model = await import("@/public/models/xgb_activity_model.json"); return model; }; ``` --- ### **2. Icon Cleanup** ๐Ÿงน **Unused Icons**: Remove jika tidak digunakan ```bash # Check usage across codebase grep -r "file.svg" app/ grep -r "globe.svg" app/ grep -r "window.svg" app/ # If no results, safe to delete rm public/file.svg public/globe.svg public/window.svg rm public/next.svg public/vercel.svg ``` **Benefit**: Reduce deployment size, faster builds --- ### **3. Add More Assets** ๐Ÿ“ **Recommended Additions**: #### **`robots.txt`** ```txt # public/robots.txt User-agent: * Allow: / Sitemap: https://yourapp.com/sitemap.xml ``` #### **`manifest.json`** (PWA) ```json { "name": "Straps Fitness", "short_name": "Straps", "icons": [ { "src": "/favicon.svg", "sizes": "48x48", "type": "image/svg+xml" } ], "theme_color": "#1E40AF", "background_color": "#000000", "display": "standalone" } ``` #### **`sitemap.xml`** (SEO) ```xml https://yourapp.com/ 1.0 ``` --- ## ๐Ÿ”’ Security Considerations ### **Current Status**: โœ… Safe **Why**: - โœ… No sensitive data in public files - โœ… Model file is read-only data (not executable) - โœ… SVG files are static images ### **Best Practices**: 1. **Never Put Secrets Here** โŒ - No API keys - No passwords - No private data 2. **Validate SVG Files** โœ… - Check for XSS vectors - Sanitize uploaded SVGs 3. **Model Integrity** ๐Ÿ” - Verify model hash before use - Detect tampering ```typescript const expectedHash = "sha256-abc123..."; const actualHash = await hashFile("/models/xgb_activity_model.json"); if (actualHash !== expectedHash) { throw new Error("Model tampered!"); } ``` --- ## ๐Ÿš€ Advanced Usage ### **1. Dynamic Model Loading** ```typescript // Lazy load untuk reduce initial bundle const HARCore = dynamic(() => import('@/lib/pose/HARCore'), { ssr: false, loading: () =>

Loading AI Model...

}); ``` ### **2. Service Worker Caching** (PWA) ```javascript // Cache model untuk offline use self.addEventListener("install", (event) => { event.waitUntil( caches.open("models-v1").then((cache) => { return cache.add("/models/xgb_activity_model.json"); }), ); }); ``` ### **3. Progressive Enhancement** ```typescript // Fallback jika model load gagal let classifier; try { classifier = await loadXGBoostModel(); } catch (err) { console.warn("Model failed to load, using heuristics"); classifier = new FallbackHeuristicClassifier(); } ``` --- ## ๐Ÿ“ˆ Performance Metrics ### **Model Loading**: - **Cold Start**: ~200-500ms (first load, no cache) - **Warm Start**: ~50-100ms (cached) - **Memory**: ~2-3 MB in-memory after parsing ### **Optimization Impact**: ```typescript // Before: Load synchronously (blocks rendering) import model from "@/public/models/xgb_activity_model.json"; // After: Load async (non-blocking) const model = await fetch("/models/xgb_activity_model.json").then((r) => r.json(), ); ``` **Result**: - โšก Faster initial page load - โšก Better Lighthouse scores - โšก Improved user experience --- ## ๐Ÿ’ก Maintenance Tips ### **When Adding New Files**: 1. **Images**: - Use WebP format (smaller than PNG/JPG) - Optimize dengan tooling (ImageOptim, Squoosh) - Consider `next/image` untuk auto-optimization 2. **Icons**: - Prefer SVG (scalable, small) - Consider icon libraries (react-icons, lucide-react) - Avoid duplicates 3. **Data Files**: - Compress large JSON/CSV - Consider API route instead of static file - Use CDN untuk large files ### **Regular Cleanup**: ```bash # Find unused public files du -sh public/* # Check git history untuk unused files git log --all --full-history -- public/ ``` --- ## ๐Ÿ”ง Troubleshooting ### **Issue**: Model not loading ``` Error: Failed to fetch /models/xgb_activity_model.json ``` **Solutions**: 1. Verify file exists: `ls public/models/` 2. Check Next.js server running 3. Clear browser cache 4. Check CORS headers (if loading from external domain) --- ### **Issue**: Icons not showing ``` 404: /public/favicon.svg not found ``` **Solution**: โŒ Remove `/public` prefix ```html ``` --- ### **Issue**: Large bundle size ``` Warning: Page size exceeds 300 KB ``` **Solution**: Lazy load model ```typescript // Lazy load const model = await import("@/public/models/xgb_activity_model.json"); ``` --- ## ๐Ÿ“š Next.js Static File Best Practices ### **โœ… DO**: - Keep files small (< 1 MB ideally) - Use modern formats (WebP, AVIF, SVG) - Compress large files - Use meaningful filenames - Organize in subdirectories ### **โŒ DON'T**: - Put sensitive data - Store frequently changing data - Use as database replacement - Include source files (.psd, .ai) - Exceed 10 MB total size --- ## ๐ŸŽ“ Summary **Current Status**: โœ… Well-organized, but can be optimized **Key Files**: 1. **xgb_activity_model.json** - Critical ML model (2.1 MB) 2. **favicon.svg** - App branding 3. **Other SVGs** - Likely unused (cleanup recommended) **Recommendations**: 1. โšก Lazy load ML model 2. ๐Ÿงน Remove unused icons 3. ๐Ÿ“ Add PWA manifest 4. ๐Ÿ” Add model integrity check 5. ๐Ÿ“Š Monitor bundle size **Total Size**: ~2.1 MB (99% from model file) **Performance**: Good, but can be improved with lazy loading