Project 6 of ~34

🎮 AI Dungeon Master — Architecture

TTRPG campaign engine via Discord + AI. State stored in Markdown/JSON. Ollama on Mac Mini for DM logic. MiniMax for high-quality narrative generation.

🏗️ Architecture Overview

┌──────────────────────────────────────────────────┐ │ INTERFACE │ │ ┌─────────────┐ ┌──────────────┐ ┌──────────┐ │ │ │ Discord Bot │ │ Web Chat UI │ │ Email │ │ │ │ (Primary) │ │ (Fallback) │ │ Recaps │ │ │ └──────┬──────┘ └──────┬───────┘ └───┬──────┘ │ └──────────┼────────────────┼─────────────┼─────────┘ │ │ │ ▼ ▼ ▼ ┌──────────────────────────────────────────────────┐ │ DM AGENT (Deno) │ │ ┌────────────┐ ┌────────────┐ ┌───────────┐ │ │ │ Session │ │ NPC Memory │ │ Combat │ │ │ │ Manager │ │ Engine │ │ Engine │ │ │ └────────────┘ └────────────┘ └───────────┘ │ │ ┌────────────┐ ┌────────────┐ ┌───────────┐ │ │ │ Quest Gen │ │ Recap Gen │ │ Character │ │ │ │ (Ollama) │ │ (MiniMax) │ │ Builder │ │ │ └────────────┘ └────────────┘ └───────────┘ │ └──────────────────────────────────────────────────┘ │ │ ▼ ▼ ┌─────────────────────┐ ┌────────────────────────┐ │ STATE FILES │ │ AI RUNTIME │ │ campaign/ │ │ ┌──────────────────┐ │ │ ├── session_3.md │ │ │ Ollama (Mac Mini)│ │ │ ├── npcs.json │ │ │ Mistral 7B │ │ │ ├── party.json │ │ │ (DM reasoning) │ │ │ └── world.json │◄────│ └──────────────────┘ │ │ (Git-tracked) │ │ ┌──────────────────┐ │ └─────────────────────┘ │ │ MiniMax API │ │ │ │ (Narrative) │ │ │ └──────────────────┘ │ └────────────────────────┘

🛠️ Tech Stack

ComponentTechnologyWhy
Primary InterfaceDiscord.js / DiscordenoPlayers already use Discord. Bot commands + slash commands for game actions.
Web FallbackSvelteKitWeb-based game table for players who don't use Discord
BackendDeno 2Runs on Mac Mini, handles all DM logic
State StorageGit + Markdown/JSONCampaign state in flat files. Git history = automatic session log. Easy to back up, easy to inspect.
AI (DM Logic)Ollama Mistral 7BOn Mac Mini. Handles NPC dialogue, quest hooks, combat narration. Fast enough for real-time.
AI (Quality Narrative)MiniMax M2.1For session recaps and important story moments where quality matters more
Recap DeliveryResend (email)Weekly recap emails for absentees
HostingMac Mini (home) + Deno Deploy (optional)Discord bot runs 24/7 on Mac Mini. Deno Deploy as cloud fallback.

🗄️ Data Model (Flat Files)

All campaign state is stored as Markdown + JSON files in a campaigns/{campaign_id}/ directory. Git-tracked. This is the simplest possible database that a DM would actually enjoy using.

party.json
characters[][{name, class, level, hp, stats, inventory, notes}]
npcs.json
npcs[][{id, name, location, personality, relationships: {pc_name: "ally"/"enemy"/"neutral"}, secrets, last_seen_session}]
session_N.md
Markdown log of the session: narration, dice rolls, player actions, DM decisions. Used for recap generation and NPC memory updates.
world.json
world{name, description, factions[], locations[], ongoing_plots[], session_count}
campaign_config.json
config{genre, tone, homebrew_rules, ai_temperature, dm_personality}

🤖 AI DM Pipeline

🎲 Dice + Combat
Player rolls dice in Discord. Bot parses: "/roll 2d20+5". Ollama Mistral 7B evaluates the outcome: "That's a 17 and a 23, plus 5... you hit! The goblin takes 18 damage." Handles attack rolls, saves, skill checks with appropriate NPC reactions.
🗣️ NPC Dialogue
When player talks to NPC: system prompt loads NPC's personality + relationships + secrets from npcs.json. Ollama generates dialogue in character. MiniMax fallback for complex social encounters.
📜 Quest Hook Generation (pre-session)
Before session, bot analyzes party composition + world state + NPC relationships. Ollama drafts 3 quest options. DM (human) picks one or asks for variations. Selected quest's branch tree is saved.
📰 Session Recap (post-session)
After session, concatenate all session_N.md logs. Send to MiniMax M2.1 for polished recap generation. Format: what happened, key decisions, NPC developments, cliffhanger for next session. Send via Resend to all players.
🔄 NPC Memory Update
After each player interaction, Ollama extracts NPC state changes and updates npcs.json. "Lord Blackwood: now suspects party of theft (was neutral). Added secret: hiding stolen artifact."

Requirements  |  All Projects  |  Presentation →