---
name: "Sandbox NotebookLM"
client: Oliver Internal
status: active
tech: [Next.js 15, FastAPI, Python 3.13, uv, PostgreSQL, Redis, ElevenLabs, Docker]
local_path: /Users/ai_leed/Documents/Projects/Oliver/sandbox-notebookllamalm-nextjs
deploy: docker compose up --build
url: https://ai-sandbox.oliver.solutions/notebookllama/
server: optical-web-1 at /opt/sandbox-notebookllamalm-nextjs
tags: [oliver, ai, notebooklm, llamaindex, rag, multi-user, nextjs15, elevenlabs]
created: 2026-04-14
last_commit: 2026-04-24
commits: 179
---

## Overview
Enterprise-ready alternative to Google NotebookLM. Multi-user, self-hosted, with AI Studio generators and podcast generation.

**Live:** https://ai-sandbox.oliver.solutions/notebookllama/
**Backend API docs:** https://ai-sandbox.oliver.solutions/notebookllama-back/api/docs
**Repo:** https://bitbucket.org/zlalani/sandbox-notebookllamalm-nextjs

## Tech Stack
- **Frontend:** Next.js 15 App Router + React 19 + TypeScript + Tailwind 4
- **Backend:** FastAPI + Python 3.13 + `uv` package manager
- **Database:** PostgreSQL 18
- **Cache:** Redis 7
- **AI:** LlamaIndex + LLM factory (multi-model)
- **Audio:** ElevenLabs (podcast generation)
- **Auth:** Microsoft SSO + signup/login
- **Infrastructure:** Docker + docker-compose

## Architecture
```
Next.js 15 (App Router)
    src/app/notebooks/[id]/page.tsx  ← main notebook page (~1600 lines)
    src/lib/api.ts                   ← all API calls (axios)
    store/authStore.ts               ← Zustand auth (localStorage)

FastAPI backend
    api/routes/
        auth.py           ← signup, login, Microsoft SSO
        notebooks.py      ← CRUD, synthesis, podcast, Studio
        documents.py      ← upload, task status
        chat.py           ← WebSocket chat
        admin.py          ← admin dashboard
    notebookllama/
        studio_generators.py  ← 7 LLM generators (flashcards, quiz, mindmap, slides, report, infographic, datatable)
        audio.py              ← ElevenLabs podcast (saves to PODCAST_DATA_DIR)
        llm_factory.py        ← get_llm_by_type(), get_structured_llm()
```

## Deployment
- **Server:** `optical-web-1` at `/opt/sandbox-notebookllamalm-nextjs`
- **Run:** `docker compose up --build`
- **Live URL:** https://ai-sandbox.oliver.solutions/notebookllama/

### Deploy Commands (Server)
```bash
git pull origin main
docker compose build backend   # or frontend or both
docker compose up -d

# Rebuild only backend (faster)
docker compose build backend && docker compose up -d backend

# Logs
docker compose logs backend --tail=50
docker compose logs frontend --tail=50
```

## Timeline / Git History
| Date | Change |
|------|--------|
| 2026-04-24 | Fix model IDs, hangs, deploy script, Docker healthchecks |
| 2026-03-31 | Update LLM models to latest versions |
| 2026-03-16 | Fix Studio tiles losing state after chat navigation |
| 2026-03-16 | Replace indigo → brand amber #FFC407 across app |
| 2026-03-15 | Add PPTX-from-template preview + download panel |
| 2026-03-15 | Fix from-template: better filename, style fidelity |
| 2026-03-15 | Increase from-template max_tokens 8192→16000 |
| 2026-03-15 | Pin python-pptx to 0.6.23 |

## Sessions
### 2026-04-24 – How to fix query engine initialization
**Asked:** How to fix query engine initialization error and what needs to be done on the server?
**Done:** Identified wrong markdown file was uploaded (not a code bug), committed language fix, and pushed to git awaiting server deployment.

### 2026-04-24 – Diagnose query engine initialization error and
**Asked:** Diagnose query engine initialization error and establish git workflow rules.
**Done:** Identified metadata handling is correct; root cause was wrong document loaded; committed language fix without server changes.

### 2026-04-24 – Fix query engine initialization error and
**Asked:** Fix query engine initialization error and deploy.sh false failure detection.
**Done:** Identified bash logic bug in deploy.sh lines 108–111 causing false failures when using --backend-only flag; recommended replacing && || pattern with if/fi construct.

### 2026-04-24 – Developer requested confirmation on server deployment
**Asked:** Developer requested confirmation on server deployment steps and established a rule against making server changes without explicit command.
**Done:** Backend changes were committed to git (02fd277) with deployment instructions provided, and a global rule was documented to prevent unauthorized server modifications.

### 2026-04-24 – Asked | Established server deployment rule
**Asked:** Asked | Established server deployment rule and patched tiktoken tokenizer mapping
**Done:** Done | Git commits made and backend redeployed with query engine and tokenizer fixes

### 2026-04-24 – Fix query engine initialization error and
**Asked:** Fix query engine initialization error and establish server deployment rules.
**Done:** Documented global rule to never modify server without explicit command; confirmed code already pushed to Bitbucket.

### 2026-04-24 – Asked | Establish git-first protocol and
**Asked:** Asked | Establish git-first protocol and record preferences
**Done:** Done | Documented no-server-changes rule and saved language/preference settings globally

### 2026-04-24 – Asked for help with query engine
**Asked:** Asked for help with query engine initialization error that persists across tests.
**Done:** Fixed the test by importing `llm_factory` before running the patch, confirming the patch is active.

