--- title: Visual Notebook emoji: ๐Ÿ““ colorFrom: blue colorTo: indigo sdk: docker app_port: 7860 pinned: false --- # Visual Notebook Interactive data exploration notebook with **DuckDB + Polars** backend and **React** frontend. ## Architecture ``` โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ Browser โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ React + TypeScript โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ Notebook โ”‚ โ”‚ Charts โ”‚ โ”‚ Transform โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ Cells โ”‚ โ”‚ (ECharts)โ”‚ โ”‚ Panel โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ REST API (/api/*) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ FastAPI Backend โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ API Routes Layer โ”‚ โ”‚ โ”‚ โ”‚ upload ยท schema ยท rows ยท ops ยท history ยท viz โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ DuckDB โ”‚ โ”‚ Polars โ”‚ โ”‚ Checkpoints โ”‚ โ”‚ โ”‚ โ”‚ (query) โ”‚ โ”‚ (sample) โ”‚ โ”‚ (Parquet) โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ”‚ โ”‚ Domain Layer โ”‚ โ”‚ โ”‚ โ”‚ DataFrameRef ยท History ยท Operations ยท Viz โ”‚ โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` ## Features - **CSV Upload** - Drag-and-drop CSV files up to 500 MB - **Schema Exploration** - Automatic type inference, null counts, unique values, min/max/mean/std stats - **Data Table** - Paginated row preview with column type badges - **Transformations** - Filter, sort, select, rename, group-by, fill-nulls, clip operations - **Undo/Redo** - Full history tree with branching support - **6 Chart Types** - Histogram, scatter, top-N bar, timeline, heatmap, geo map - **Export** - Download filtered/transformed data as CSV - **Checkpoints** - Save and restore data snapshots (Parquet + JSON metadata) - **Session-based** - Each browser session gets its own isolated DuckDB instance ## Quick Start ### Prerequisites - Python 3.11+ - Node.js 20+ - [uv](https://docs.astral.sh/uv/) (Python package manager) ### Backend ```bash cd backend uv pip install -e . uvicorn visual_notebook.main:app --reload --port 8000 ``` ### Frontend ```bash cd frontend npm install npm run dev ``` The frontend dev server starts at `http://localhost:5173` and proxies API requests to the backend at `http://localhost:8000`. ### Environment Variables | Variable | Default | Description | |---|---|---| | `DATA_DIR` | `datasets` | Directory containing CSV data files | | `CHECKPOINT_DIR` | `checkpoints` | Directory for checkpoint storage | | `MAX_UPLOAD_SIZE` | `524288000` | Max CSV upload size in bytes (500 MB) | | `PREVIEW_ROWS` | `50` | Default number of preview rows | | `CORS_ORIGINS` | `http://localhost:5173` | Allowed CORS origins | | `HOST` | `0.0.0.0` | Server bind host | | `PORT` | `8000` | Server bind port | | `VITE_API_URL` | _(empty)_ | Frontend API URL override | ## Docker ```bash docker build -t visual-notebook . docker run -p 7860:7860 -v $(pwd)/datasets:/app/datasets visual-notebook ``` One image, one URL โ€” FastAPI serves both the API and the React frontend on port 7860. ## Deploy to Hugging Face Spaces The app deploys as a single Docker container to HF Spaces: 1. Create a new **Docker** Space at [huggingface.co/new-space](https://huggingface.co/new-space) 2. Add these **GitHub Secrets** (repo โ†’ Settings โ†’ Secrets โ†’ Actions): - `HF_USERNAME` โ€” your HF username - `HF_TOKEN` โ€” your HF access token - `HF_SPACE_ID` โ€” `username/space-name` 3. Push to `main` โ€” the `hf-space-deploy.yml` workflow builds and deploys automatically Your app will be live at: `https://huggingface.co/spaces//` ## Hugging Face Spaces (Federated Compute) The federated compute worker is a **separate project** deployed to Hugging Face Spaces. It is not part of this repository. See `docs/federated-compute.md` for the full architecture. ## Project Structure ``` visual-notebook/ โ”œโ”€โ”€ pyproject.toml # Workspace root config โ”œโ”€โ”€ Dockerfile # Combined backend+frontend build โ”œโ”€โ”€ docker-compose.yml # Multi-service development โ”œโ”€โ”€ .dockerignore # Docker build exclusions โ”œโ”€โ”€ .gitignore # Git exclusions โ”œโ”€โ”€ .env.example # Environment variable template โ”œโ”€โ”€ README.md # This file โ”‚ โ”œโ”€โ”€ backend/ โ”‚ โ”œโ”€โ”€ pyproject.toml # Backend dependencies โ”‚ โ””โ”€โ”€ visual_notebook/ โ”‚ โ”œโ”€โ”€ main.py # FastAPI app entry point โ”‚ โ”œโ”€โ”€ config.py # Settings from env vars โ”‚ โ”œโ”€โ”€ session.py # Session management โ”‚ โ”œโ”€โ”€ api/ โ”‚ โ”‚ โ”œโ”€โ”€ deps.py # Dependency injection โ”‚ โ”‚ โ”œโ”€โ”€ schemas.py # Pydantic models โ”‚ โ”‚ โ””โ”€โ”€ routes.py # API routes โ”‚ โ”œโ”€โ”€ data/ โ”‚ โ”‚ โ”œโ”€โ”€ types.py # Column type classification โ”‚ โ”‚ โ”œโ”€โ”€ csv_loader.py # CSV loading & registration โ”‚ โ”‚ โ””โ”€โ”€ schema.py # Schema inference โ”‚ โ”œโ”€โ”€ domain/ โ”‚ โ”‚ โ”œโ”€โ”€ dataframe.py # DataFrameRef (DuckDB/Polars) โ”‚ โ”‚ โ”œโ”€โ”€ history.py # Undo/redo/branch history โ”‚ โ”‚ โ”œโ”€โ”€ operations.py # Operations registry โ”‚ โ”‚ โ”œโ”€โ”€ checkpoints.py # Checkpoint persistence โ”‚ โ”‚ โ””โ”€โ”€ validators.py # Validation helpers โ”‚ โ””โ”€โ”€ viz/ โ”‚ โ”œโ”€โ”€ _common.py # Chart utilities โ”‚ โ”œโ”€โ”€ histogram.py # Histogram chart โ”‚ โ”œโ”€โ”€ scatter.py # Scatter plot โ”‚ โ”œโ”€โ”€ bar_topn.py # Top-N bar chart โ”‚ โ”œโ”€โ”€ timeline.py # Timeline/area chart โ”‚ โ”œโ”€โ”€ heatmap.py # Heatmap โ”‚ โ””โ”€โ”€ map.py # Geo map spec โ”‚ โ”œโ”€โ”€ frontend/ โ”‚ โ”œโ”€โ”€ package.json # Frontend dependencies โ”‚ โ”œโ”€โ”€ vite.config.ts # Vite + API proxy config โ”‚ โ”œโ”€โ”€ Dockerfile # Nginx-based frontend build โ”‚ โ”œโ”€โ”€ nginx.conf # Reverse proxy config โ”‚ โ””โ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ api/ # API client & hooks โ”‚ โ”œโ”€โ”€ store/ # Zustand state stores โ”‚ โ”œโ”€โ”€ lib/ # Utilities โ”‚ โ””โ”€โ”€ components/ # React components โ”‚ โ”œโ”€โ”€ datasets/ โ”‚ โ””โ”€โ”€ orders.csv # Demo data โ”‚ โ”œโ”€โ”€ docs/ # Documentation โ”‚ โ””โ”€โ”€ .github/workflows/ # CI/CD pipelines โ”œโ”€โ”€ deploy.yml # CI + GHCR Docker push โ””โ”€โ”€ hf-space-deploy.yml # HF Spaces deploy ``` ## License MIT