An AI-powered multimodal story and image generator built using React (frontend) and Node.js/Express (backend) for generating unique, creative stories and illustrations from user prompts. Powered by Groq AI, HuggingFace Stable Diffusion, and MongoDB for user management.
π¬ Testing with Keploy: This project uses Keploy for automated API testing with built-in mocking of external APIs and database interactions.
β¨ Story Generation
- Generate unique, creative stories in seconds
- Powered by Groq AI (LLaMA 3) for ultra-fast inference
- Support for multiple story genres and styles
π¨ Image Generation
- Generate AI-powered illustrations
- Powered by HuggingFace Stable Diffusion
- Integrated with Replicate API
π€ User Management
- User registration and authentication (JWT)
- MongoDB database for persistent storage
- Secure password hashing with bcryptjs
π§ͺ Automated Testing
- Keploy integration for API testing
- Automatic test generation from API traffic
- Built-in mocking for external APIs
- MongoDB query recording and replay
- React - UI framework
- Vite - Fast build tool
- Tailwind CSS - Styling
- Node.js - Runtime
- Express v5.1.0 - Web framework
- MongoDB - Database
- Groq AI API - Story generation (LLaMA 3)
- HuggingFace - Image generation (Stable Diffusion)
- JWT - Authentication
- bcryptjs - Password hashing
- Keploy 3.3.10 - API testing & mocking
- Docker - Containerization
- Docker Compose - Multi-service orchestration
- Node.js v18+ (verify with
node --version) - MongoDB running locally or connection string
- npm or yarn package manager
- Keploy (optional, for testing)
cd backendCreate a .env file with:
# MongoDB Configuration
MONGO_URI=mongodb://localhost:27017/storyforge
# JWT Configuration
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production
# API Keys
GROQ_API_KEY=your_groq_api_key_here
HUGGINGFACE_API_TOKEN=your_huggingface_token_here
REPLICATE_API_TOKEN=your_replicate_token_here
# Server Configuration
PORT=5000
NODE_ENV=development- Groq Console - Free LLaMA API access
- HuggingFace - Image generation
- Replicate - Alternative image generation
# Option A: If MongoDB is installed locally
sudo systemctl start mongod
# Option B: Using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latest# Install backend dependencies
cd backend
npm install
# Install frontend dependencies
cd ../frontend
npm installcd backend
npm run devYou should see:
β
Connected to MongoDB
π Server running on http://localhost:5000
cd frontend
npm run devThe app will be available at http://localhost:5173
The GIF above shows Keploy in action - automatically recording API traffic and replaying it as tests.
Keploy is an automated API testing tool that:
- Records actual API traffic and converts it to test cases
- Automatically mocks external APIs (Groq, HuggingFace, Replicate)
- Records and replays MongoDB queries
- Generates test reports with coverage metrics
# For Linux/macOS
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin
keploy --version # Should print: Keploy 3.3.10cd backend
./test-keploy-setup.shYou should see all checks passing β
Terminal 1 - Start Recording:
cd backend
npm run keploy:recordTerminal 2 - Generate Test Traffic:
cd backend
./keploy-test.sh generateOr manually test endpoints:
# Test root endpoint
curl http://localhost:5000/
# Test signup
curl -X POST http://localhost:5000/api/signup \
-H "Content-Type: application/json" \
-d '{"email":"demo@example.com","password":"Demo123!"}'
# Test login
curl -X POST http://localhost:5000/api/login \
-H "Content-Type: application/json" \
-d '{"email":"demo@example.com","password":"Demo123!"}'
# Test story generation
curl -X POST http://localhost:5000/api/ai \
-H "Content-Type: application/json" \
-d '{"prompt":"Write a short sci-fi story","model":"llama3-8b-8192"}'
# Test image generation
curl -X POST http://localhost:5000/api/image \
-H "Content-Type: application/json" \
-d '{"prompt":"A magical forest with glowing trees"}'Press Ctrl+C in Terminal 1 to stop recording. Tests are saved in backend/keploy/tests/
cd backend
npm run keploy:testView results:
π Test Summary
β
test-1-root.yaml: PASSED
β
test-2-signup.yaml: PASSED
β
test-3-login.yaml: PASSED
β
test-4-ai-story.yaml: PASSED
β
test-5-image.yaml: PASSED
cd backend
npm run keploy:test:coveragecd backend
# Development (with auto-reload)
npm run dev
# Start production server
npm start
# Record Keploy tests
npm run keploy:record
# Run Keploy tests
npm run keploy:test
# Run tests with coverage report
npm run keploy:test:coveragecd frontend
# Development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
# Run ESLint
npm run lintAI-StoryForge-Multimodal-Story-Generator/
βββ backend/
β βββ index.js # Main server file
β βββ model/
β β βββ User.js # MongoDB User schema
β βββ keploy/
β β βββ tests/ # Recorded test cases
β β β βββ test-set-0/
β β β βββ test-1-root.yaml
β β β βββ test-2-signup.yaml
β β β βββ test-3-login.yaml
β β β βββ test-4-ai-story.yaml
β β β βββ test-5-image.yaml
β β βββ mocks/ # API mock responses
β βββ keploy.yml # Keploy configuration
β βββ package.json
β βββ .env # Environment variables (git ignored)
β βββ KEPLOY_TESTING.md # Detailed Keploy guide
βββ frontend/
β βββ src/
β β βββ components/
β β β βββ Login.jsx
β β β βββ Signup.jsx
β β β βββ StoryGenerator.jsx
β β β βββ ProtectedRoute.jsx
β β β βββ Navbar.jsx
β β βββ context/
β β β βββ AuthContext.jsx
β β βββ App.jsx
β β βββ main.jsx
β βββ package.json
β βββ vite.config.js
βββ README.md
POST /api/signup- Register new userPOST /api/login- User login, returns JWT token
POST /api/ai- Generate story- Request:
{"prompt": "your story prompt", "model": "llama3-8b-8192"} - Response:
{"response": "generated story...", "usage": {...}}
- Request:
POST /api/image- Generate image- Request:
{"prompt": "your image description"} - Response:
{"imageUrl": "data:image/png;base64,..."}
- Request:
GET /- Server status check
β MongoDB connection error
Solution: Ensure MongoDB is running
# Start MongoDB
sudo systemctl start mongod
# Or using Docker
docker run -d -p 27017:27017 mongo:latestError: Please check your firewall rules...
Solution: Run with elevated privileges
sudo keploy record -c "node index.js"β GROQ_API_KEY is not configured
Solution: Add API keys to .env file
# Get keys from:
# - Groq: https://console.groq.com
# - HuggingFace: https://huggingface.co/settings/tokens- Keploy Testing Guide - Comprehensive testing documentation
- Keploy Official Docs - Full Keploy documentation
- Groq API Docs - Groq API reference
- HuggingFace API Docs - Image generation
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Write code following the existing patterns
- Record Keploy test cases for new endpoints
- Update documentation if needed
- Test with
npm run keploy:test
This project is open source and available under the MIT License.
- Groq - For the amazing LLaMA API
- HuggingFace - For image generation capabilities
- Keploy - For the automated testing framework
- MongoDB - For the database
- All contributors and users who support this project
Feel free to open an issue or reach out on:
- GitHub Issues: Create an issue
- GitHub Discussions: Start a discussion
Happy story generating! πβ¨
