An AI-Powered Interactive Narrative RPG Engine
Features โข Themes โข Getting Started โข Architecture โข API Reference โข Contributing
Lorelic is a sophisticated web-based interactive fiction platform that combines the depth of tabletop RPG mechanics with the power of generative AI. Players embark on unique narrative adventures across multiple thematic worlds, with an AI Game Master that dynamically responds to their choices, creating emergent stories that evolve based on player decisions.
The engine features persistent character progression, rich world-building systems, and a flexible theme architecture that allows for diverse narrative experiencesโfrom gothic monster hunting to high-seas piracy and cosmic custodial adventures.
- AI-Driven Narratives โ Powered by Google's Gemini models for dynamic, contextual storytelling
- Persistent Character Progression โ Level up characters with XP, unlock traits, and build unique abilities
- Multiple Playable Themes โ Each theme offers distinct settings, mechanics, and narrative tones
- Dice Roll Integration โ Traditional TTRPG mechanics interpreted by the AI for consistent challenge resolution
- Four Core Attributes โ Integrity, Willpower, Aptitude, and Resilience govern all character interactions
- Trait System โ Unlock and choose from theme-specific traits as you level up
- Equipment & Inventory โ Theme-appropriate gear with static and consumable item types
- Dynamic Conditions โ Temporary states that affect gameplay based on narrative events
- World Shards โ Persistent lore fragments unlocked through gameplay that carry across sessions
- Theme-Specific Dashboards โ Rich UI panels displaying objectives, relationships, and world state
- Localization Support โ Full multi-language support for both UI and narrative content
- Tiered Access System โ Free, Pro, and Ultra tiers with configurable usage limits
- Secure Authentication โ JWT-based auth with email confirmation and password reset
- Cloud Save โ Automatic game state persistence across devices
Lorelic ships with several distinct narrative themes:
| Theme | Setting | Tone |
|---|---|---|
| Grim Warden | Gothic monster hunting | Dark, atmospheric horror |
| Salt Reavers | Pirate adventures on cursed seas | Swashbuckling action |
| Celestial Custodians | Cosmic janitors in bizarre stations | Absurdist comedy |
| Echo Sleuths | Memory detectives in surreal mindscapes | Noir mystery |
Each theme includes:
- Custom configuration and mechanics
- Unique equipment slots and currency
- Theme-specific traits and progression
- Dedicated prompt systems and lore
- Node.js 18.x or higher
- PostgreSQL database
- Google AI API Key (Gemini access)
-
Clone the repository
git clone https://github.com/yourusername/lorelic.git cd lorelic -
Install server dependencies
cd server npm install -
Configure environment variables
Create a
.envfile in theserverdirectory:# Database DATABASE_URL="postgresql://user:password@localhost:5432/lorelic" DIRECT_URL="postgresql://user:password@localhost:5432/lorelic" # Authentication JWT_SECRET="your-secure-jwt-secret" JWT_EXPIRES_IN="7d" # Google AI GEMINI_API_KEY="your-gemini-api-key" # Server PORT=3000 NODE_ENV=development ALLOWED_ORIGINS="http://localhost:3000"
-
Initialize the database
npx prisma migrate deploy npx prisma generate
-
Start the server
npm start
-
Access the application
Open
http://localhost:3000in your browser.
For hot-reloading during development:
npm run devlorelic/
โโโ index.html # Main application entry point
โโโ style.css # Global styles
โโโ js/
โ โโโ app.js # Application bootstrap
โ โโโ core/ # Core services (API, config, state, logging)
โ โโโ data/ # Static data and manifests
โ โโโ game/ # Game controller logic
โ โโโ services/ # Business logic (AI, auth, themes, localization)
โ โโโ ui/ # UI managers and components
โโโ server/
โ โโโ server.js # Express server entry point
โ โโโ config.js # Server configuration
โ โโโ middleware/ # Auth and rate limiting middleware
โ โโโ routes/ # API route handlers
โ โโโ utils/ # Helper utilities (dice, tokens, AI)
โ โโโ prisma/ # Database schema and migrations
โโโ themes/
โ โโโ master/ # Base theme configuration
โ โโโ grim_warden/ # Gothic monster hunting theme
โ โโโ salt_reavers/ # Pirate adventure theme
โ โโโ celestial_custodians/ # Cosmic comedy theme
โ โโโ echo_sleuths/ # Memory detective theme
โโโ images/ # Application and theme assets
| Layer | Technology |
|---|---|
| Frontend | Vanilla JavaScript (ES Modules), CSS3 |
| Backend | Node.js, Express 5.x |
| Database | PostgreSQL with Prisma ORM |
| AI Engine | Google Gemini (Flash/Pro models) |
| Authentication | JWT with bcrypt password hashing |
| Security | Helmet.js, CORS, rate limiting |
| Endpoint | Method | Description |
|---|---|---|
/api/v1/auth/register |
POST | Create new user account |
/api/v1/auth/login |
POST | Authenticate user |
/api/v1/auth/confirm-email |
GET | Confirm email address |
/api/v1/auth/forgot-password |
POST | Request password reset |
/api/v1/auth/reset-password |
POST | Reset password with token |
| Endpoint | Method | Description |
|---|---|---|
/api/v1/gamestates |
GET | Retrieve user's game states |
/api/v1/gamestates |
POST | Save current game state |
/api/v1/gamestates/:themeId |
DELETE | Delete game state for theme |
| Endpoint | Method | Description |
|---|---|---|
/api/v1/gemini/generate |
POST | Generate AI narrative response |
| Endpoint | Method | Description |
|---|---|---|
/api/v1/world-shards/:themeId |
GET | Get unlocked shards for theme |
/api/v1/world-shards |
POST | Save new world shard |
| Attribute | Base Value | Purpose |
|---|---|---|
| Integrity | 100 | Health/structural wholeness โ reaching zero ends the game |
| Willpower | 50 | Resource pool for special abilities and extraordinary actions |
| Aptitude | 10 | Passive modifier improving action quality and success |
| Resilience | 10 | Defensive modifier reducing negative effect severity |
- Characters earn XP by completing objectives and overcoming challenges
- Each level grants 1 Attribute Point and a choice of 3 random Traits
- Character progression persists across game sessions within each theme
- Equipment and currency reset each session for roguelike replayability
// server/middleware/usageLimiter.js
FREE_MODEL = 'gemini-2.5-flash-lite-preview-06-17' // Free tier
PRO_MODEL = 'gemini-2.5-flash' // Pro tier
ULTRA_MODEL = 'gemini-2.5-flash' // Ultra tierEach theme requires:
config.jsonโ Theme metadata, attributes, equipment slotstexts.jsonโ Localized strings for UI and narrativeprompts-config.jsonโ AI prompt templates and configurationsprompts/โ Detailed prompt files for the AI Game Master
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
See the existing themes in the themes/ directory as templates. Each theme requires:
- Complete
config.jsonwith attribute definitions and UI configurations - Localized
texts.jsonfor all theme-specific strings - AI prompt files tailored to the theme's narrative style
- Theme-specific images and icons
This project is licensed under the ISC License. See the LICENSE file for details.
- Google Gemini โ Powering the AI narrative engine
- Prisma โ Elegant database access and migrations
- Express โ Fast, unopinionated web framework
Built with โค๏ธ for storytellers and adventurers