TuiEngine 🛠️ Powered by Bun & OpenTUI

Multiplayer SSH & Web Games in the Terminal

A high-performance, authoritative multiplayer game engine. Write game mechanics and ANSI graphics, while TuiEngine orchestrates SSH/Web routing, SQLite schemas, real-time loops, and admin control panels.

$ bun create github.com/thoughtlesslabs/tuicraft my-game
tuicraft - live_arena.ts (Web SSH Viewport)
ONLINE (Port 2222)
+--------------------------------------------------+
| # # # # # # # # # # # # # # # # # # # # # # # #  |
| # . . . . . . . . . . . . . . . . . . . . . . #  |
| # . @ . . . . . . . . . . . . . . . . . . . . #  |
| # . . . . . . . . . # # # # . . . . . . . . . #  |
| # . . . . . . . . . # . . # . . . . . A . . . #  |
| # . . . . B . . . . # . . # . . . . . . . . . #  |
| # . . . . . . . . . # # # # . . . . . . . . . #  |
| # . . . . . . . . . . . . . . . . . . . . . . #  |
| # # # # # # # # # # # # # # # # # # # # # # # #  |
+--------------------------------------------------+
          
Click inside terminal, then use WASD or to move
[System] Starting authoritative tick loop (300ms)...
[System] SQLite loaded: data/mygame.db
[SSH] Listening on port 2222
[Web] Socket bridge opened on port 3000
[Join] player_guest connected.
player_guest: hello from the terminal!
[Join] bot_adventurer connected.
bot_adventurer: cool, real-time multiplayer!
>
ENGINES & INFRASTRUCTURE

Everything Built-in, Out-of-the-Box

TuiEngine is a blank-slate template configured to get you building terminal graphics immediately.

Dual Network Server

Playable natively over standard terminal SSH (`ssh localhost -p 2222`) OR in browser using a proxy WebSocket to xterm.js wrapper.

Authoritative Game Loop

Central action queue that executes inputs sequentially per tick (default 300ms) with auto-saving, state tracking, and idle room sweeping.

SQLite DB Integration

Utilizes `bun:sqlite` with predefined schemas for session recovery, bans, keys, chat logs, and hooks to easily register custom gameplay tables.

Admin Control Console

Beautiful, separate SSH control screen on port 2223 with TOFU public key security to kick/ban users, broadcast alerts, and trigger custom commands.

Model Context Protocol (MCP)

Built-in AI server allowing LLM agents, players, or developer bots to connect, inspect rooms, fetch logs, and trigger game controls dynamically.

Docker Orchestration

Docker Compose layouts and optimized multi-stage Slim builds containing curve25519 fixes for seamless deployments on Ubuntu/VPS nodes.

GETTING STARTED

Build Your First Multiplayer TUI

Bootstrap a production-ready repository structure in seconds.

index.ts
import { TuiEngine, BoxRenderable } from "tuiengine";

// 1. Instantiate the TuiEngine
const engine = new TuiEngine({
  databasePath: "data/mygame.db",
  tickRateMs: 300,
  onPlayerSession: handlePlayerSession
});

// 2. Handle the player rendering loop & UI layout
function handlePlayerSession(session) {
  const { renderer } = session;
  
  // Draw boxes and controls using OpenTUI components
  const box = new BoxRenderable(renderer.root.ctx, {
    width: "100%",
    height: "100%",
    border: true,
    title: " Welcome to TuiCraft "
  });
  
  renderer.root.add(box);
  renderer.requestRender();
}

// 3. Boot the servers! (SSH & Web)
engine.start();