Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

Add Docker infrastructure for DeepTutor, including multi-stage Dockerfile, docker-compose configurations (dev/prod), `.dockerignore`, and environment documentation in README.

andres4budly6fa86b1f6c42
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 000000000..df03d5e31
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,139 @@
+# ============================================
+# DeepTutor Docker Ignore File
+# ============================================
+# Excludes files and directories from the Docker build context
+# to improve build speed and reduce image size
+# ============================================
+
+# ============================================
+# Git
+# ============================================
+.git
+.gitignore
+.gitattributes
+
+# ============================================
+# Documentation
+# ============================================
+*.md
+!README.md
+docs/
+assets/gifs/
+assets/figs/
+assets/README/
+
+# ============================================
+# Python
+# ============================================
+__pycache__/
+**/__pycache__/
+*.py[cod]
+*$py.class
+*.so
+*.egg
+*.egg-info/
+.eggs/
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+*.egg-info/
+.installed.cfg
+MANIFEST
+
+# Virtual environments
+.env
+*.env
+!.env.example
+env/
+venv/
+ENV/
+.venv/
+env.bak/
+venv.bak/
+DeepTutor.env
+
+# Pytest cache
+.pytest_cache/
+.coverage
+htmlcov/
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# ============================================
+# Node.js
+# ============================================
+node_modules/
+**/node_modules/
+web/node_modules/
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+
+# Next.js
+.next/
+web/.next/
+out/
+web/out/
+
+# ============================================
+# IDE and Editor
+# ============================================
+.idea/
+.vscode/
+*.swp
+*.swo
+*~
+.DS_Store
+
+# ============================================
+# Docker
+# ============================================
+Dockerfile*
+docker-compose*.yml
+.docker/
+.dockerignore
+
+# ============================================
+# User Data (will be mounted as volumes)
+# ============================================
+data/user/
+data/knowledge_bases/
+run_code_workspace/
+
+# ============================================
+# Development and Testing
+# ============================================
+develop/
+scripts/extract_numbered_items.sh
+*.log
+logs/
+*.bak
+*.tmp
+
+# ============================================
+# Temporary and Cache Files
+# ============================================
+.cache/
+cache/
+**/cache/
+tmp/
+temp/
+*.tmp
+*.temp
+
+# ============================================
+# License and Communication
+# ============================================
+LICENSE
+Communication.md
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 000000000..cd6428b4e
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,258 @@
+# ============================================
+# DeepTutor Multi-Stage Dockerfile
+# ============================================
+# This Dockerfile builds a production-ready image for DeepTutor
+# containing both the FastAPI backend and Next.js frontend
+#
+# Build: docker build -t deeptutor .
+# Run: docker run -p 8001:8001 -p 3782:3782 --env-file .env deeptutor
+# ============================================
+
+# ============================================
+# Stage 1: Frontend Builder
+# ============================================
+FROM node:20-alpine AS frontend-builder
+
+WORKDIR /app/web
+
+# Copy package files first for better caching
+COPY web/package.json web/package-lock.json* ./
+
+# Install dependencies
+RUN npm ci --legacy-peer-deps
+
+# Copy frontend source code
+COPY web/ ./
+
+# Build the Next.js application
+# Create a placeholder .env.local for build (will be overridden at runtime)
+RUN echo "NEXT_PUBLIC_API_BASE=http://localhost:8001" > .env.local
+
+# Build Next.js for production
+RUN npm run build
+
+# ============================================
+# Stage 2: Python Base with Dependencies
+# ============================================
+FROM python:3.11-slim AS python-base
+
+# Set environment variables
+ENV PYTHONDONTWRITEBYTECODE=1 \
+ PYTHONUNBUFFERED=1 \
+ PYTHONIOENCODING=utf-8 \
+ PIP_NO_CACHE_DIR=1 \
+ PIP_DISABLE_PIP_VERSION_CHECK=1
+
+WORKDIR /app
+
+# Install system dependencies
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ curl \
+ git \
+ build-essential \
+ && rm -rf /var/lib/apt/lists/*
+
+# Copy requirements and install Python dependencies
+COPY requirements.txt ./
+RUN pip install --upgrade pip && \
+ pip install -r requirements.txt
+
+# ============================================
+# Stage 3: Production Image
+# ============================================
+FROM python:3.11-slim AS production
+
+# Labels
+LABEL maintainer="DeepTutor Team" \
+ description="DeepTutor: AI-Powered Personalized Learning Assistant" \
+ version="0.1.0"
+
+# Set environment variables
+ENV PYTHONDONTWRITEBYTECODE=1 \
+ PYTHONUNBUFFERED=1 \
+ PYTHONIOENCODING=utf-8 \
+ NODE_ENV=production \
+ # Default ports (can be overridden)
+ BACKEND_PORT=8001 \
+ FRONTEND_PORT=3782
+
+WORKDIR /app
+
+# Install Node.js 20.x (LTS) and npm
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ curl \
+ ca-certificates \
+ gnupg \
+ supervisor \
+ && mkdir -p /etc/apt/keyrings \
+ && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
+ && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
+ && apt-get update \
+ && apt-get install -y nodejs \
+ && rm -rf /var/lib/apt/lists/* \
+ && npm --version
+
+# Copy Python packages from builder stage
+COPY --from=python-base /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
+COPY --from=python-base /usr/local/bin /usr/local/bin
+
+# Copy built frontend from frontend-builder stage
+COPY --from=frontend-builder /app/web/.next ./web/.next
+COPY --from=frontend-builder /app/web/public ./web/public
+COPY --from=frontend-builder /app/web/package.json ./web/package.json
+COPY --from=frontend-builder /app/web/next.config.js ./web/next.config.js
+COPY --from=frontend-builder /app/web/node_modules ./web/node_modules
+
+# Create a startup script for the frontend
+RUN echo '#!/bin/bash\ncd /app/web && exec node node_modules/next/dist/bin/next start -H 0.0.0.0 -p ${FRONTEND_PORT:-3782}' > /app/start-frontend.sh && \
+ chmod +x /app/start-frontend.sh
+
+# Copy application source code
+COPY src/ ./src/
+COPY config/ ./config/
+COPY scripts/ ./scripts/
+COPY pyproject.toml ./
+COPY requirements.txt ./
+
+# Create necessary directories
+RUN mkdir -p \
+ data/user/solve \
+ data/user/question \
+ data/user/research/cache \
+ data/user/research/reports \
+ data/user/guide \
+ data/user/notebook \
+ data/user/co-writer/audio \
+ data/user/co-writer/tool_calls \
+ data/user/logs \
+ data/user/run_code_workspace \
+ data/user/performance \
+ data/knowledge_bases
+
+# Create supervisord configuration for running both services
+RUN mkdir -p /etc/supervisor/conf.d
+
+COPY <<EOF /etc/supervisor/conf.d/deeptutor.conf
+[supervisord]
+nodaemon=true
+logfile=/var/log/supervisor/supervisord.log
+pidfile=/var/run/supervisord.pid
+childlogdir=/var/log/supervisor
+
+[program:backend]
+command=python -m uvicorn src.api.main:app --host 0.0.0.0 --port %(ENV_BACKEND_PORT)s
+directory=/app
+autostart=true
+autorestart=true
+stderr_logfile=/var/log/supervisor/backend.err.log
+stdout_logfile=/var/log/supervisor/backend.out.log
+environment=PYTHONPATH="/app",PYTHONUNBUFFERED="1"
+
+[program:frontend]
+command=/bin/bash /app/start-frontend.sh
+directory=/app/web
+autostart=true
+autorestart=true
+startsecs=5
+stderr_logfile=/var/log/supervisor/frontend.err.log
+stdout_logfile=/var/log/supervisor/frontend.out.log
+environment=NODE_ENV="production"
+EOF
+
+# Create log directories
+RUN mkdir -p /var/log/supervisor
+
+# Create entrypoint script
+COPY <<'EOF' /app/entrypoint.sh
+#!/bin/bash
+set -e
+
+echo "============================================"
+echo "πŸš€ Starting DeepTutor"
+echo "============================================"
+
+# Set default ports if not provided
+export BACKEND_PORT=${BACKEND_PORT:-8001}
+export FRONTEND_PORT=${FRONTEND_PORT:-3782}
+
+# Update Next.js environment file with actual backend URL
+echo "NEXT_PUBLIC_API_BASE=http://localhost:${BACKEND_PORT}" > /app/web/.env.local
+
+# If NEXT_PUBLIC_API_BASE is provided externally, use it
+if [ -n "$NEXT_PUBLIC_API_BASE_EXTERNAL" ]; then
+ echo "NEXT_PUBLIC_API_BASE=${NEXT_PUBLIC_API_BASE_EXTERNAL}" > /app/web/.env.local
+fi
+
+echo "πŸ“Œ Backend Port: ${BACKEND_PORT}"
+echo "πŸ“Œ Frontend Port: ${FRONTEND_PORT}"
+echo "============================================"
+
+# Check for required environment variables
+if [ -z "$LLM_BINDING_API_KEY" ]; then
+ echo "⚠️ Warning: LLM_BINDING_API_KEY not set"
+ echo " Please provide LLM configuration via environment variables"
+fi
+
+# Start supervisord
+exec /usr/bin/supervisord -c /etc/supervisor/conf.d/deeptutor.conf
+EOF
+
+RUN chmod +x /app/entrypoint.sh
+
+# Expose ports
+EXPOSE 8001 3782
+
+# Health check
+HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
+ CMD curl -f http://localhost:${BACKEND_PORT:-8001}/ || exit 1
+
+# Set entrypoint
+ENTRYPOINT ["/app/entrypoint.sh"]
+
+# ============================================
+# Stage 4: Development Image (Optional)
+# ============================================
+FROM production AS development
+
+# Install development tools
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ vim \
+ git \
+ && rm -rf /var/lib/apt/lists/*
+
+# Install development Python packages
+RUN pip install --no-cache-dir \
+ pre-commit \
+ black \
+ ruff
+
+# Override supervisord config for development (with reload)
+COPY <<EOF /etc/supervisor/conf.d/deeptutor.conf
+[supervisord]
+nodaemon=true
+logfile=/var/log/supervisor/supervisord.log
+pidfile=/var/run/supervisord.pid
+childlogdir=/var/log/supervisor
+
+[program:backend]
+command=python -m uvicorn src.api.main:app --host 0.0.0.0 --port %(ENV_BACKEND_PORT)s --reload
+directory=/app
+autostart=true
+autorestart=true
+stderr_logfile=/var/log/supervisor/backend.err.log
+stdout_logfile=/var/log/supervisor/backend.out.log
+environment=PYTHONPATH="/app",PYTHONUNBUFFERED="1"
+
+[program:frontend]
+command=/bin/bash -c "cd /app/web && node node_modules/next/dist/bin/next dev -H 0.0.0.0 -p ${FRONTEND_PORT:-3782}"
+directory=/app/web
+autostart=true
+autorestart=true
+startsecs=5
+stderr_logfile=/var/log/supervisor/frontend.err.log
+stdout_logfile=/var/log/supervisor/frontend.out.log
+environment=NODE_ENV="development"
+EOF
+
+# Development ports
+EXPOSE 8001 3782
diff --git a/README.md b/README.md
index 0b348fc46..7e57c713f 100644
--- a/README.md
+++ b/README.md
@@ -351,7 +351,119 @@ Create custom knowledge bases through the web interface with support for multipl
---
-## πŸ“‚ Data Storage
+## οΏ½ Docker Deployment
+
+DeepTutor can be easily deployed using Docker, which bundles both the FastAPI backend and Next.js frontend in a single container.
+
+### Prerequisites
+
+- [Docker](https://docs.docker.com/get-docker/) installed
+- [Docker Compose](https://docs.docker.com/compose/install/) (included with Docker Desktop)
+
+### Quick Start with Docker
+
+```bash
+# 1. Clone the repository
+git clone https://github.com/HKUDS/DeepTutor.git
+cd DeepTutor
+
+# 2. Copy environment template and configure your API keys
+cp .env.example .env
+# Edit .env with your LLM API keys (LLM_BINDING_API_KEY, LLM_MODEL, LLM_BINDING_HOST)
+
+# 3. Build and run with Docker Compose
+docker compose up --build
+
+# 4. Access the application
+# Frontend: http://localhost:3782
+# Backend API: http://localhost:8001
+# API Docs: http://localhost:8001/docs
+```
+
+### Docker Compose Commands
+
+```bash
+# Start in detached mode (background)
+docker compose up -d
+
+# View logs
+docker compose logs -f
+
+# Stop services
+docker compose down
+
+# Rebuild after code changes
+docker compose up --build
+
+# Development mode with hot-reload
+docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build
+```
+
+### Environment Variables
+
+Configure the following environment variables in your `.env` file:
+
+| Variable | Required | Description |
+|:---|:---:|:---|
+| `LLM_BINDING` | No | LLM provider (default: `openai`) |
+| `LLM_MODEL` | **Yes** | Model name (e.g., `gpt-4o`, `gpt-4-turbo`) |
+| `LLM_BINDING_API_KEY` | **Yes** | Your LLM API key |
+| `LLM_BINDING_HOST` | **Yes** | API endpoint URL |
+| `BACKEND_PORT` | No | Backend port (default: `8001`) |
+| `FRONTEND_PORT` | No | Frontend port (default: `3782`) |
+| `TTS_MODEL` | No | Text-to-Speech model |
+| `TTS_API_KEY` | No | TTS API key |
+| `TTS_URL` | No | TTS API endpoint |
+
+### Data Persistence
+
+Docker volumes are used to persist user data and knowledge bases:
+
+```yaml
+volumes:
+ - deeptutor_user_data:/app/data/user
+ - deeptutor_knowledge_bases:/app/data/knowledge_bases
+```
+
+To use local directories instead (for easier access to files):
+
+```bash
+# Create local data directories
+mkdir -p data/user data/knowledge_bases
+
+# Run with local volume mounts
+docker compose -f docker-compose.yml -f docker-compose.dev.yml up
+```
+
+### Building Custom Images
+
+```bash
+# Build production image
+docker build -t deeptutor:latest .
+
+# Build development image
+docker build --target development -t deeptutor:dev .
+
+# Run standalone container
+docker run -p 8001:8001 -p 3782:3782 --env-file .env deeptutor:latest
+```
+
+### Docker Architecture
+
+The Dockerfile uses a multi-stage build for optimized images:
+
+| Stage | Purpose |
+|:---|:---|
+| `frontend-builder` | Builds Next.js frontend with npm |
+| `python-base` | Installs Python dependencies |
+| `production` | Final production image with supervisord |
+| `development` | Development image with hot-reload support |
+
+Both services (backend + frontend) run in a single container managed by **supervisord**.
+
+---
+
+## οΏ½πŸ“‚ Data Storage
All user content and system data are stored in the `data/` directory:
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
new file mode 100644
index 000000000..5621efdf6
--- /dev/null
+++ b/docker-compose.dev.yml
@@ -0,0 +1,28 @@
+# ============================================
+# DeepTutor Docker Compose - Development Override
+# ============================================
+# Use with: docker compose -f docker-compose.yml -f docker-compose.dev.yml up
+# ============================================
+
+services:
+ deeptutor:
+ build:
+ target: development
+ volumes:
+ # Mount source code for hot-reload
+ - ./src:/app/src:ro
+ - ./config:/app/config:ro
+ - ./web/app:/app/web/app:ro
+ - ./web/components:/app/web/components:ro
+ - ./web/lib:/app/web/lib:ro
+ - ./web/hooks:/app/web/hooks:ro
+ - ./web/context:/app/web/context:ro
+ - ./web/types:/app/web/types:ro
+ - ./web/public:/app/web/public:ro
+ # Persist user data (writable)
+ - ./data/user:/app/data/user
+ - ./data/knowledge_bases:/app/data/knowledge_bases
+ environment:
+ - NODE_ENV=development
+ networks:
+ - deeptutor-network
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 000000000..84513a015
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,83 @@
+# ============================================
+# DeepTutor Docker Compose Configuration
+# ============================================
+# This file provides orchestration for DeepTutor services
+#
+# Usage:
+# Development: docker compose up
+# Production: docker compose -f docker-compose.yml -f docker-compose.prod.yml up
+# Build only: docker compose build
+# ============================================
+
+services:
+ # ============================================
+ # All-in-One DeepTutor Service
+ # ============================================
+ deeptutor:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ target: production
+ container_name: deeptutor
+ restart: unless-stopped
+ ports:
+ - "${BACKEND_PORT:-8001}:8001"
+ - "${FRONTEND_PORT:-3782}:3782"
+ environment:
+ # LLM Configuration (Required)
+ - LLM_BINDING=${LLM_BINDING:-openai}
+ - LLM_MODEL=${LLM_MODEL}
+ - LLM_BINDING_API_KEY=${LLM_BINDING_API_KEY}
+ - LLM_BINDING_HOST=${LLM_BINDING_HOST}
+ - DISABLE_SSL_VERIFY=${DISABLE_SSL_VERIFY:-false}
+ # Embedding Configuration (Required for Knowledge Base)
+ - EMBEDDING_BINDING=${EMBEDDING_BINDING:-openai}
+ - EMBEDDING_MODEL=${EMBEDDING_MODEL:-text-embedding-3-large}
+ - EMBEDDING_BINDING_API_KEY=${EMBEDDING_BINDING_API_KEY}
+ - EMBEDDING_BINDING_HOST=${EMBEDDING_BINDING_HOST}
+ - EMBEDDING_DIM=${EMBEDDING_DIM:-3072}
+ - EMBEDDING_MAX_TOKENS=${EMBEDDING_MAX_TOKENS:-8192}
+ # TTS Configuration (Optional)
+ - TTS_MODEL=${TTS_MODEL:-}
+ - TTS_API_KEY=${TTS_API_KEY:-}
+ - TTS_URL=${TTS_URL:-}
+ - TTS_VOICE=${TTS_VOICE:-alloy}
+ # Web Search Configuration (Optional)
+ - PERPLEXITY_API_KEY=${PERPLEXITY_API_KEY:-}
+ # Logging Configuration
+ - RAG_TOOL_MODULE_LOG_LEVEL=${RAG_TOOL_MODULE_LOG_LEVEL:-INFO}
+ # Service Ports
+ - BACKEND_PORT=${BACKEND_PORT:-8001}
+ - FRONTEND_PORT=${FRONTEND_PORT:-3782}
+ # External API URL (for browser access if different from localhost)
+ - NEXT_PUBLIC_API_BASE_EXTERNAL=${NEXT_PUBLIC_API_BASE_EXTERNAL:-}
+ volumes:
+ # Persist user data and knowledge bases
+ - deeptutor_user_data:/app/data/user
+ - deeptutor_knowledge_bases:/app/data/knowledge_bases
+ # Optional: Mount custom config
+ # - ./config:/app/config:ro
+ healthcheck:
+ test: ["CMD", "curl", "-f", "http://localhost:8001/"]
+ interval: 30s
+ timeout: 10s
+ retries: 3
+ start_period: 60s
+ networks:
+ - deeptutor-network
+
+# ============================================
+# Named Volumes for Data Persistence
+# ============================================
+volumes:
+ deeptutor_user_data:
+ driver: local
+ deeptutor_knowledge_bases:
+ driver: local
+
+# ============================================
+# Networks
+# ============================================
+networks:
+ deeptutor-network:
+ driver: bridge