CodeMotion is a full-stack web application that allows users to create mathematical animations and data visualizations using natural language. Simply describe what you want to see, and CodeMotion generates Manim Python code, renders it into high-quality videos, and displays them in an interactive interface.
- Natural Language to Code: Describe animations in plain English, and AI generates Manim Python code
- Real-time Video Generation: Cloud-based rendering produces 1080p/4K videos in seconds
- Interactive Project Workspace: Resizable sidebar with chat interface for iterative refinement
- Video Preview: Built-in video player with play/pause, scrubbing, and time controls
- Code Validation: Automatic sanitization and validation of generated code for security
- Google OAuth Sign-in: Seamless authentication via Supabase
- JWT Token-based Auth: Secure API access with token verification
- User Profile Display: Shows username/name in navigation
- Responsive Design: Works on desktop and mobile devices
- Resizable Sidebar: Users can adjust sidebar width to their preference
- Gradient Background: Beautiful animated gradient background
- Smooth Animations: Framer Motion powered transitions
- Dark Theme: Modern dark UI with accent colors
- Framework: Next.js 16 with App Router
- Language: TypeScript
- Styling: Tailwind CSS 4
- State Management: React Context API (AuthContext)
- Animations: Framer Motion
- Icons: Lucide React
- Authentication: Supabase Auth with SSR support
- Framework: FastAPI (Python)
- AI Integration: Google Generative AI (Gemini)
- Video Rendering: Docker-based Manim execution
- Storage: Supabase Storage for video hosting
- Authentication: Supabase JWT verification
new-test/
├── frontend/ # Next.js frontend application
│ ├── components/
│ │ └── landing/ # Landing page components
│ │ ├── AuthModal.tsx # Authentication modal
│ │ ├── Features.tsx # Features section
│ │ ├── Hero.tsx # Hero section with input
│ │ ├── HowItWorks.tsx # How it works section
│ │ ├── Navbar.tsx # Navigation bar
│ │ ├── Pricing.tsx # Pricing section
│ │ └── Showcase.tsx # Project showcase
│ ├── src/
│ │ ├── app/
│ │ │ ├── auth/
│ │ │ │ └── callback/ # OAuth callback handler
│ │ │ ├── project/ # Project workspace page
│ │ │ ├── layout.tsx # Root layout with AuthProvider
│ │ │ └── page.tsx # Landing page
│ │ ├── contexts/
│ │ │ └── AuthContext.tsx # Authentication context
│ │ └── lib/
│ │ ├── api/
│ │ │ └── client.ts # API client utilities
│ │ └── supabase/
│ │ ├── client.ts # Browser Supabase client
│ │ └── server.ts # Server Supabase client
│ └── public/ # Static assets
│
└── backend/ # FastAPI backend application
├── controllers/ # Business logic
│ ├── auth_controller.py
│ ├── generation_controller.py
│ ├── render_controller.py
│ └── validation_controller.py
├── middlewares/ # Middleware functions
│ └── auth.py # JWT authentication
├── models/ # Data models
│ └── schemas.py # Pydantic schemas
├── routes/ # API routes
│ ├── generation.py # Code generation endpoints
│ ├── protected.py # Protected endpoints
│ ├── rendering.py # Video rendering endpoints
│ └── validation.py # Code validation endpoints
├── utils/ # Utility functions
│ └── supabase_client.py
├── generated_scripts/ # Generated Manim scripts
├── generated_videos/ # Rendered video files
├── main.py # FastAPI application entry
└── requirements.txt # Python dependencies
- Node.js 18+ and npm
- Python 3.10+
- Docker (for Manim rendering)
- Supabase Account (for authentication and storage)
- Google Cloud Account (for Generative AI API)
git clone <repository-url>
cd new-testcd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtcd frontend
# Install dependencies
npm install# Supabase Configuration
SUPABASE_URL=your_supabase_project_url
SUPABASE_KEY=your_supabase_anon_key
SERVICE_ROLE_KEY=your_supabase_service_role_key
SUPABASE_BUCKET=videos
# Google Generative AI
GENAI_API_KEY=your_google_genai_api_key
# Optional: JWT Verification (for faster token validation)
SUPABASE_JWT_SECRET=your_jwt_secret
SUPABASE_AUD=your_audience# Supabase Configuration
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
# Backend API URL
NEXT_PUBLIC_API_URL=http://localhost:8008-
Create a Supabase Project at supabase.com
-
Enable Google OAuth:
- Go to Authentication → Providers
- Enable Google provider
- Add your Google OAuth credentials
- Set redirect URL:
http://localhost:3000/auth/callback
-
Create Storage Bucket:
- Go to Storage
- Create a new bucket named
videos(or match yourSUPABASE_BUCKETenv var) - Make it public so videos can be accessed via URL
- Configure CORS if needed
-
Get API Keys:
- Project Settings → API
- Copy
URL→NEXT_PUBLIC_SUPABASE_URLandSUPABASE_URL - Copy
anon publickey →NEXT_PUBLIC_SUPABASE_ANON_KEYandSUPABASE_KEY - Copy
service_rolekey →SERVICE_ROLE_KEY
- Create a Google Cloud Project
- Enable Generative AI API
- Create API Key:
- Go to APIs & Services → Credentials
- Create API Key
- Copy to
GENAI_API_KEY
The backend uses Docker to run Manim in an isolated environment. Ensure Docker is running:
# Build the Manim Docker image (if not already built)
docker build -t manim-image:latest -f backend/Dockerfile .cd backend
source venv/bin/activate # On Windows: venv\Scripts\activate
uvicorn main:app --reload --host 0.0.0.0 --port 8008Backend will be available at http://localhost:8008
cd frontend
npm run devFrontend will be available at http://localhost:3000
cd frontend
npm run build
npm startcd backend
uvicorn main:app --host 0.0.0.0 --port 8008http://localhost:8008
POST /api/generate-and-render
- Description: Generate Manim code from prompt and render video
- Auth: Optional (Bearer token)
- Request Body:
{ "prompt": "Create a rotating 3D cube", "scene_class": "GeneratedScene", "quality": "low", "filename": "script.py", "max_retries": 2 } - Response:
{ "success": true, "filename": "script.py", "local_path": "/path/to/video.mp4", "supabase_url": "https://...", "code": "from manim import *\n...", "sanitized_code": "...", "error": null, "logs": {} }
POST /api/generate
- Description: Generate Manim code from prompt (no rendering)
- Request Body:
{ "prompt": "Create a rotating 3D cube" }
POST /api/render
- Description: Render existing Manim code to video
- Request Body:
{ "code": "from manim import *\n...", "scene_class": "GeneratedScene", "quality": "low", "filename": "script.py" }
POST /api/validate
- Description: Validate and sanitize Manim code
- Request Body:
{ "code": "from manim import *\n..." }
GET /api/me
- Description: Get current user information
- Headers:
Authorization: Bearer <token> - Response:
{ "id": "user-id", "email": "user@example.com", "role": "authenticated", "raw": {...} }
GET /api/admin-only
- Description: Admin-only endpoint (example)
- Headers:
Authorization: Bearer <token>
GET /debug/supabase
- Description: Check Supabase configuration
- Response: Configuration status
GET /
- Description: Health check
- Response:
{"msg": "ok"}
- User clicks "Sign in with Google" on frontend
- Redirects to Google OAuth for authentication
- Google redirects back to
/auth/callbackwith code - Frontend exchanges code for session via Supabase
- Access token stored in session
- API requests include
Authorization: Bearer <token>header - Backend verifies token using Supabase JWT verification
- User authenticated and can access protected endpoints
- Hero Section: Main input field for animation prompts
- Features Section: Key features showcase
- How It Works: Step-by-step explanation
- Pricing: Subscription plans
- Showcase: Community projects gallery
- Resizable Sidebar: Drag to adjust width (280px - 800px)
- Chat Interface: Interactive conversation with AI
- Video Player: Full-featured video preview
- Code View: Toggle between preview and code (coming soon)
- Mobile-friendly navigation
- Adaptive layouts
- Touch-friendly controls
- User submits prompt via frontend
- Frontend calls
/api/generate-and-renderwith prompt - Backend uses Google Generative AI to generate Manim code
- Code is validated and sanitized for security
- Code is executed in Docker container with Manim
- Video is rendered and uploaded to Supabase Storage
- Public URL is returned to frontend
- Frontend displays video in project workspace
- Code Sanitization: Removes dangerous imports and functions
- Docker Isolation: Manim runs in isolated container
- JWT Verification: Secure token-based authentication
- CORS Protection: Configured for specific origins
- Components in
components/directory - Pages in
src/app/directory - Context providers in
src/contexts/ - Utilities in
src/lib/
- Routes in
routes/directory - Controllers in
controllers/directory - Middleware in
middlewares/directory - Models in
models/directory
"Failed to fetch" error
- Check if backend is running on port 8008
- Verify CORS configuration in
backend/main.py - Check network tab in browser dev tools
"Bucket not found" error
- Ensure Supabase bucket named
videosexists - Make sure bucket is set to public
- Verify
SUPABASE_BUCKETenvironment variable
Video not loading
- Check Supabase bucket CORS settings
- Verify video URL is accessible
- Check browser console for errors
Authentication not working
- Verify Supabase environment variables
- Check Google OAuth redirect URL matches
- Ensure callback route is accessible
Docker errors
- Ensure Docker is running
- Check Manim Docker image is built
- Verify Docker has necessary permissions
Vercel is the recommended platform for Next.js applications:
-
Install Vercel CLI (optional):
npm i -g vercel
-
Deploy via Vercel Dashboard:
- Go to vercel.com
- Click "New Project"
- Import your Git repository
- Set root directory to
frontend - Add environment variables:
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYNEXT_PUBLIC_API_URL(your backend URL)
- Click "Deploy"
-
Deploy via CLI:
cd frontend vercel -
Update Supabase Redirect URL:
- Go to Supabase Dashboard → Authentication → URL Configuration
- Add your Vercel domain to "Redirect URLs":
https://your-app.vercel.app/auth/callback
-
Build Configuration (
netlify.tomlinfrontend/):[build] command = "npm run build" publish = ".next" [[redirects]] from = "/*" to = "/index.html" status = 200
-
Deploy:
- Connect repository to Netlify
- Set build directory to
frontend - Add environment variables
- Deploy
-
Build the application:
cd frontend npm run build -
Start production server:
npm start
-
Use PM2 for process management:
npm install -g pm2 pm2 start npm --name "CodeMotion-frontend" -- start pm2 save pm2 startup -
Set up Nginx reverse proxy:
server { listen 80; server_name your-domain.com; location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }
Railway supports Docker and is great for FastAPI apps:
-
Create
railway.jsoninbackend/:{ "$schema": "https://railway.app/railway.schema.json", "build": { "builder": "DOCKERFILE", "dockerfilePath": "Dockerfile" }, "deploy": { "startCommand": "uvicorn main:app --host 0.0.0.0 --port $PORT", "restartPolicyType": "ON_FAILURE", "restartPolicyMaxRetries": 10 } } -
Deploy:
- Go to railway.app
- New Project → Deploy from GitHub
- Select your repository
- Set root directory to
backend - Add environment variables
- Deploy
-
Create
render.yamlin root:services: - type: web name: CodeMotion-backend env: python buildCommand: pip install -r requirements.txt startCommand: uvicorn main:app --host 0.0.0.0 --port $PORT envVars: - key: SUPABASE_URL sync: false - key: SUPABASE_KEY sync: false - key: SERVICE_ROLE_KEY sync: false - key: GENAI_API_KEY sync: false
-
Deploy:
- Connect GitHub repository
- Create new Web Service
- Set root directory to
backend - Add environment variables
- Deploy
-
SSH into your server
-
Install dependencies:
sudo apt update sudo apt install python3-pip python3-venv nginx
-
Clone and setup:
git clone <your-repo> cd new-test/backend python3 -m venv venv source venv/bin/activate pip install -r requirements.txt
-
Use Gunicorn for production:
pip install gunicorn gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8008
-
Set up systemd service (
/etc/systemd/system/CodeMotion-backend.service):[Unit] Description=CodeMotion Backend After=network.target [Service] User=www-data WorkingDirectory=/path/to/backend Environment="PATH=/path/to/backend/venv/bin" ExecStart=/path/to/backend/venv/bin/gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8008 [Install] WantedBy=multi-user.target
-
Start service:
sudo systemctl start CodeMotion-backend sudo systemctl enable CodeMotion-backend -
Nginx configuration:
server { listen 80; server_name api.your-domain.com; location / { proxy_pass http://127.0.0.1:8008; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
-
Create
docker-compose.ymlin root:version: '3.8' services: backend: build: context: ./backend dockerfile: Dockerfile ports: - "8008:8008" environment: - SUPABASE_URL=${SUPABASE_URL} - SUPABASE_KEY=${SUPABASE_KEY} - SERVICE_ROLE_KEY=${SERVICE_ROLE_KEY} - GENAI_API_KEY=${GENAI_API_KEY} - SUPABASE_BUCKET=${SUPABASE_BUCKET} volumes: - ./backend/generated_videos:/app/generated_videos restart: unless-stopped frontend: build: context: ./frontend dockerfile: Dockerfile ports: - "3000:3000" environment: - NEXT_PUBLIC_SUPABASE_URL=${NEXT_PUBLIC_SUPABASE_URL} - NEXT_PUBLIC_SUPABASE_ANON_KEY=${NEXT_PUBLIC_SUPABASE_ANON_KEY} - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} depends_on: - backend restart: unless-stopped
-
Deploy:
docker-compose up -d
Create Dockerfile in backend/ if not exists:
FROM python:3.10-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
docker.io \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application
COPY . .
# Expose port
EXPOSE 8008
# Run application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8008"]Create Dockerfile in frontend/:
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED 1
RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
CMD ["node", "server.js"]Update next.config.ts:
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
}
module.exports = nextConfigNEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key
NEXT_PUBLIC_API_URL=https://api.your-domain.comSUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your_anon_key
SERVICE_ROLE_KEY=your_service_role_key
SUPABASE_BUCKET=videos
GENAI_API_KEY=your_genai_key- Update Supabase redirect URLs with production domain
- Verify CORS settings in backend allow production frontend URL
- Test authentication flow end-to-end
- Verify video uploads to Supabase Storage
- Check API endpoints are accessible
- Set up SSL/HTTPS certificates (Let's Encrypt)
- Configure domain DNS records
- Set up monitoring and logging
- Configure backup strategy
- Test error handling and fallbacks
- Enable Next.js Image Optimization
- Configure CDN for static assets
- Enable compression
- Set up caching headers
- Use environment-specific builds
- Use production ASGI server (Gunicorn + Uvicorn)
- Configure proper logging
- Set up health check endpoints
- Implement rate limiting
- Use connection pooling for databases
- Configure proper CORS for production domains
- Frontend: Vercel Analytics, Sentry
- Backend: Logtail, Datadog, or CloudWatch
- Uptime: UptimeRobot, Pingdom
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com -d api.your-domain.com- Add domain to Cloudflare
- Enable SSL/TLS encryption
- Configure DNS records
Built with ❤️ using Next.js, FastAPI, Manim, and Supabase