Software & Web ApplicationsSeptember 2025Status: Complete

Starship Command

Designing and Building a Database-Driven Adventure Game with PostgreSQL, Flask and Docker

At a glance

Problem
Game rules spread across clients drift apart and let players reach invalid states.
My role
Extended a team database design project into a playable, containerized web application.
Key decision
Make the database the source of truth: stored procedures and triggers hold the gameplay rules.
Result
A playable game started with one command: a browser terminal over a thin Flask API, with every rule in PostgreSQL.
Proof
7 tables12 database functions3 triggers
Built with
Database
  • PostgreSQL 17
  • PL/pgSQL
Original version
  • SQL Server
  • T-SQL
API
  • Python
  • Flask
  • psycopg
Client
  • HTML
  • CSS
  • JavaScript
Delivery
  • Docker Compose
Design tools
  • Draw.io
  • Azure Data Studio

In Practice

1 of 4

Context

I wanted to explore how relational databases could support interactive applications beyond traditional business systems. Our team translated gameplay mechanics into a normalized data model, implemented database-driven game logic and extended the original SQL Server design into a playable, containerized application backed by PostgreSQL.

How can a relational database serve as the foundation for an interactive application while maintaining data integrity, reusable gameplay logic and a consistent experience across different clients?

An interactive game requires persistent state, relationships between entities and rules governing how players interact with the game world. The project explored how these requirements could be modeled and enforced within a relational database, then exposed through an application interface without duplicating gameplay logic in the application layer.

Approach

Designed and implemented a normalized relational database representing the game world, player progression, inventory and gameplay events. Stored procedures and database triggers centralize gameplay operations, validation and audit logging. The original SQL Server implementation was subsequently extended with a PostgreSQL 17 backend, a thin Flask API and a browser-based terminal interface. Docker Compose packages the database and application into a reproducible local deployment.

Data sources

  • Custom Relational Database

    A purpose-built game world containing locations, movement connections, players, items, inventories and gameplay events. Seed scripts initialize the game environment, while database functions manage player state, mission progression and gameplay operations.

Solution

Data model

  1. Data models. Designed conceptual and logical data models to translate gameplay requirements into a normalized relational schema.

  2. Integrity constraints. Implemented relational structures with primary keys, foreign keys, unique constraints and check constraints to maintain data integrity.

Rules in the database

  1. Stored procedures. Developed database functions and stored procedures for player creation, movement, exploration, inventory management and mission completion.

  2. Triggers. Implemented database triggers for movement logging, inventory auditing and gameplay validation.

  3. Shared world, separate inventories. Improved multiplayer progression by keeping item placement in shared world data while maintaining independent player inventories and mission state.

Port and app

  1. PostgreSQL port. Ported the game engine from SQL Server and T-SQL to PostgreSQL 17 and PL/pgSQL while retaining the original SQL Server scripts.

  2. Flask API. Built a Flask API that delegates gameplay operations to PostgreSQL and returns standardized JSON responses.

  3. Browser terminal. Developed a browser-based terminal interface for exploring the game world, collecting items and completing the mission.

Delivery

  1. One-command setup. Packaged the PostgreSQL database and web application with Docker Compose for reproducible setup and execution.

Architecture

Starship Command uses a database-centric architecture in which PostgreSQL manages the game world, player progression, inventory and gameplay rules. A normalized relational schema connects players, locations, items, inventories and action history through defined relationships, keys and constraints.

Database functions implement gameplay operations, while triggers automate validation and audit logging. A thin Flask API exposes these operations over HTTP and returns JSON responses without duplicating game rules in application code. A browser-based terminal interface provides an interactive client, and Docker Compose packages the application and database for local execution.

The original SQL Server implementation remains available alongside the PostgreSQL version, demonstrating how the same project can evolve across database platforms while retaining its core relational design.

Architecture: a browser terminal calls a Flask API with 9 endpoints, which calls one PostgreSQL function per action; 12 functions and 3 triggers act on 7 tables, all running under Docker Compose.
Hover to magnify · click to open full sizeTap to open full size

Components

  • Conceptual and logical data models
  • Normalized relational schema
  • Primary keys, foreign keys and integrity constraints
  • PostgreSQL functions and PL/pgSQL gameplay logic
  • Original SQL Server and T-SQL implementation
  • Database triggers for validation and audit logging
  • Flask API with standardized JSON responses
  • Browser-based terminal interface
  • Docker Compose deployment
  • Database initialization and seed scripts

Outcome

A team database design project became a playable game that starts with one command. The PostgreSQL version runs on 7 tables, 12 database functions and 3 triggers; the Flask API passes each player command to a single function and returns its JSON, and the browser terminal is the client. The original SQL Server scripts remain alongside the port.

Scope and limits

Runs locally, with no authentication or protected player sessions. One handcrafted map and mission. The original SQL Server version is kept for reference, not maintained in parallel.

Lessons Learned

  • Translating conceptual requirements into normalized relational structures creates a strong foundation for application behavior.

  • Stored procedures, functions and triggers can centralize application rules while requiring careful coordination to avoid duplicated logic.

  • Database portability involves more than translating SQL syntax; behavior, constraints, triggers and client interfaces must also be adapted.

  • Putting rules and the audit trail in the database means no client can skip them, the same principle behind governed AI agents.

What's next

  • Add user authentication and protected player sessions.
  • Introduce lighting mechanics that use location darkness and item usability to influence exploration.
  • Generate randomized maps and item placements.
  • Add scoring, achievements and additional progression mechanics.
  • Build analytics dashboards from player action logs.
  • Explore deployment against a managed cloud database platform.