A collaborative storytelling platform for Reddit where the community votes on what happens next. Built with Reddit Devvit, powered by AI.
The Infinite Story Engine transforms a Reddit post into an interactive story where:
- Community members submit story prompts via comments
- The most upvoted prompt wins
- AI (GPT-4o + DALL-E 3) generates the next chapter with an illustration
- The story is displayed in a beautiful book reader with page-flip animations
- Community Voting: Native Reddit upvoting determines story direction
- AI Generation: GPT-4o creates story continuations, DALL-E 3 generates illustrations
- Immersive Reader: 3D page-flip animations in a webview book reader
- Scheduled Jobs: Automatic deadline processing and content generation
- Content Moderation: Banned word filtering and OpenAI moderation
- Error Handling: Graceful fallbacks and comprehensive logging
- Node.js 18+ and npm
- Reddit Developer Account
- OpenAI API Key (with GPT-4o and DALL-E 3 access)
- Devvit CLI installed:
npm install -g devvit
-
Clone and Install Dependencies
npm install
-
Configure Devvit
devvit login
-
Build the Project
npm run build
-
Upload to Reddit
npm run upload
-
Install on Your Subreddit
- Go to your subreddit's mod tools
- Navigate to Apps
- Install "Infinite Story Engine"
-
Configure Settings
- Set your OpenAI API key (required)
- Customize story title, genre, and opening paragraph
- Set voting duration (default: 60 minutes)
- Add banned words for content moderation (optional)
infinite-story-engine/
โโโ src/
โ โโโ main.tsx # App entry point
โ โโโ types/
โ โ โโโ index.ts # TypeScript interfaces
โ โโโ handlers/
โ โ โโโ install.ts # Installation handler
โ โ โโโ scheduler.ts # Deadline processing
โ โ โโโ webview.ts # API routes
โ โโโ services/
โ โ โโโ storage.ts # Redis operations
โ โ โโโ reddit.ts # Reddit API wrapper
โ โ โโโ openai.ts # OpenAI integration
โ โโโ utils/
โ โ โโโ validation.ts # Content moderation
โ โโโ webview/
โ โโโ App.tsx # React root
โ โโโ components/
โ โ โโโ BookCover.tsx # Cover page
โ โ โโโ StoryPage.tsx # Story page
โ โโโ styles/
โ โโโ book.css # 3D animations
โโโ devvit.yaml # Devvit configuration
โโโ tsconfig.json # TypeScript config
โโโ package.json # Dependencies
- App creates an initial story post with opening paragraph
- Sets up Redis storage for story state
- Schedules deadline job for voting window
- Users comment with story ideas
- Community upvotes/downvotes prompts
- Native Reddit voting mechanics
- Scheduled job triggers at deadline
- Fetches and filters comments
- Selects winner (highest upvotes, earliest for ties)
- Calls OpenAI APIs for text and image generation
- Updates post with new chapter
- Saves to Redis
- Webview displays story as a book
- Page-flip animations between chapters
- Credits winning authors
- Responsive design for mobile/desktop
| Setting | Type | Default | Description |
|---|---|---|---|
openai_api_key |
Secret | - | Your OpenAI API key (required) |
voting_duration_minutes |
Number | 60 | How long voting stays open |
story_title |
String | "The Infinite Story" | Title of your story |
story_genre |
String | "Fantasy" | Genre for AI context |
opening_paragraph |
Text | Default text | First paragraph |
banned_words |
String | "" | Comma-separated banned words |
story:{postId}- Story state and chaptersdeadline:{postId}- Voting deadline timestampjob:{postId}- Job processing status
Edit src/webview/styles/book.css to customize:
- Colors and fonts
- Page layout
- Animation timing
- Responsive breakpoints
Modify src/services/openai.ts:
- System prompts for story generation
- Image generation prompts
- Temperature and creativity settings
Adjust src/services/reddit.ts:
- Winner selection algorithm
- Comment filtering rules
- Tie-breaking logic
"OpenAI API key not configured"
- Ensure you've set the API key in app settings
- Key must have access to GPT-4o and DALL-E 3
"No valid comments found"
- App uses fallback prompt automatically
- Check banned words aren't too restrictive
"Image generation failed"
- App continues with text-only
- Check OpenAI API quota and permissions
"Job already processed"
- Idempotency check prevents duplicate processing
- Safe to ignore if job completed successfully
Enable verbose logging:
// In src/main.tsx
console.log('Debug info:', data);Check Redis state:
devvit redis get story:{postId}- Webview Load: < 2s on 4G
- AI Generation: < 30s (with 25s timeout)
- Full Cycle: < 2 minutes (voting โ generation โ update)
- API keys stored in Devvit Secrets (never exposed to client)
- Content sanitization on all user inputs
- OpenAI moderation endpoint for inappropriate content
- Banned word filtering
- Rate limiting via OpenAI API
npm run devnpm run buildnpm run lintnpm run upload- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
ISC License - See LICENSE file for details
- Built with Reddit Devvit
- Powered by OpenAI GPT-4o and DALL-E 3
- Inspired by collaborative storytelling communities
For issues and questions:
- Check the Troubleshooting section
- Review Devvit Documentation
- Open an issue on GitHub
- Multi-chapter support (extend beyond Day One)
- Story branching (multiple paths)
- User profiles and leaderboards
- Export stories as PDFs
- Custom illustration styles
- Voice narration
- Mobile app integration
Made with โค๏ธ for Reddit Hackathon 2026