An interactive narrative game engine based on Joseph Campbell's Hero's Journey theory. Players input a keyword and character name, and the AI generates a complete 6-step hero's journey story, blending Ancient Greek mythology settings, hand gesture recognition interaction, and PDF export functionality.
- AI-Powered Dynamic Story Generation: Uses Google Gemini 2.5 Flash to generate stories following the hero's journey framework based on user input
- Three-Stage Game Flow:
- Opening Page: Immersive visual introduction
- Input Page: Enter a story theme (seed) and hero name
- Story Page: Real-time narrative experience
- Multiple Interaction Methods:
- Keyboard Input
- Gesture Recognition (MediaPipe): Use hand gestures left/right to select story paths
- Full-Screen Immersion Mode: Retro terminal-style UI
- Story Export: Automatically generate PDF books with complete story and AI-generated illustrations
- Retro-Futuristic Aesthetic: CRT scanlines, green terminal fonts, neon glow effects
- Framework: React 19.2.0 with Vite 7.2.2
- Styling: Tailwind CSS + Custom CSS (retro terminal style)
- Animations: Pure CSS keyframe animations
- LLM: Google Gemini 2.5 Flash (story generation)
- Gesture Recognition: MediaPipe Tasks Vision (real-time hand detection)
- Image Generation: Imagen API via
@google/genai(illustration generation)
- Runtime: Vercel Serverless Functions (
/api/story,/api/icon,/api/cover) - Secret Management:
GEMINI_API_KEYstored in server-side environment variables
- PDF Generation: html2pdf.js
- Build: Vite
- Linting: ESLint
- Local Full-Stack Dev: Vercel CLI (
vercel dev) - Package Manager: npm
- Deployment: Vercel (primary), GitHub Pages (static-only fallback)
- Visually striking title and narration
- Click anywhere to proceed to input stage
Step One: Enter the story theme (Language based on the input word)
Question: What is the most important thing in your life?
Examples: freedom, love, power, knowledge...
Step Two: Enter the hero's name
Question: The name of the hero is?
Examples: Orion, Artemis, Alexander...
- Steps 1-2 (Separation): The Call to Adventure and Crossing the First Threshold
- Steps 3-4 (Initiation): The Road of Trials and The Abyss
- Steps 5-6 (Return): The Ultimate Boon and Master of Two Worlds
- Step 7 (Epilogue): The Grand Title and Final Reflection
Gesture Interaction (requires camera permission)
Move hand to left 40% area → Select left option
Move hand to right 40% area → Select right option
Progress bar fills to 100% → Auto-selects choice
- Displays Grand Title: The mythical name given to the story
- Provides PDF export button
- Restart button (resets the entire narration)
MONOMYTH/
├── api/ # Serverless API routes (run on Vercel)
│ ├── story.js # Story generation endpoint
│ ├── icon.js # Background icon generation endpoint
│ ├── cover.js # Cover image generation endpoint
│ └── _lib/env.js # Local/server env loader
├── src/
│ ├── pages/
│ │ ├── opening/ # Opening page
│ │ │ ├── opening.jsx
│ │ │ └── opening.css
│ │ ├── input/ # Input page
│ │ │ ├── input.jsx
│ │ │ └── input.css
│ │ └── story/ # Story page
│ │ ├── story.jsx # Main story logic with typewriter effect & choice handling
│ │ └── story.css # Retro terminal styling
│ ├── models/ # AI & Interaction modules
│ │ ├── handChoice.jsx # Gesture recognition controller (MediaPipe)
│ │ ├── coverGenerator.jsx # PDF cover generation (Gemini Vision)
│ │ └── iconGenerator.jsx # Icon/illustration generation
│ ├── components/
│ │ ├── header/ # Page header
│ │ ├── footer/ # Page footer
│ │ └── background.jsx # Progressive background
│ ├── App.jsx # Main app component (manages three-stage state)
│ ├── constants.js # System prompt and max steps config
│ └── main.jsx # App entry point
├── index.html
├── package.json
├── vercel.json
├── vite.config.js
├── .env.local # Local environment variables (git-ignored)
└── README.md # This file
- Node.js 18+
- npm
- Vercel CLI (
npm i -g vercel) - Google AI Studio API key (for Gemini access)
git clone https://github.com/SihongShen/MONOMYTH.exe.git
cd MONOMYTHnpm installtouch .env.localEdit .env.local and add your API key:
GEMINI_API_KEY=your_gemini_api_key_hereHow to Get an API Key:
- Visit Google AI Studio
- Click "Create API Key"
- Select a new or existing project
- Copy the generated key to your
.env.localfile
- Never hardcode API keys in source code
- Add
.env.localto.gitignore(already included) - Exposed keys can be abused; protect them carefully
npm run dev:localOpen your browser and visit http://localhost:3000
npm run devUse this mode only for UI work. API routes in /api/* are not served in this mode.
npm run build
npm run preview # Preview production build locallynpm run deploynpm run deploy deploys to Vercel production.
If you need static-only GitHub Pages deployment:
npm run deploy:pages<Typewriter
text={node.narrative}
isLatest={isLatest}
speed={25}
onComplete={handleTypewriterComplete}
/>- Displays story text character by character with blinking cursor
- Animation only plays for the latest story node
- Triggers
onCompletecallback when finished
<HandChoiceController
leftOption="Choice A Text"
rightOption="Choice B Text"
onSelect={(selected) => handleChoice(selected)}
/>- Real-time webcam input (requires user permission)
- Auto-triggers when hand is in left/right 40% area for 2-3 seconds
- Visual progress bar feedback
- Shows ghost hand animation when no hand is detected
- Generates artistic illustrations for stories
- Uses Gemini Vision API
- Integrated into PDF export workflow
- Classic CRT scanline effect
- CSS gradients and keyframe animations
- Smooth transitions
Story generation relies on a carefully designed system prompt (see src/constants.js) that includes:
- Separation (Steps 1-2): Call to Adventure, Refusal, Crossing Threshold
- Initiation (Steps 3-4): Road of Trials, The Abyss, Dark Ordeal
- Return (Steps 5-6): Ultimate Boon, Magic Flight, Return Threshold
- Resolution (Step 7): Grand Title, Final Reflection
- Setting: Strictly Ancient Greek/Mediterranean mythology
- Forbidden Elements: No sci-fi terminology (code, glitch, system, dimension)
- Required Elements: Sensory details (sight, sound, smell, touch, psyche), metaphors, mythological archetypes
- Avoid binary opposites (yes/no, stay/leave)
- Offer two different methods of engagement rather than simple branches
{
"narrative": "Story text",
"choices": [
{
"id": "A",
"shortDesc": "Brief description",
"text": "Narration after choice"
},
{
"id": "B",
"shortDesc": "Brief description",
"text": "Narration after choice"
}
],
"title": "Step title",
"step": 1,
"stage": "SEPARATION",
"grandTitle": "Story final name (only in epilogue)"
}Opening Page
↓ (Click anywhere)
Input Page - Step 1
Enter theme keyword (e.g., "freedom")
↓ (Press Enter)
Input Page - Step 2
Enter hero name (e.g., "Orion")
↓ (Press Enter)
Input Page - Step 3 (Loading progress bar)
↓ (Progress reaches 100%)
Story Page - Step 1
Display story text (typewriter effect)
↓ (Click option or gesture)
Story Page - Steps 2-6
Repeat choice → Next step
↓ (Complete step 6)
Story Page - Epilogue (Step 7)
Display story grand title
↓ (Click export or restart)
Story Export/Reset
| Feature | Desktop | Tablet | Mobile |
|---|---|---|---|
| Story Reading | ✅ | ✅ | ✅ |
| Button Selection | ✅ | ✅ | ✅ |
| Gesture Recognition | ✅ | ||
| PDF Export | ✅ | ✅ |
# Google Gemini API Key (get from https://aistudio.google.com)
VITE_GEMINI_API_KEY=your_api_key_here
# (Optional) Custom API endpoint
# VITE_API_ENDPOINT=https://your-custom-endpoint.com
# (Optional) Debug mode
# VITE_DEBUG=trueVITE_GEMINI_API_KEY(required): Google AI API key- All
VITE_prefixed variables are exposed to client code - Non-
VITE_prefixed variables are only used during build time
Edit SYSTEM_INSTRUCTION in src/constants.js:
export const SYSTEM_INSTRUCTION = `
// Modify story framework, style, constraints, etc.
`;Embark on your hero's journey! 🌟