Skip to main content

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

The .env.example file from the repository:

Required Variables

DATABASE_URL

string
required
PostgreSQL connection string with credentials and database name
Format:
Examples:
From server/config/env.ts:

JWT_SECRET

string
required
Secret key for signing JWT authentication tokens. Defaults to SESSION_SECRET if not provided.
Generate a secure secret:
Configuration:
From server/config/env.ts:
Tokens expire after 7 days by default. See Security Configuration for details.

SESSION_SECRET

string
required
Secret for session encryption and cookie signing
Best practices:
  • Use different secrets for development and production
  • Minimum 32 characters
  • Never commit secrets to version control
From server/config/env.ts:
The default dev-secret-change-me is insecure. Always set a custom value in production.

OPENROUTER_API_KEY

string
required
API key for OpenRouter (primary AI provider)
Obtain an API key:
  1. Sign up at openrouter.ai
  2. Navigate to Keys
  3. Create a new API key
  4. Copy the key (starts with sk-or-v1-...)
Configuration:
From server/config/env.ts:
OpenRouter provides access to multiple models. Sunschool uses:
  • Lesson generation: Gemini 3.1 Pro
  • SVG illustrations: Gemini 3.1 Flash

Optional Variables

PERPLEXITY_API_KEY

string
API key for Perplexity (knowledge enrichment)
From server/config/env.ts:
Use case: Enriching lesson content with up-to-date information and context.

BITTENSOR_API_KEY (Experimental)

string
API key for Bittensor Subnet 1 (decentralized AI)
From server/config/env.ts:
See AI Provider Configuration for Bittensor setup.

PORT

number
default:"5000"
Server listening port
From server/config/env.ts:

NODE_ENV

string
default:"development"
Environment mode: development or production
From server/config/env.ts:
Affects:
  • Logging verbosity
  • Error detail exposure
  • SSL requirements

Feature Flags

From server/config/flags.ts:

USE_AI

boolean
default:"1"
Enable/disable AI features entirely. Set to 0 for static fallback content.

ENABLE_STATS

boolean
default:"1"
Enable statistics collection and analytics

ENABLE_BITTENSOR_SUBNET_1

boolean
default:"0"
Enable Bittensor as AI provider

Image Generation Flags

Advanced Configuration

Image Generation

string
default:"svg-llm"
Primary image generation strategy: svg-llm, openrouter, or stability
From server/config/env.ts:

Model Fallback Chains

string
Comma-separated list of fallback models for SVG generation
From server/config/env.ts:
Fallbacks activate when primary model returns 404 or 402 (insufficient credits).

LLM Provider Selection

string
default:"openrouter"
Primary LLM provider: openrouter, bittensor, or perplexity
From server/config/env.ts:

Complete Example

Production .env

Development .env

Validation

From server/config/env.ts, the getEnv helper throws errors for missing required variables:
Test your configuration:

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