Environment File Setup
Sunschool uses a.env file for configuration. During development, the server loads variables using dotenv. In production (Replit, Railway), environment variables are set directly.
From server/config/env.ts:
Create Configuration File
.env.example file from the repository:
Required Variables
DATABASE_URL
PostgreSQL connection string with credentials and database name
- Neon Serverless
- Local PostgreSQL
- Railway PostgreSQL
server/config/env.ts:
JWT_SECRET
Secret key for signing JWT authentication tokens. Defaults to SESSION_SECRET if not provided.
server/config/env.ts:
SESSION_SECRET
Secret for session encryption and cookie signing
- Use different secrets for development and production
- Minimum 32 characters
- Never commit secrets to version control
server/config/env.ts:
OPENROUTER_API_KEY
API key for OpenRouter (primary AI provider)
- Sign up at openrouter.ai
- Navigate to Keys
- Create a new API key
- Copy the key (starts with
sk-or-v1-...)
server/config/env.ts:
- Lesson generation: Gemini 3.1 Pro
- SVG illustrations: Gemini 3.1 Flash
Optional Variables
PERPLEXITY_API_KEY
API key for Perplexity (knowledge enrichment)
server/config/env.ts:
BITTENSOR_API_KEY (Experimental)
API key for Bittensor Subnet 1 (decentralized AI)
server/config/env.ts:
PORT
Server listening port
server/config/env.ts:
NODE_ENV
Environment mode:
development or productionserver/config/env.ts:
- Logging verbosity
- Error detail exposure
- SSL requirements
Feature Flags
Fromserver/config/flags.ts:
USE_AI
Enable/disable AI features entirely. Set to
0 for static fallback content.ENABLE_STATS
Enable statistics collection and analytics
ENABLE_BITTENSOR_SUBNET_1
Enable Bittensor as AI provider
Image Generation Flags
Advanced Configuration
Image Generation
Primary image generation strategy:
svg-llm, openrouter, or stabilityserver/config/env.ts:
Model Fallback Chains
Comma-separated list of fallback models for SVG generation
server/config/env.ts:
LLM Provider Selection
Primary LLM provider:
openrouter, bittensor, or perplexityserver/config/env.ts:
Complete Example
Production .env
Development .env
Validation
Fromserver/config/env.ts, the getEnv helper throws errors for missing required variables:
Next Steps
Database Setup
Initialize PostgreSQL and run migrations
AI Providers
Configure OpenRouter, Perplexity, and Bittensor
Security
Implement authentication and access controls
Troubleshooting
Resolve common configuration issues