Installation
Sunschool is fully open-source and can be self-hosted on your own infrastructure. This guide walks you through setting up a production-ready instance.Prefer a hosted solution? Visit sunschool.xyz for a managed instance with automatic updates and backups.
Prerequisites
Before you begin, ensure you have:Node.js v20+
Runtime for the server and client. v22 recommended for best performance.
PostgreSQL
Relational database for storing users, lessons, and analytics.
npm
Package manager included with Node.js.
Git
Version control for cloning the repository.
System Requirements
| Resource | Minimum | Recommended |
|---|---|---|
| CPU | 1 core | 2+ cores |
| RAM | 512 MB | 2 GB |
| Storage | 1 GB | 5 GB |
| Network | 1 Mbps | 10 Mbps |
Step 1: Clone the Repository
Clone the Sunschool repository from GitHub:Repository Structure
Step 2: Install Dependencies
Install all required packages:What Gets Installed
Key dependencies frompackage.json:
Step 3: Configure Environment Variables
Create a.env file in the root directory:
Required Variables
Edit.env and set the following:
PostgreSQL connection string
Secret key for signing JWT tokens (minimum 32 characters recommended)
Secret key for session management
Optional Variables
API key for Perplexity AI (alternative provider)
Port for the Express server
Enable SSL for database connections
Example Configuration
Step 4: Set Up the Database
Create the Database
If you haven’t already, create a PostgreSQL database:Run Migrations
Sunschool uses Drizzle ORM for database migrations. Migrations run automatically on server startup, but you can run them manually:Verify Schema
Check that tables were created:users— All accounts (admins, parents, learners)learner_profiles— Grade levels, subjects, knowledge graphslessons— Generated lessons with content and statusachievements— Milestones and badgesrewards— Parent-defined redemption goalspoints_ledger— Transaction log for earned/spent pointssync_configs— External database sync settings
Seed Test Data (Optional)
Populate the database with sample users and lessons:Seeding creates test accounts. Do not use in production — it includes weak passwords.
Step 5: Build the Frontend
Compile the React client:client/dist/ and served by Express in production.
Step 6: Start the Server
Development Mode
Run with hot-reloading:- Backend: Express server on
http://localhost:5000 - Frontend: Vite dev server on
http://localhost:5173(proxies API requests)
Production Mode
Build and run the production server:deploy script from package.json:10:
- Runs auto-migrations on startup
- Serves the built frontend from
client/dist/ - Exposes the API at
/api/* - Provides health checks at
/api/healthcheck
Verify It’s Running
Check the health endpoint:Step 7: Create the First Admin Account
Navigate tohttp://localhost:5000 in your browser.
Auto-Promotion to Admin
The first user to register is automatically promoted to Admin, regardless of the role selected during registration.
server/routes.ts:87-92:
Registration Steps
- Click Sign Up
- Fill in:
- Username:
admin - Email:
admin@example.com - Name:
Admin User - Password:
<secure-password> - Role:
PARENT(will be overridden toADMIN)
- Username:
- Accept the age disclaimer
- Submit
Step 8: Deploy to Production
Sunschool is designed to deploy seamlessly to platforms like Railway, Render, or Heroku.Railway Deployment
Sunschool auto-deploys on push tomain:
- Connect your GitHub repository to Railway
- Set environment variables in the Railway dashboard
- Railway detects the NIXPACKS buildpack automatically
- Push to
maintriggers deployment
/api/healthcheck (from README.md:152).
Environment Variables in Railway
Set these in the Railway dashboard (do not use.env in production):
Manual Deployment
For other platforms:- Build:
npm run build - Set env vars: Configure
DATABASE_URL,JWT_SECRET, etc. - Run:
npm start - Expose port: Ensure port
5000(or$PORT) is accessible
Post-Installation
Security Checklist
Backup Strategy
PostgreSQL Backups
Database Sync Feature
Sunschool includes an optional external sync feature:- Parents configure a second PostgreSQL connection at
/database-sync - Data is pushed to the external database on-demand or continuously
- Use this for redundancy or data portability
server/sync-utils.ts for implementation.
Next Steps
Configuration
Configure AI providers, feature flags, and advanced settings
First Steps
Navigate the interface and create your first learners
Quickstart
Walk through the full user experience
API Reference
Integrate with the Sunschool API
Troubleshooting
Database connection fails
Database connection fails
Symptoms:
Error: connect ECONNREFUSED or FATAL: password authentication failedSolutions:- Verify
DATABASE_URLformat:postgresql://user:password@host:port/database - Check PostgreSQL is running:
systemctl status postgresql - Test connection:
psql $DATABASE_URL - Ensure user has
CREATEandSELECTpermissions
Migrations don't run
Migrations don't run
Symptoms: Tables don’t exist, server crashes on startupSolutions:
- Run migrations manually:
npm run migrate - Check server logs for Drizzle errors
- Verify database user has schema modification permissions
- Delete and recreate the database if schema is corrupted
Frontend doesn't load
Frontend doesn't load
Symptoms: Blank page, 404 errorsSolutions:
- Run
npm run buildto compile the frontend - Check
client/dist/exists and containsindex.html - Verify the server is serving static files (see
server/index.ts) - Clear browser cache and reload
AI generation fails
AI generation fails
Symptoms:
Failed to generate lesson content, 503 errorsSolutions:- Verify
OPENROUTER_API_KEYis valid - Check OpenRouter account has credits
- Test API key:
curl https://openrouter.ai/api/v1/models -H "Authorization: Bearer $OPENROUTER_API_KEY" - Check server logs for rate limiting or quota errors
- Set
USE_AI=0in.envto disable AI features for testing
Port already in use
Port already in use
Symptoms:
EADDRINUSE: address already in use :::5000Solutions:- Change
PORTin.envto an available port (e.g.,5001) - Kill the process using port 5000:
lsof -ti:5000 | xargs kill - Use a different port in Railway/platform settings