Skip to main content

Backend Configuration

The backend uses environment variables for API keys, database, and AWS configuration.

Create Backend .env File

Create a .env file in the sprout-backend/ directory:
cd sprout-backend
touch .env

Required Environment Variables

# Anthropic API Key (Required)
ANTHROPIC_API_KEY=your_anthropic_api_key_here

# AWS Configuration (Required for document uploads)
AWS_ACCESS_KEY_ID=your_aws_access_key
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
AWS_REGION=us-east-1
AWS_S3_BUCKET=your-bucket-name

# Database Configuration (Optional)
DB_PATH=./sprout.db

# Server Configuration (Optional)
PORT=8000

Configuration Details

ANTHROPIC_API_KEY (Required)The backend uses Claude for seven autonomous agents:
  • Topic Agent
  • Subconcept Bootstrap Agent
  • Concept Refinement Agent
  • Tutor Chat Agent
  • Grade Answers Agent
  • Generate Diagnostic Agent
  • Review Learning Path Agent
Get your API key from the Anthropic Console.
Without this key, agent-powered features (topic generation, diagnostics, tutoring) will not work.

Frontend Configuration

The frontend uses environment variables to connect to the backend and configure feature flags.

Create Frontend .env.local File

Create a .env.local file in the sprout-frontend/ directory:
cd sprout-frontend
touch .env.local

Required Environment Variables

# Backend API URL (Required)
NEXT_PUBLIC_BACKEND_ORIGIN=http://localhost:8000

# Backend Proxy Prefix (Required)
NEXT_PUBLIC_BACKEND_PROXY_PREFIX=/backend-api

# Agent Mode (Optional)
NEXT_PUBLIC_SMALL_AGENTS=false

Configuration Details

NEXT_PUBLIC_BACKEND_ORIGIN (Required)The URL where your Express backend is running. Used for Server-Sent Events (SSE) streaming.
# Local development
NEXT_PUBLIC_BACKEND_ORIGIN=http://localhost:8000

# Production
NEXT_PUBLIC_BACKEND_ORIGIN=https://api.sprout.example.com
The frontend bypasses the Next.js proxy for SSE connections and connects directly to this origin.

Hand Tracking Configuration

The Python hand tracking service runs on a fixed port and connects via WebSocket.

Default Configuration

SettingValueNotes
Port8765Avoids conflict with Node.js backend (8000)
ProtocolWebSocketws://localhost:8765
Camera Index0Default webcam
Frame Rate60 fpsCapped to prevent queue buildup
Model Complexity0Lightest/fastest MediaPipe model

Customizing Hand Tracking

Edit backend.py to customize settings:
# Change camera index for multiple cameras
cap = cv2.VideoCapture(1)  # Use camera 1 instead of 0

# Adjust hand detection parameters
hands = mp_hands.Hands(
    max_num_hands=2,
    model_complexity=0,              # 0=fast, 1=accurate
    min_detection_confidence=0.7,    # Lower = more sensitive
    min_tracking_confidence=0.8,     # Higher = less jitter
)

# Change WebSocket port
async def main():
    async with websockets.serve(handler, "localhost", 8765):
        # Change 8765 to your preferred port

Configuration Validation

Verify your configuration is correct:
1

Check Backend Environment

cd sprout-backend
cat .env
Ensure ANTHROPIC_API_KEY is set.
2

Check Frontend Environment

cd sprout-frontend
cat .env.local
Ensure NEXT_PUBLIC_BACKEND_ORIGIN matches your backend URL.
3

Test Backend Health

Start the backend and check the health endpoint:
cd sprout-backend
npm run dev
Visit http://localhost:8000/api/health - you should see:
{"status":"ok","timestamp":"2024-..."}

Common Issues

The backend will fail to start or agent routes will return 500 errors.Solution: Add your Anthropic API key to .env:
ANTHROPIC_API_KEY=sk-ant-...
AWS credentials are missing or incorrect.Solution: Verify your AWS credentials and bucket name:
AWS_ACCESS_KEY_ID=AKIA...
AWS_SECRET_ACCESS_KEY=wJalr...
AWS_S3_BUCKET=your-bucket-name
Test with AWS CLI:
aws s3 ls s3://your-bucket-name
CORS error or connection refused.Solution: Check that:
  1. Backend is running on the correct port
  2. NEXT_PUBLIC_BACKEND_ORIGIN matches the backend URL
  3. Backend has CORS enabled (enabled by default in src/index.ts)

Next Steps

Running Locally

Start all three services in development mode

Database Migrations

Initialize the SQLite database schema

Build docs developers (and LLMs) love