An open-source platform designed for creative minds to generate and share multiple story variations from a single prompt. Perfect for writers, creators, and enthusiasts exploring AI-powered storytelling!
- Table of Contents
- About 🚀
- AI Story Generation Pipeline
- Features 💪
- Local development (monorepo)
- Environment variables
- Troubleshooting
- Contributing 👨💻
- Contributors 🤝
- About 🚀
- Features 💪
- Local Development
- Environment Variables
- Minimal Working Example (Story Generation API)
- Troubleshooting 🛠️
- Contributing 👨💻
- Contributors 🤝
- Maintainers
- License 📜
- Support 🙏
- Website: StorySparkAI
- StorySparkAI empowers creative minds by generating and showcasing AI-crafted stories from user prompts in a simple, engaging way.
- Users can:
- Input an idea or prompt
- Explore multiple story variations
- Save favorites
- Leverage AI analysis to enhance their creative writing journey
- AI-Powered Story Generation: Create unique stories instantly using advanced AI models.
- Prompt-Based Storytelling: Provide a prompt and watch it come to life.
- Story Bookmarks & History: Save and revisit your favorite creations.
- AI Analysis: Get summaries, critiques, and insights on your stories.
- Creative Writing Assistance: Overcome writer's block with intelligent suggestions.
- Responsive UI: Seamless experience across devices.
- Dark-Mode: Toggle between light and dark themes for a comfortable reading experience.
- Google Login: Sign in quickly and securely using your Google account.
- User Reviews: Share your experience and explore reviews from the community.
- Subscription Plans: Access unlimited story generation and team collaboration with paid plans.
- Featured Posts: Discover featured posts curated from the community.
Prerequisites: Node.js 18.18+, pnpm 8+, MongoDB URI for the API.
-
Clone the repository
git clone https://github.com/<your-github-username>/story-spark-ai.git
-
Navigate to the project directory
cd story-spark-ai -
Install dependencies (single install at the repo root — npm workspaces)
pnpm install
-
Environment files
- Copy
backend/.env.example→backend/.envand fill in all values (see Environment variables). - Copy
frontend/.env.example→frontend/.envand setVITE_BASE_URLto your API base URL (e.g.http://localhost:5000/api/v1when the backend runs on port 5000). Optionally setVITE_SOCKET_URLfor real-time notifications; the frontend uses your logged-in access token to join the notification room.
Never commit
backend/.envorfrontend/.env. Only.env.examplefiles belong in git. - Copy
-
First-Time Setup (Admin Seeding)
Before starting the server for the first time, you must create an admin user:
cd backend npx ts-node scripts/seed-admin.tsMake sure
ADMIN_EMAILandADMIN_PASSWORDare set in yourbackend/.envfile. -
Run apps
-
Both (two terminals or one combined process):
pnpm dev
-
Backend only:
pnpm dev:backend— API (default port 5000 ifPORTis unset). -
Frontend only:
pnpm dev:frontend— Vite dev server on http://localhost:4001
-
-
Production builds
pnpm run build pnpm run start:backend # requires `pnpm run build:backend` first pnpm run start:frontend # serves built static app (preview)
Use two Vercel projects from this monorepo:
| Project | Root directory | Example domain |
|---|---|---|
| Frontend | frontend |
storysparkai.vercel.app |
| Backend API | backend |
apistorysparkai.vercel.app |
Frontend environment variables (redeploy after changing):
VITE_BASE_URL=https://<your-api>.vercel.app/api/v1VITE_SOCKET_URL=https://notification-socket-io.onrender.com(or your own persistent Node host)- Do not point
VITE_SOCKET_URLat your Vercel API URL — Vercel serverless cannot run Socket.IO, which causes endless/socket.io/404 logs.
Backend environment variables: set DATABASE_URL, JWT secrets, AI keys, and CORS_ORIGINS including https://storysparkai.vercel.app.
Git: Use a single repository root (one .git folder). Do not nest another .git inside frontend/ or backend/.
After cloning, create your env files from the examples in the repo:
# 1. Clone the repository
git clone https://github.com/ronisarkarexe/story-spark-ai.git
cd story-spark-ai
# 2. Install all dependencies (npm workspaces — single install)
npm installCopy the example env files and fill in your values:
cp backend/.env.example backend/.env
cp frontend/.env.example frontend/.envVariables marked Yes are required. Variables marked Optional are only required when you use that feature.
| Variable | Example | Required | Description |
|---|---|---|---|
NODE_ENV |
development |
✅ Yes | Environment mode |
PORT |
5000 |
✅ Yes | Backend server port |
CORS_ORIGINS |
http://localhost:4001 |
✅ Yes | Allowed frontend origin |
| Variable | Example | Required | Description |
|---|---|---|---|
DATABASE_URL |
mongodb://127.0.0.1:27017/story_spark_ai |
✅ Yes | MongoDB connection string (Atlas or local) |
| Variable | Example | Required | Description |
|---|---|---|---|
SALT_ROUNDS |
10 |
✅ Yes | bcrypt hashing rounds |
JWT_SECRET |
any_random_string |
✅ Yes | Access token signing secret |
JWT_REFRESH_SECRET |
another_random_string |
✅ Yes | Refresh token signing secret |
JWT_EXPIRES_IN |
60d |
✅ Yes | Access token expiry |
JWT_REFRESH_EXPIRES_IN |
120d |
✅ Yes | Refresh token expiry |
DEFAULT_ADMIN_PASSWORD |
admin123 |
✅ Yes | Initial admin password for seeding |
ADMIN_EMAIL |
admin@example.com |
✅ Yes | Admin account email |
ADMIN_PASSWORD |
secure-password |
✅ Yes | Admin account password |
| Variable | Example | Required | Description |
|---|---|---|---|
OPEN_AI_KEY |
sk-... |
Required for OpenAI story generation | |
GEMINI_API_KEY |
AIza... |
Required for Gemini story generation | |
AI_API_KEYS |
key1,key2,key3 |
Comma-separated keys for round-robin rotation | |
AI_CONCURRENCY |
3 |
Max simultaneous AI calls (default: 3) |
ℹ️ You need at least one of
OPEN_AI_KEY,GEMINI_API_KEY, orAI_API_KEYSfor story generation to work.
| Variable | Example | Required | Description |
|---|---|---|---|
UNSPLASH_KEY_API |
your_access_key |
Required for story cover images | |
UNSPLASH_KEY_API_SECRET |
your_secret |
Unsplash API secret |
| Variable | Example | Required | Description |
|---|---|---|---|
VERIFY_EMAIL |
noreply@example.com |
Sender email for verification mails | |
VERIFY_PASSWORD |
app_password |
Email app password (not your login password) |
| Variable | Example | Required | Description |
|---|---|---|---|
GOOGLE_CLIENT_ID |
xxxx.apps.googleusercontent.com |
Required for Google Login |
| Variable | Example | Required | Description |
|---|---|---|---|
VITE_BASE_URL |
http://localhost:5000/api/v1 |
✅ Yes | Backend API base URL |
VITE_SOCKET_URL |
http://localhost:5000 |
WebSocket server URL (only needed for real-time notifications) | |
VITE_GOOGLE_CLIENT_ID |
xxxx.apps.googleusercontent.com |
✅ Yes | Google OAuth Client ID |
Only these variables are needed to run core features:
backend/.env
NODE_ENV=development
PORT=5000
CORS_ORIGINS=http://localhost:4001
DATABASE_URL=mongodb://127.0.0.1:27017/story_spark_ai
SALT_ROUNDS=10
JWT_SECRET=any_random_string
JWT_REFRESH_SECRET=another_random_string
JWT_EXPIRES_IN=60d
JWT_REFRESH_EXPIRES_IN=120d
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD=admin123
DEFAULT_ADMIN_PASSWORD=admin123frontend/.env
VITE_BASE_URL=http://localhost:5000/api/v1
VITE_SOCKET_URL=http://localhost:5000Step 1 — Seed the admin user (first time only)
Before starting the server for the first time, create an admin account:
cd backend
npx ts-node scripts/seed-admin.tsMake sure DEFAULT_ADMIN_PASSWORD and ADMIN_EMAIL are set in backend/.env.
Step 2 — Start development servers
# Run both frontend & backend concurrently (from repo root)
npm run dev
# Or run individually:
npm run dev:backend # API on http://localhost:5000
npm run dev:frontend # Vite on http://localhost:4001Step 3 — Production build
npm run build
npm run start:backend # requires build:backend first
npm run start:frontend # serves built static app (preview)Once your backend is running (pnpm dev:backend or npm run dev:backend) and you have a valid auth token, use the examples below to quickly verify your setup by generating a story.
ℹ️ You must be authenticated first (e.g. via the login endpoint or Google Login) to obtain a Bearer token, and at least one AI provider key (
OPEN_AI_KEY,GEMINI_API_KEY, orAI_API_KEYS) must be set inbackend/.env.
curl -X POST http://localhost:5000/api/v1/story/generate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \
-d '{
"prompt": "A lost astronaut discovers a planet made of memories"
}'const res = await fetch(`${import.meta.env.VITE_BASE_URL}/story/generate`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
prompt: "A lost astronaut discovers a planet made of memories",
}),
});
const data = await res.json();
console.log(data);{
"success": true,
"storyId": "64fabc1234...",
"stories": [
{
"title": "Echoes of Memory",
"content": "Far beyond the Orion belt...",
"variation": 1
},
{
"title": "The Memory Planet",
"content": "In the silence of space...",
"variation": 2
}
]
}- The API returns multiple story variations generated from a single prompt.
- Each variation includes a
titleandcontentfield. - The
storiesarray can be mapped directly into your frontend UI. - A successful response confirms that your environment variables (database, JWT, and AI provider keys) are configured correctly.
If you get an error instead of a response, see Troubleshooting — most issues trace back to a missing AI provider key or an invalid/expired Bearer token.
Stories not generating?
→ Set at least one of OPEN_AI_KEY, GEMINI_API_KEY, or AI_API_KEYS.
Google Login not working?
→ GOOGLE_CLIENT_ID is missing. Get it from Google Cloud Console.
Story cover images not loading?
→ UNSPLASH_KEY_API is not set. Register at Unsplash Developers.
Verification email not sent? → For Gmail, use an App Password, not your account password.
MongoDB connection failed?
→ Ensure MongoDB is running locally: mongod
→ Or use Atlas URI: mongodb+srv://user:pass@cluster.mongodb.net/story_spark_ai
CORS error in browser?
→ CORS_ORIGINS must exactly match your frontend URL including port. No trailing slash.
- Problem: Running
pnpmcommands returns a "command not found" error. - Possible cause:
pnpmis not installed globally on your system. - Suggested solution: Install
pnpmglobally using npm:Verify the installation by checking the version:npm install -g pnpm
pnpm --version
- Problem: The backend or frontend fails to start, or throws unexpected runtime errors.
- Possible cause: Your installed Node.js version is older than the required version. The project requires Node.js 18.18 or later.
- Suggested solution: Check your installed Node.js version:
If your version is older than 18.18, please upgrade Node.js to the required version or later (available on the official Node.js website).
node -v
- Problem: The backend starts with database connection errors or cannot load API data.
- Possible cause:
DATABASE_URLis missing, incorrect, points to the wrong database, or MongoDB is not running. - Suggested solution: Check
backend/.envand verifyDATABASE_URLmatches your local MongoDB or Atlas URI. If you use local MongoDB, make sure the MongoDB service is running before starting the backend.
- Problem: The backend cannot connect to a remote MongoDB Atlas database.
- Possible cause: The
DATABASE_URLinbackend/.envcontains incorrect credentials, or your current IP address is not whitelisted on MongoDB Atlas. - Suggested solution: Verify that your
DATABASE_URLcontains the correct database username and password. Ensure that your current IP address is whitelisted in the Network Access settings of your MongoDB Atlas dashboard.
- Problem: The backend or frontend fails to start, or features break during development.
- Possible cause: Required values are missing from
backend/.envorfrontend/.env. - Suggested solution: Compare your local
.envfiles withbackend/.env.exampleandfrontend/.env.example, then add any missing variables.
- Problem: Changes made to
.envfiles do not seem to apply to the running application. - Possible cause: The development server only loads environment variables when it starts. Subsequent changes do not auto-reload.
- Suggested solution: Stop your running frontend or backend development server (usually by pressing
Ctrl + Cin the terminal) and restart it (e.g.,npm run dev) to apply the new configuration.
- Problem: Users are unable to log in with Google, or Google OAuth returns authentication errors.
- Possible cause: Missing or mismatched Google Client IDs in your environment configuration, or credentials that do not match the Google Cloud Console setup.
- Suggested solution: Verify that
GOOGLE_CLIENT_IDis set correctly inbackend/.envandVITE_GOOGLE_CLIENT_IDis set correctly infrontend/.env. Ensure both values match the client credentials configured for your web application in the Google Cloud Console.
- Problem: The frontend or backend cannot start because a port is already in use.
- Possible cause: Another process is already using port 4001 for the frontend or 5000 for the backend.
- Suggested solution: Find and stop the conflicting process, then restart the app.
- Windows: Run
netstat -ano | findstr :5000ornetstat -ano | findstr :4001, then stop the process withtaskkill /PID <PID> /F. - Linux/macOS: Run
lsof -i :5000orlsof -i :4001to find the process ID (PID), then stop it withkill -9 <PID>. If needed, change the backendPORTinbackend/.envor update the frontend dev server port in the frontend configuration.
- Windows: Run
- Problem:
pnpm installfails or installed packages behave unexpectedly. - Possible cause: Cached dependencies, a stale lock file, or an incomplete install.
- Suggested solution: Delete
node_modulesand the lock file, then reinstall dependencies from the repository root withpnpm install.
- Problem: Running
pnpm installfails or packages behave unexpectedly after switching git branches. - Possible cause: Stale dependencies or mismatched lockfiles from the previous branch are causing conflicts.
- Suggested solution: Remove the
node_modulesdirectory and reinstall dependencies from the repository root:# Remove node_modules # On Windows (PowerShell): Remove-Item -Recurse -Force node_modules # On Linux/macOS: rm -rf node_modules # Reinstall dependencies pnpm install
- Problem: UI updates are not visible in the browser, or hot module replacement (HMR) seems to have frozen.
- Possible cause: The browser has cached stale assets, or the Vite dev server's file watcher stopped responding.
- Suggested solution: Perform a hard refresh in your browser (
Ctrl + Shift + Ron Windows/Linux orCmd + Shift + Ron macOS). If the issue persists, stop and restart the frontend development server.
- Problem: Admin user creation fails when running
npx ts-node scripts/seed-admin.ts. - Possible cause: Admin credentials are missing or the backend cannot connect to MongoDB.
- Suggested solution: Verify
ADMIN_EMAILandADMIN_PASSWORDare set inbackend/.env, then confirmDATABASE_URLis valid and MongoDB is running.
- Problem: Real-time notifications do not connect or the browser shows Socket.IO errors.
- Possible cause:
VITE_SOCKET_URLis incorrect, missing, or the backend/socket service is not running. - Suggested solution: Check
frontend/.envand verifyVITE_SOCKET_URLpoints to the active socket service. Make sure the backend/socket service is running, then check the browser console for connection errors.
Cause: There's a version mismatch in the root package.json — @types/express is set to ^5.0.6 in devDependencies, which conflicts with what the project expects.
Fix: Open your root package.json and change the @types/express version under devDependencies:
// ❌ Before
"@types/express": "^5.0.6"
// ✅ After
"@types/express": "^4.17.21"Then re-run:
pnpm installCause: Docker Desktop is not installed or not added to your system PATH.
Fix: Download and install Docker Desktop from the official site: 👉 https://www.docker.com/products/docker-desktop/
After installation, restart your terminal and verify with:
docker --versionCause: Your Windows Subsystem for Linux (WSL) version is outdated and incompatible with the current Docker Desktop.
Fix: Run the following command in your terminal (as Administrator if needed):
wsl --updateOnce the update completes, click Try Again in Docker Desktop. If the issue persists, restart your machine.
Cause: The package-lock.json is either missing or out of sync with package.json, causing npm ci to fail.
Fix: At the repo root, regenerate the lockfile:
pnpm installThen commit the updated pnpm-lock.yaml before rebuilding your Docker image:
git add pnpm-lock.yaml
git commit -m "chore: regenerate pnpm-lock.yaml"💡 Still stuck? Open an issue or check existing ones — your problem may already have a solution!
- Fork the repository and clone your fork.
- Create a branch:
git checkout -b your-feature-branch - Install with
pnpm installat the repo root, configure.envfiles, thengit add,git commit,git push, and open a pull request.
Contributions make the open source community such an amazing place to learn, inspire, and create.
Any contributions you make are truly appreciated!
Thanks to everyone who has helped build Story Spark AI. This grid updates automatically from GitHub contributors.
Roni Sarkar Project Maintainer · @ronisarkarexe |
|
This project is licensed under MIT. |
Thank you for contributing to our open-source project! We appreciate your support 🚀
Don't forget to leave a star ⭐
