🏆 Devpost Submission: Varys Chronicles
💡 Inspiration
The inspiration for Varys Chronicles stems from legendary internet events like Twitch Plays Pokémon and active collaborative writing communities like r/WritingPrompts or r/HFY. We wanted to explore what happens when thousands of creative minds collaborate on a single story.
However, running these events manually is a nightmare for moderators—compiling comments, calculating upvotes, chasing ties, writing summaries, editing massive posts, keeping contributors updated, and tracking scores. We wanted to build a fully automated narrative machine—an AI-powered Dungeon Master hosted directly on Reddit that allows the community to co-author a high-quality interactive novel, completely hand-off for moderators.
📖 What it does
Varys Chronicles is an autonomous, community-driven storytelling platform built natively for Reddit via Devvit. It transforms a standard subreddit post into an active "Choose-Your-Own-Adventure" game:
- The Core Loop: Once installed, it creates an initial story post with an opening page and starts an automated voting window. Users write their ideas as comments and upvote their favorite directions.
- Automated Narrator (Gemini AI): At the deadline, a scheduled job filters comments and sends the story context + winning suggestion to Google Gemini to write a vivid, highly engaging multi-paragraph next chapter matching the subreddit's configured genre (e.g., Dark Fantasy, Sci-Fi).
- Live Flair Countdowns: The post's flair automatically counts down every 5 minutes in real-time (e.g.,
"⏳ Voting open — 25m left"), shifting to"🔒 Generating..."and"✅ Chapter is live!"so the community feels the post is alive. - Gamified Contributor Recognition: Winners receive massive recognition. The bot replies directly to their winning comment in the thread and sends them a private Reddit DM containing their co-author credit, the written chapter, and their total wins pulled from Redis.
- Subreddit Leaderboards: The app automatically increments user scores on a persistent Redis Sorted Set Leaderboard, posting a formatted scoreboard weekly and on-demand via a mod menu trigger.
- Interactive Webview Book Reader: Users can tap a custom button on the post to open a gorgeous React-based 3D digital book, turning pages to read the entire community-written adventure.
🛠️ How we built it
We built Varys Chronicles entirely within the Reddit Developer Platform (Devvit) utilizing serverless architecture:
- Engine & Logic: Devvit SDK 0.12.24 written in TypeScript, using
addTriggerfor installation andaddSchedulerJobto handle deadlines, weekly score tracking, and flair animations. - AI Integration: Google Gemini API calling
gemini-2.0-flash-lite(with a programmatic fallback togemini-2.0-flash) using detailed custom developer instructions to ensure structural narrative compliance and consistent word counts. - Database & Persistence: Devvit Redis (
context.redis) for high-speed key-value operations. We used string registers for story states, deadlines, locks, and chapter cutoff boundaries, and Redis Sorted Sets (vc:leaderboard:{subredditName}) to manage contributor win statistics. - Frontend Webview: Built with React 18 and custom CSS. We isolated React types inside a nested folder structure and separate compilation schema to build a responsive, paginated book interface with gorgeous layouts.
🚧 Challenges we ran into
- Global JSX Type Collisions: Because Devvit declares global JSX namespaces for its block elements, importing React 18 types triggered immediate typescript errors. We solved this by isolating our React book reader into a nested
src/webview/folder with an independenttsconfig.jsoncontaining specific node/react configurations, excluding it from the root compiler. - Workaround for Lack of Redis Sets: Devvit Redis does not currently support standard Set operations like
SISMEMBER. To ensure each comment ID only wins once, we designed an O(1) string key system (vc:won:{postId}:{commentId}) to serve as a fast membership register. - Post Editing Restrictions (403 Forbidden): Initially, we planned to edit the body of the original post to append new chapters. However, we discovered Devvit apps lack permission to edit posts they do not own. We turned this limitation into a design feature by publishing new chapters as styled top-level comments and credit replies, making the comment section highly active and engaging.
- Graceful DM Failures: Some users completely disable DMs on Reddit. We wrapped our winner private messaging system in isolated try/catch logs, ensuring that even if a DM fails, the bot continues to credit them in the public comment thread without stopping the loop.
🏆 Accomplishments that we're proud of
- Zero-Touch Automation: The entire story generation, winner selection, flair updates, leaderboards, and user messaging flow runs completely on its own. A moderator only has to install the app once.
- Premium User Engagement: The private message winner notifications feel incredibly premium—sending the user their winning prompt quoted back to them alongside a co-author co-credit lines and their official winner counts.
- A Clean, Lint-Free Codebase: Successfully structured the dual-compiler TypeScript setup to compile flawlessly with zero linting or type errors.
- Indian Standard Time (IST) Localizations: Built helper modules (
utils/time.ts) to ensure all scheduling dates, post countdown calculations, and developer logs are accurately adjusted to IST, facilitating seamless local testing and deployment.
🏫 What we learned
- Advanced Asynchronous Scheduling: We mastered chaining short-interval background jobs (
updateFlairevery 5 mins) alongside long-interval jobs (weeklyLeaderboardevery 7 days) without causing thread blocks or Redis race conditions. - AI Novel Writing Prompt Engineering: We learned how to guide Gemini to write stories that are structured cleanly (4 paragraphs, 350-500 words) while keeping the tone strictly matching the selected genre.
- Devvit Ecosystem Security: Utilizing Devvit App Settings securely locks away API keys so they are never exposed to the frontend webview client.
🚀 What's next for Varys Chronicles
We want to expand Varys Chronicles into a premier collaborative game engine:
- Interactive Story Branching: Introduce branching pathways where the community can vote on multiple concurrent paths, allowing the story to split and merge.
- RPG Character Attributes: Let players register characters and accumulate experience points and customized RPG stats on the Redis leaderboard based on their winning prompt contributions.
- AI Visual Illustrations: Reinstate DALL-E 3 / Imagen visual generation to create a custom cover image and page illustrations for every single chapter in the book webview.
- Compilation Export: Allow subreddits to export their completed collaborative novels as beautifully formatted PDFs or EPUB files to preserve the community's masterpiece forever.

Log in or sign up for Devpost to join the conversation.