### 2026-04-24 – Update models, fix hangs, and dockerize
**Asked:** Update models, fix hangs, and dockerize the project with proper deploy script.
**Done:** Increased error logging context, updated docker-compose.yml, and pushed deploy script changes.

### 2026-04-24 – Fix Docker Compose healthchecks and deployment
**Asked:** Fix Docker Compose healthchecks and deployment script to resolve service startup hangs.
**Done:** Updated frontend depends_on condition to service_started and improved healthcheck logic to prevent blocking startup chains.

### 2026-04-24 – Update models, fix hangs, and implement
**Asked:** Update models, fix hangs, and implement Docker with deploy script.
**Done:** Committed TypeScript fixes and pushed updates; deploy script ready to run on server.

### 2026-04-24 – Fix model imports, hangs, and implement
**Asked:** Fix model imports, hangs, and implement Docker with proper deploy script.
**Done:** Identified incomplete monkey-patch in base.py and suppressed Docker build output preventing error visibility.

### 2026-04-24 – Update models and dependencies, investigate hangs,
**Asked:** Update models and dependencies, investigate hangs, and implement Docker with deploy script.
**Done:** Updated multiple packages including Anthropic, LlamaIndex, FastAPI, and other dependencies via uv lock, committed and pushed changes.

### 2026-04-24 – Update models, fix hangs, dockerize project,
**Asked:** Update models, fix hangs, dockerize project, and improve deploy scripts with rollback support.
**Done:** Analyzed project models, reviewed git and deploy scripts, dockerized setup, and fixed rollback.sh.

### 2026-04-24 – Update models, fix hanging issues, and
**Asked:** Update models, fix hanging issues, and implement Docker setup with proper deploy scripts.
**Done:** Added 120s timeout to query engine initialization and 130s timeout to WebSocket handler to prevent hangs; prepared commit with pipeline and chat fixes.

### 2026-04-24 – Investigated project structure, identified model dependencies,
**Asked:** Investigated project structure, identified model dependencies, and fixed hanging issues with timeouts.
**Done:** Added asyncio timeouts to pipeline_manager.py and chat.py WebSocket handlers, plus timeout protection for background tasks.

### 2026-04-14 – Project catalogued
**Done:** Added to Obsidian second brain with full details.

---
## Change Log
| Date | Requested | Changed | Files |
|------|-----------|---------|-------|
| 2026-04-24 | Query engine error fix | Language fix committed, wrong file identified as root cause | commit 282b1c4 |
| 2026-04-24 | Query engine error diagnosis | Verified metadata handling, identified wrong document source | (commits pushed, no file changes specified) |
| 2026-04-24 | Deploy script fix | Replace && || logic with if/fi in health checks | deploy.sh |
| 2026-04-24 | Query engine initialization fix | Patched tiktoken model tokenizer map in llm_factory.py, committed changes | llm_factory.py |
| 2026-04-24 | Query engine & tokenizer fix | Add hardcoded model→tokenizer map patch, establish no-server-changes-without-approval rule | llm_factory.py |
| 2026-04-24 | Query engine error, deployment rules | Added no-server-modification rule to ~/.claude/CLAUDE.md, set Russian language preference | ~/.claude/CLAUDE.md |
| 2026-04-24 | Git protocol setup | Added global rule (no server changes without approval), recorded language preference | .obsidian/settings.json, global-rules.md |
| 2026-04-24 | Query engine fix | Add llm_factory import, verify patch activation | test_file.py |
| 2026-04-24 | Dockerization and deploy | docker-compose.yml, on_error logging, deploy.sh | docker-compose.yml, scripts/deploy.sh |
| 2026-04-24 | Docker deployment | depends_on condition changed to service_started, healthcheck logic improved | docker-compose.yml |
| 2026-04-24 | Model/Docker setup | TypeScript errors fixed, deploy script verified | base.py, deploy.sh |
| 2026-04-24 | Dockerization setup | Monkey-patch anthropic_modelname_to_contextsize in base.py and utils.py, Show Docker build output in deploy.sh | base.py, utils.py, deploy.sh |
| 2026-04-24 | Package updates | anthropic 0.71.0→0.97.0, llama-index-llms-anthropic 0.9.6→0.11.3, fastapi 0.119.0→0.136.1, uvicorn 0.37.0→0.46.0, elevenlabs 2.18.0→2.44.0, google-genai 1.67.0→1.73.1 | pyproject.toml, uv.lock |
| 2026-04-24 | Dockerization & deployment | Docker setup, deploy script, rollback.sh, model updates | Dockerfile, docker-compose.yml, deploy.sh, rollback.sh |
| 2026-04-24 | Infrastructure updates | Query engine timeout (120s), WebSocket handler timeout (130s), background task fixes | pipeline_manager.py, chat.py, background_tasks.py |
| 2026-04-24 | Model investigation & hangs fix | asyncio.wait_for timeouts (120s/130s), error handling in WS | pipeline_manager.py, chat.py, background_tasks.py |
| 2026-03-16 | Brand color update | Indigo → amber #FFC407 | global styles |
| 2026-03-15 | PPTX from template | New from-template workflow | notebooks.py, frontend |

## Related
- [[enterprise-ai-hub-nexus/Enterprise AI Hub Nexus]]
- [[cinema-studio-pro/Cinema Studio Pro]] (same ai-sandbox.oliver.solutions server)
- [[Oliver-ai-bot_2.0/Oliver AI Bot 2.0]]
