Potion Template
Production-ready Notion-like editor with AI features, built on Plate.
What is Potion?
Potion is a comprehensive template built on Plate, offering a Notion-like interface with advanced content management capabilities, enhanced by AI features.
Requirements
- React 19
- TailwindCSS 4
Key Features
-
Production-Ready AI Integration
- GitHub Copilot-style suggestions with word-by-word acceptance
- AI-powered commands for content generation and editing
-
Media Management
- UploadThing integration for efficient file handling
- Advanced image/video features: resize, align, caption
- Clickable media placeholders with upload/embed options
-
Enhanced Navigation
- Sticky TOC sidebar with hover-to-expand
- Extended slash menu with item groups
- Context menu via drag button or three-dot menu
-
Mathematical Content
- LaTeX equation support with real-time rendering
- Toolbar integration for quick equation insertion
Key Benefits
- Launch faster: Skip 100+ hours of development and debugging
- Enterprise-ready: Database persistence, input validation, rate limiting, and type safety
- Full control: Modify any component, extend any feature
- Future-proof: Built on T3 Stack
Tech Stack
Get Started with the Frontend
Need just the editor? Get our decoupled frontend version that works with any backend:
This frontend-only version gives you Potion's powerful editor features without the backend constraints. Perfect for teams with existing infrastructure. Follow our installation guide – a few copy-paste and it's yours.
Perfect For
- Startups building the next-gen content platform
- Enterprises needing a customizable document editor
- Developers creating knowledge bases or documentation sites
- Teams requiring AI-enhanced content creation tools
License
Available under our commercial license. Get full source code access and free updates.
README
Getting Started
Environment Variables
Copy the example env file:
cp .env.example .env.localDatabase & Redis
Potion requires both PostgreSQL and Redis for:
- PostgreSQL: Main database
- Redis: Real-time collaboration and rate limiting
Local Docker Compose (Recommended for Development)
- Launch Docker Desktop
- The provided
docker-compose.ymlincludes both PostgreSQL and Redis - Set the database environment variables:
DATABASE_URL=postgresql://admin:password@localhost:5432/db?schema=public
POSTGRES_USER=admin
POSTGRES_PASSWORD=password
POSTGRES_DB=db
# Redis (for collaboration)
REDIS_HOST=localhost
REDIS_PORT=6379Remote Services
- Remove
dev:dbscript from thescriptsinpackage.json. - Set the environment variables to your remote services:
DATABASE_URL=your_postgresql_url
REDIS_HOST=your_redis_host
REDIS_PORT=6379Authentication
Create a new GitHub OAuth app with the following settings:
- Application Name:
Potion Local - Homepage URL:
http://localhost:3000 - Authorization callback URL:
http://localhost:3000/api/auth/callback/github
Then set these environment variables:
BETTER_AUTH_SECRET- A secret key for signing cookies (min 32 characters). Generate with:openssl rand -base64 32GITHUB_CLIENT_IDGITHUB_CLIENT_SECRET
AI
For AI features, get an AI Gateway API key from Vercel and set:
AI_GATEWAY_API_KEY
File Uploads
For file uploads, create a new UploadThing account and set:
UPLOADTHING_TOKEN
Real-time Collaboration (Optional)
For real-time collaborative editing, configure the WebSocket server:
# YJS WebSocket Server
YJS_PORT=4444
YJS_HOST=0.0.0.0
YJS_PATH=/yjs
YJS_TIMEOUT=10000
YJS_DEBOUNCE=2000
YJS_MAX_DEBOUNCE=10000
# Frontend WebSocket URL
NEXT_PUBLIC_YJS_URL=ws://localhost:4444/yjsDevelopment
bun installbun dev- This starts:- Next.js app on port 3000
- YJS WebSocket server on port 4444
- Docker services (PostgreSQL & Redis)
bun migrate: db migration in another terminal
Deployment
Potion is deployed on Coolify using a Dockerfile. You could deploy it anywhere you want (Vercel, Fly.io, etc.) without Docker.
Required Services
Your deployment needs the following services:
- PostgreSQL - Main database
- Redis - Real-time collaboration and caching
- Next.js App - The application (includes WebSocket server)
Environment Variables
NEXT_PUBLIC_ENVIRONMENT=production
# Use your own domain
NEXT_PUBLIC_SITE_URL=https://potion.platejs.org
# Database
DATABASE_URL=postgresql://user:password@postgres:5432/db?schema=public
# Redis (important for collaboration)
REDIS_HOST=redis
REDIS_PORT=6379
# YJS WebSocket Server
YJS_PORT=4444
YJS_HOST=0.0.0.0
YJS_PATH=/yjs
YJS_TIMEOUT=10000
YJS_DEBOUNCE=2000
YJS_MAX_DEBOUNCE=10000
# Frontend WebSocket URL (adjust based on your domain)
NEXT_PUBLIC_YJS_URL=wss://your-domain.com/yjs
# Or if exposing port directly: ws://your-domain.com:4444/yjsCoolify Setup
Services Configuration
-
PostgreSQL Service
- Type: PostgreSQL
- Persistent storage: Enabled
-
Redis Service ⚠️ Required
- Type: Redis 7-alpine
- Persistent storage: Enabled
- Service name:
redis(important for networking)
-
Application
- Build Pack:
Dockerfile - Exposed Ports:
3000(HTTP) and4444(WebSocket)
- Build Pack:
General Settings
- Direction:
Redirect to non-www.
Build Settings
- Build Command:
bun build && bun db:deploy - Start Command:
bun start(starts both Next.js and YJS server)
Advanced Settings
Enable Gzip Compression: disabled
Environment Variables
- Set each environment variable with
Build Variable?enabled.
Network Configuration
Ensure all services (PostgreSQL, Redis, App) are on the same Docker network.
WebSocket Proxy (if using Nginx/Traefik)
If you're proxying the WebSocket connection, ensure WebSocket upgrade headers are configured:
location /yjs {
proxy_pass http://app:4444;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}CloudFlare DNS
- SSL/TLS: Full
- WebSocket: Enabled (orange cloud proxied)
App Architecture
Frontend
- Routes
app/- Next.js 15+ App Routerapp/(dynamic)/(main)/- Main app routesapp/(dynamic)/(public)/- Public routesapp/(dynamic)/(admin)/- Admin routes
- Components
components/- Application-wide componentscomponents/hooks/- Application-wide hookscomponents/ui/- Reusable UI componentscomponents/editor/- Editor components coupled to the applicationregistry/- Core editor components from pro.platejs.orgcomponents/auth/- Auth components
- Configuration
Backend
-
API tRPC
server/api/- Default API layer using tRPCserver/api/middlewares/- tRPC middlewaresserver/api/routers/- tRPC routerstrpc/hooks.ts- React query and mutation hooks
-
API Hono
server/hono/- API layer using Honoserver/hono/middlewares/- Hono middlewaresserver/hono/routes/- Hono routes
-
Auth
server/auth/- Authentication system (Better Auth)server/auth/auth.ts- Better Auth configurationserver/auth/auth-client.ts- Client-side auth helpers
-
Database
prisma/schema.prisma- Prisma schemaserver/db.ts- Prisma with PostgreSQLserver/ratelimit.ts- Rate limiting with Redis
-
Real-time Collaboration
server/yjs/- YJS collaboration serverserver/yjs/server.ts- Hocuspocus WebSocket serverserver/yjs/auth.ts- Collaboration authenticationserver/yjs/document.ts- Document sync with database