Configuration
Sunschool is highly configurable through environment variables and feature flags. This guide covers all configuration options.Environment Variables
All configuration is managed through environment variables in the.env file.
Core Settings
PostgreSQL connection stringFormat:
postgresql://[user]:[password]@[host]:[port]/[database]Examples:- Local:
postgresql://postgres:postgres@localhost:5432/sunschool - Neon:
postgresql://user:pass@ep-xyz.us-east-2.aws.neon.tech/sunschool?sslmode=require - Railway: Automatically provided via
$DATABASE_URL
Enable SSL for database connectionsSet to
false for local development without SSL.Port for the Express serverMost hosting platforms provide
$PORT automatically.Environment modeValues:
development, productionAuthentication
Secret key for signing JWT tokensGenerate securely:From
server/config/env.ts:41:JWT token expiration timeFormat:
[number][unit] where unit is s, m, h, dExamples: 30m, 12h, 7d, 90dSecret key for session managementGenerate securely:
AI Provider Configuration
Sunschool supports multiple AI providers with automatic fallback chains.OpenRouter (Primary)
API key for OpenRouterGet your key: openrouter.ai/keysFrom Used for:
server/config/env.ts:48:- Lesson content generation
- Quiz question creation
- SVG illustration generation
Primary LLM providerOptions:
openrouter, bittensor, perplexityFrom server/config/env.ts:45:Bittensor (Experimental)
Enable Bittensor Subnet 1 providerFrom
server/config/flags.ts:12:API key for Bittensor Archive
GraphQL endpoint for Bittensor Subnet 1From
server/config/env.ts:52:Bittensor wallet name for authentication
Bittensor wallet hotkey
Enable automatic fallback to OpenRouter when Bittensor failsFrom
server/config/flags.ts:13:Perplexity
Image Generation
Provider Selection
Image generation providerOptions:
svg-llm: LLM-generated SVG graphics (recommended)openrouter: Raster images via OpenRouterstability: Stability AI models
server/config/env.ts:60:OpenRouter Image Models
Primary model for image generationFrom
server/config/env.ts:61:Primary model for SVG generationFrom
server/config/env.ts:62:Comma-separated list of fallback models for image generationTried in order when the primary model returns 404 or fails.From
server/config/env.ts:69-70:Comma-separated list of fallback models for SVG generationFrom Default fallbacks from
server/config/env.ts:67-68:server/config/env.ts:73-76:Image Generation Limits
Timeout for image generation in millisecondsFrom
server/config/env.ts:63:Maximum number of images to generate per lessonFrom
server/config/env.ts:64:Feature Flags
Feature flags control optional functionality. Seeserver/config/flags.ts for implementation.
AI Controls
Enable AI-generated contentSet to
0 to disable all AI features (lessons use placeholder content).From server/config/flags.ts:9:Enable OpenRouter image generationFrom
server/config/flags.ts:19:Enable LLM-based SVG generationFrom
server/config/flags.ts:20:Enable Stability AI as fallback for image generationFrom
server/config/flags.ts:21:Analytics
Enable statistics collectionSet to
0 to disable analytics tracking (performance data, usage metrics).From server/config/flags.ts:16:Example Configurations
Minimal (Development)
Production (Recommended)
Bittensor Experimental
Advanced Configuration
Database Connection Pooling
Sunschool usespg with Neon serverless driver. Connection pooling is handled automatically.
For high-traffic deployments, configure external pooling (e.g., PgBouncer):
CORS Configuration
CORS is enabled by default for all origins in development. For production, editserver/index.ts:
Rate Limiting
Sunschool does not include built-in rate limiting. Use a reverse proxy (nginx, Caddy) or middleware:Configuration Validation
Sunschool validates critical environment variables on startup. Missing required variables throw errors:Startup Checks
When the server starts:- Database connection is tested
- Migrations are run automatically
- Missing API keys log warnings (not errors) for optional providers
Next Steps
First Steps
Navigate the interface and manage learners
Installation
Self-host Sunschool on your infrastructure
API Reference
Integrate with the Sunschool API
Quickstart
Complete walkthrough from signup to first lesson
Troubleshooting
API key not working
API key not working
Symptoms:
Failed to generate lesson content, 401 errorsSolutions:- Verify the API key is correct (no extra spaces or quotes)
- Check the provider’s dashboard for key status
- Test the key with a curl request
- Ensure the account has sufficient credits/quota
Feature flag not taking effect
Feature flag not taking effect
Symptoms: Feature still enabled/disabled after changing flagSolutions:
- Restart the server:
npm start - Check
.envfile has no typos in variable names - Verify the flag is read correctly: add
console.log(USE_AI)inserver/config/flags.ts - Clear any cached environment variables
Image generation is slow
Image generation is slow
Symptoms: Lessons load but images take 20+ secondsSolutions:
- Increase
IMAGE_GENERATION_TIMEOUT(default: 15000ms) - Use faster models in fallback chain (e.g.,
gemini-3-flash-preview) - Reduce
MAX_IMAGES_PER_LESSONto 2-3 - Check OpenRouter model availability at openrouter.ai/models
Database SSL error
Database SSL error
Symptoms:
Error: self signed certificate, SSL SYSCALL errorSolutions:- For local dev, set
DATABASE_SSL=false - For production, ensure the database supports SSL
- Add
?sslmode=requiretoDATABASE_URL - Check the database provider’s SSL documentation