This guide documents how to set up and run Story Spark AI locally for development and contribution.
- Node.js: 20.x (repository
engines.node) - Package manager: pnpm 9.15.9 (repository
packageManager) - MongoDB: running locally (or provide a MongoDB Atlas connection string)
- A Node version manager:
- nvm (macOS/Linux)
- Volta (cross-platform)
The repository includes an ML helper folder under backend/ml/. If you want to run those scripts/tests, install Python 3.10+.
# Replace <REPO_URL> with the repository origin
git clone <REPO_URL>
cd story-spark-aiThis is a pnpm workspace repo. Install once at the root:
pnpm installThe root package.json defines workspace scripts, but the repo is primarily configured for pnpm.
npm installNote: Some setups may rely on the pnpm lockfile. If you hit issues, prefer
pnpm install.
This repo uses .env.example files to generate real .env files.
# Backend
cp backend/.env.example backend/.env
# Frontend
cp frontend/.env.example frontend/.envCreate backend/.env and set at least the following (names are taken from the repo docs and configuration):
Common required values for local development:
DATABASE_URL(MongoDB connection string)SALT_ROUNDSJWT_SECRETJWT_REFRESH_SECRETJWT_EXPIRES_INJWT_REFRESH_EXPIRES_INDEFAULT_ADMIN_PASSWORD(used during admin seeding)
Optional (only if you use corresponding features):
OPEN_AI_KEY(OpenAI-powered features)GEMINI_API_KEY(Gemini-powered features)UNSPLASH_KEY_API/UNSPLASH_KEY_API_SECRET(Unsplash image features)VERIFY_EMAIL/VERIFY_PASSWORD(email verification/notifications)GOOGLE_CLIENT_ID(Google login)
Example backend/.env:
DATABASE_URL=mongodb://localhost:27017/storysparkai
PORT=5000
NODE_ENV=development
CORS_ORIGINS=http://localhost:4001
SALT_ROUNDS=10
JWT_SECRET=your-jwt-secret
JWT_REFRESH_SECRET=your-refresh-secret
JWT_EXPIRES_IN=60d
JWT_REFRESH_EXPIRES_IN=120d
DEFAULT_ADMIN_PASSWORD=admin123
# Optional keys
OPEN_AI_KEY=
GEMINI_API_KEY=
GOOGLE_CLIENT_ID=Create frontend/.env.
Required:
VITE_BASE_URL(backend API base URL)VITE_GOOGLE_CLIENT_ID
Optional:
VITE_SOCKET_URL(Socket.IO server URL, if you are testing real-time features)
Example frontend/.env:
VITE_BASE_URL=http://localhost:5000/api/v1
VITE_SOCKET_URL=http://localhost:5000
VITE_GOOGLE_CLIENT_ID=your-google-client-idImportant: Don’t commit
.envfiles.
pnpm devThis starts:
backend(Express API)frontend(Vite dev server)
pnpm dev:backendpnpm dev:frontendpnpm buildpnpm -C backend testpnpm -C frontend testSymptom: scripts fail with errors related to Node compatibility.
Fix:
- Switch to Node 20.x:
node -vThen reinstall dependencies if needed:
pnpm installThe project commonly uses:
- Frontend:
http://localhost:4001 - Backend API:
http://localhost:5000(default)
Fix (identify processes using the ports):
lsof -i :4001
lsof -i :5000Stop the conflicting process and restart.
If needed, adjust:
backend/.env→PORT- frontend dev behavior → consult
frontend/vite.config.ts(only if you changed ports)
Symptom: backend fails to connect or cannot load data.
Fix:
- Ensure MongoDB is running.
- Verify
backend/.env:DATABASE_URLpoints to your running MongoDB instance
Symptom: backend/frontend fails to start or key features break.
Fix:
- Re-copy and fill values from the
.env.examplefiles:
cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.envSome local setups require an admin user.
Fix:
- Ensure
DEFAULT_ADMIN_PASSWORDis set inbackend/.env - Run the seed script:
cd backend
npx ts-node scripts/seed-admin.tsSymptom: browser console shows Socket.IO connection/404 errors.
Fix:
- Verify
frontend/.env:VITE_SOCKET_URLpoints to the active socket service URL
- Ensure the backend/socket server is running (via
pnpm devorpnpm dev:backend).
- Prefer running the repo exactly as documented in
README.md/DEVELOPMENT.mdif anything drifts. - Keep
.envfiles out of version control.