Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

154 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Lorelic Logo

Lorelic

An AI-Powered Interactive Narrative RPG Engine

Features โ€ข Themes โ€ข Getting Started โ€ข Architecture โ€ข API Reference โ€ข Contributing

Node.js Express Prisma PostgreSQL Gemini AI


Overview

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.


Features

๐ŸŽฎ Core Gameplay

  • 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

๐Ÿ“Š Character Systems

  • 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 Building

  • 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

๐Ÿ‘ค User Management

  • 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

Themes

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

Getting Started

Prerequisites

  • Node.js 18.x or higher
  • PostgreSQL database
  • Google AI API Key (Gemini access)

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/lorelic.git
    cd lorelic
  2. Install server dependencies

    cd server
    npm install
  3. Configure environment variables

    Create a .env file in the server directory:

    # 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"
  4. Initialize the database

    npx prisma migrate deploy
    npx prisma generate
  5. Start the server

    npm start
  6. Access the application

    Open http://localhost:3000 in your browser.

Development Mode

For hot-reloading during development:

npm run dev

Architecture

lorelic/
โ”œโ”€โ”€ 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

Tech Stack

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

API Reference

Authentication

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

Game State

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

AI Generation

Endpoint Method Description
/api/v1/gemini/generate POST Generate AI narrative response

World Shards

Endpoint Method Description
/api/v1/world-shards/:themeId GET Get unlocked shards for theme
/api/v1/world-shards POST Save new world shard

Game Mechanics

Attribute System

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

Progression

  • 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

Configuration

Model Tiers

// 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 tier

Theme Configuration

Each theme requires:

  • config.json โ€” Theme metadata, attributes, equipment slots
  • texts.json โ€” Localized strings for UI and narrative
  • prompts-config.json โ€” AI prompt templates and configurations
  • prompts/ โ€” Detailed prompt files for the AI Game Master

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Creating New Themes

See the existing themes in the themes/ directory as templates. Each theme requires:

  • Complete config.json with attribute definitions and UI configurations
  • Localized texts.json for all theme-specific strings
  • AI prompt files tailored to the theme's narrative style
  • Theme-specific images and icons

License

This project is licensed under the ISC License. See the LICENSE file for details.


Acknowledgments

  • Google Gemini โ€” Powering the AI narrative engine
  • Prisma โ€” Elegant database access and migrations
  • Express โ€” Fast, unopinionated web framework

Built with โค๏ธ for storytellers and adventurers

About

Web-based interactive fiction platform that combines the depth of tabletop RPG mechanics with the power of generative AI.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages