An intelligent, AI-powered Game Master designed to create dynamic and engaging role-playing experiences with minimal setup.
Explore the Frontend Repo »
·
Explore the Backend Repo »
Table of Contents
The Chronicler's Codex is a backend project aimed at creating a smart Game Master (GM) that can run narrative-driven role-playing games. The core philosophy is to leverage Large Language Models (LLMs) not just as storytellers, but as reasoning engines that can dynamically adapt the game based on player actions.
This project eliminates the need for extensive preparation typically associated with TTRPGs, allowing a player to jump straight into a unique, responsive adventure defined by a truly interactive game loop.
This project is built using a pragmatic Hexagonal Architecture (Ports and Adapters) to ensure a clean separation of concerns and high maintainability.
graph TD
subgraph Infrastructure
A[Adapters: Web, Persistence, AI]
end
subgraph Application
B[Use Cases, Ports, Services]
end
subgraph Domain
C[Core Models & Rules]
end
A -- Calls --> B
B -- Uses --> C
style A fill:#2d2d34,stroke:#c3073f,stroke-width:2px,color:#fff
style B fill:#2d2d34,stroke:#6f2232,stroke-width:2px,color:#fff
style C fill:#2d2d34,stroke:#4b5d67,stroke-width:2px,color:#fff
Dependencies always point inwards, from Infrastructure to Application to Domain.
The game's core loop is a stateful, multi-step dialogue between the client and the server, creating an interactive experience.
sequenceDiagram
participant Player as Player
participant Client as Client (Frontend)
participant Backend as Backend (GameService)
participant AI as AI (LLM)
Player->>+Client: Submits action text (e.g., "I try to pick the lock")
Client->>+Backend: POST /api/.../action
Backend->>+AI: Reason and propose action (sends full game context)
AI-->>-Backend: Returns JSON { narration, requiredAction }
Backend-->>-Client: Returns ActionConsequenceDTO
Note over Client: Displays narration and "Roll Dice" button
Player->>+Client: Clicks "Roll Dice"
Client->>+Backend: POST /api/.../resolve
Note over Backend: Executes dice roll via RulesEngine
Backend->>+AI: Narrate Outcome (sends mechanical result and game context)
AI-->>-Backend: Returns JSON { narration, stateUpdates }
Note over Backend: Applies state updates to DB
Backend-->>-Client: Returns final ActionConsequenceDTO
deactivate Client
Note over Client: Displays narration
- Backend: Java 24, Spring Boot 3, Spring AI, Spring Data JPA
- Database: PostgreSQL (with
jsonbsupport) - AI Backend: Configured for any OpenAI-compatible API (defaulting to OpenRouter) and includes a profile for local use with Ollama.
- API Docs: SpringDoc OpenAPI 3 (Swagger UI)
- Build Tool: Apache Maven
This backend is designed to be flexible. You can run it locally with Ollama for easy testing, or connect it to a cloud-based AI provider like OpenRouter. To get a local copy up and running, follow these simple steps.
- JDK 24 or later.
- Apache Maven 3.8+.
- Docker (for the PostgreSQL database).
-
Clone the repo:
git clone https://github.com/Juangr4/chroniclers-codex.git cd chroniclers-codex -
Choose your AI Provider Setup:
Option A: Cloud API (Recommended - OpenRouter) This is the default configuration. OpenRouter is a service that gives you access to many different models through a single, OpenAI-compatible API.
- Get a free API Key from OpenRouter.ai.
- Create a
.envfile in the root of the project. - Add your API key to the
.envfile:OPENAI_API_KEY=YOUR_OPENROUTER_API_KEY
Option B: Local Setup (Ollama) If you prefer to run the AI model locally.
- You will need to activate the
ollamaprofile when running the application.
-
Run the application:
- For Cloud API (Default):
./mvnw spring-boot:run
- For Local Ollama Setup:
./mvnw spring-boot:run -Dspring-boot.run.profiles=ollama
- For Cloud API (Default):
Spring Boot will automatically start the PostgreSQL database and ollama containers via its Docker Compose support.
For the complete experience, you need to run both the backend and the frontend.
- Follow the "Getting Started" steps above to run the backend.
- Clone and run the frontend client by following the instructions in its repository: ➡️ The Chronicler's Codex - Frontend Repo
This project uses springdoc-openapi to automatically generate API documentation. Once the application is running, you can access the interactive Swagger UI here:
➡️ http://localhost:8080/swagger-ui.html
- Interactive, AI-Driven Game Loop: A multi-step "Reason -> Resolve -> Narrate" flow.
- Structured AI Communication: AI communicates via reliable JSON contracts.
- Session Management API: Full CRUD operations for game sessions.
- Dynamic State Management: Player and world state are updated by AI decisions.
- Robust Error Handling: Custom exception hierarchy and global handler.
- Multilingual Support: Game sessions can be run in different languages via prompt engineering.
- Flexible Configuration: Support for multiple environments and AI providers via Spring Profiles.
- Voice I/O: Implement endpoints to handle voice-to-text and text-to-voice for a more immersive experience.
- AI Image Generation: Add an API to generate images for key scenes, characters, or locations based on the narrative.
- Dynamic Campaign Creation: Allow the AI to generate custom campaigns.
- Dynamic Character Creation: Allow the AI to assist in creating characters tailored to a generated campaign via API calls.
- Advanced AI Memory: Implement a vector database for long-term memory, allowing for more coherent, long-running campaigns by using RAG features to improve game context.
Distributed under the MIT license. See LICENSE.md for more information.