Compresso Lab is an interactive, web-based research and design workbench for data compression algorithms. It allows users to visually construct, test, and analyze compression pipelines.
Key Goals:
- Provide a hands-on environment for learning about compression.
- Allow experimentation with chaining different algorithms (transformations + compression).
- Visualize data at the byte level to understand how algorithms affect entropy and structure.
- Leverage AI (Google Gemini) to analyze data and suggest optimal compression strategies.
- Frontend Framework: React 19
- Build Tool: Vite
- Language: TypeScript
- Styling: Tailwind CSS
- Visualization: Recharts (Charts), Custom Canvas/SVG (Heatmaps)
- AI Integration: Google Gemini API (
@google/genai)
- Node.js (LTS recommended)
- Google Gemini API Key
- Install Dependencies:
npm install
- Environment Configuration:
Create a
.env.localfile in the root directory:VITE_GEMINI_API_KEY=your_api_key_here
- Development Server:
Runs the app at
npm run dev
http://localhost:5173. - Build for Production:
Outputs to
npm run build
dist/. - Preview Production Build:
npm run preview
src/(Implied root for source)components/: React UI components (e.g.,AlgorithmButton,ByteHeatmap,DataInspector).services/: Core business logic and algorithms.compressionAlgorithms.ts: Implementation of all compression and transformation logic (RLE, LZW, Huffman, etc.).analysisUtils.ts: Entropy calculation and frequency analysis.geminiService.ts: Interface with Google Gemini API.imageUtils.ts,dataUtils.ts: Helpers for data manipulation.
App.tsx: Main application controller and layout.types.ts: TypeScript definitions for Pipelines, Steps, and Results.constants.tsx: UI constants, icons, and text content.
- Pipeline: A sequence of
PipelineSteps. Data flows through these steps sequentially. - Steps: Each step performs an operation (Algorithm) on the data.
- Compression: Reduces size (e.g., LZW, Huffman).
- Transformation: Reorders/modifies data to potentially lower entropy (e.g., BWT, MTF, Delta).
- Lossy: Discards information (e.g., DCT, Quantization).
- Execution Model:
services/compressionAlgorithms.tsexportsexecutePipeline.- It runs the forward pipeline on input data.
- It immediately attempts to reverse the pipeline to verify integrity (lossless check).
- It returns a
CompressionResultobject containing metrics (Size, Entropy, Ratio) for each step.
- Lossless: RLE, LZW, Huffman, Arithmetic Coding.
- Transformations: Burrows-Wheeler Transform (BWT), Move-to-Front (MTF), Delta Encoding, XOR, PNG Filter.
- Lossy: DCT (1D), Scalar Quantization, Sub-sampling.
- Misc: Base64.
- Byte Heatmap: Visual representation of byte values (0-255) as colors.
- Frequency Charts: Histogram of byte occurrences.
- Entropy Analysis: Shannon entropy calculation per step.
- Analysis: Generates textual insights on why a pipeline works (or doesn't).
- Optimization: Suggests pipeline configurations based on input data characteristics.
- State: Centralized state in
App.tsxpassed down via props. Complex state logic (e.g., pipeline execution) is triggered byuseEffecton pipeline changes. - Styling: Extensive use of Tailwind CSS utility classes directly in JSX. Dark mode theme (
slate-950,slate-900) is the default. - Type Safety: Strict TypeScript usage. All algorithms accept and return
Uint8Array. - Performance: Large datasets are handled cautiously. Some algorithms have safety limits (e.g., BWT max 5kb in demo) to prevent main-thread blocking.
services/compressionAlgorithms.ts: The "brain" of the application.App.tsx: The "body" connecting UI to logic.types.ts: The "skeleton" defining data structures.