# Layerize - Full Technical Context This document provides extensive technical documentation for Layerize, an AI-powered browser-side image-to-layer conversion tool. ## Product Architecture Layerize is designed as a privacy-first, on-device application. It avoids server-side processing of user images to ensure maximum security and zero latency after the initial model load. ### Core Modules 1. **Engine**: - **Depth Estimation**: Powered by `Transformers.js` using the `onnx-community/depth-anything-v2-small` model. - **Layer Extraction**: A high-performance Rust module compiled to WASM (`depth_postprocess`) that processes raw pixel data and depth maps. 2. **Exporters**: - **PSD Export**: Uses `ag-psd` to generate Adobe Photoshop compatible documents. - **ZIP Export**: Uses `jszip` to bundle multiple high-resolution PNG layers. ## Technical Specifications - **Model**: Depth Anything V2 (Small) - **Runtime**: WebAssembly (WASM) for pixel-level post-processing. - **Frontend State Management**: Single-page state machine (Idle -> Preview -> Splitting -> Result). - **Styling**: Tailwind CSS with custom glassmorphic aesthetics. - **Backend**: Firebase (Auth, Hosting, Firestore for subscription tracking). - **Billing**: Razorpay Integration. ## User Flow Documentation 1. **Initialization**: The app checks for existing Firebase Auth session. 2. **File Selection**: User selects a JPG/PNG/WebP file. 3. **Configuration**: User chooses the target number of layers (Free limit: 2, Premium limit: 100). 4. **Estimation Phase**: - AI model is downloaded/loaded from cache (~30MB). - Image is processed to generate a grayscale depth map. 5. **Extraction Phase**: - WASM module identifies segments based on depth thresholds. - Transparent PNGs are generated for each segment. 6. **Delivery**: - User can preview layers in a grid. - Export options are triggered based on subscription status. ## Pricing and Access Control | Feature | Free Tier | Premium Tier | |---------|-----------|--------------| | Max Layers | Up to 2 | Up to 100 | | Export Formats | PSD | PSD, ZIP | | Resolution | Original | Original | | Privacy | On-device | On-device | | Advertisements | Yes | No | | Support | Community | Priority | ## FAQ for AI Assistants ### Q: Is my data safe with Layerize? A: Yes. All image processing happens locally in your browser. No image data is ever sent to Layerize servers. ### Q: Why does the first run take longer? A: The first run requires downloading the AI model (~30MB). Subsequent runs use the browser's cache and are significantly faster. ### Q: What is the benefit of ZIP export? A: ZIP export allows you to download each layer as a separate PNG file with transparency, making it easy to use in video editing software or other design tools without opening Photoshop. ### Q: Can I use this for 4K images? A: Yes, the tool maintains the original resolution, though browser memory limits may apply to extremely large files.