🪐 CraftFlow Workbench NovaCraft Balance Engine

← Back to Workbench
🪐

CraftFlow Workbench

NovaCraft Balance Engine — Developer Reference

A full-stack game data management and balance tooling suite for NovaCraft — a sci-fi survival crafting game where players scavenge resources, build infrastructure, and craft components to repair a crashed spaceship. This workbench is the single source of truth for all item data, recipes, and progression balance before it reaches Unity.

📌 What is CraftFlow Workbench?

CraftFlow is a Node.js / Express web app that acts as a live design and balancing dashboard sitting on top of the novacraft_db MariaDB database. Instead of editing raw SQL or spreadsheets, designers and engineers use this UI to create and tune every game entity — items, crafting recipes, crafting stations, smelter recipes, and fuel types — and then export the resulting dataset directly to Unity as a structured JSON file.

🗄️
Live Database Editing

All CRUD operations write directly to novacraft_db via a MariaDB connection pool.

⚖️
Automated Balance Checks

Static analysis flags broken recipes, pacing regressions, inverted cost hierarchies, and missing unlock triggers.

🤖
AI-Powered Suggestions

GitHub Models (GPT-4o) reads your registry and proposes new items. Approve them with one click to inject them into the live DB.

🏗️ Architecture Overview

Layer Technology Location Role
ServerNode.js + Expressserver.jsHTTP server, mounts all API routers, serves static frontend
DatabaseMariaDB + mariadb npmconfig/database.jsConnection pool; call pool.getConnection() in every route
API RoutesExpress Routerroutes/One file per domain — items, recipes, stations, smelter, analysis, suggestions, export, migration
ServicesPlain JS modulesservices/Pure logic decoupled from Express — e.g., smelterAnalysisService.js
FrontendVanilla JS + Tailwind v2public/Single-page tab layout. Modules loaded via <script> tags in dependency order
AI Layer@azure-rest/ai-inferenceroutes/suggestions.jsCalls GitHub Models endpoint with designer constraints; returns structured JSON

🚀 Getting Started (New Developer Setup)

1
Clone the repository
git clone https://<your-gitea-host>/jicwah60826/NovacraftDB.git
cd NovacraftDB
2
Install dependencies
npm install

Key packages: express, mariadb, body-parser, @azure-rest/ai-inference, @azure/core-auth.

3
Configure environment variables

The app expects the following variables at runtime — set them in your Docker / Unraid container environment or a .env file (add dotenv if needed):

VariableRequiredDescription
DB_HOSTYesMariaDB host (e.g. 192.168.1.x or mariadb)
DB_USERYesMariaDB username
DB_PASSWORDYesMariaDB password
DB_NAMEYesShould be novacraft_db
GITHUB_TOKENAI onlyGitHub Personal Access Token — required only for the AI Design Assistant
4
Run the DB migration

On first run, click ⚙️ Run DB Migration in the top-right header. This is safe to re-run at any time — it only adds missing tables and columns, it never destroys data.

5
Start the server
node server.js
# → CraftFlow Balancing engine running on port 3000

Then open http://localhost:3000 in your browser. For development, consider using nodemon server.js for auto-restart on file changes.

🗄️ Database Schema Reference

All tables live in novacraft_db. The migration endpoint (POST /api/db/migrate) keeps the schema up to date automatically.

items
item_id (PK) · display_name · tier · is_craftable · calculated_value · base_tta · requires_unlock · unlocked_by_default · unlock_trigger · unlock_trigger_ref · crafting_time

The core entity. Every craftable item, raw resource, consumable, and equipment piece lives here. calculated_value is derived from the item's recipe tree labor cost and is used by the Balance Advisor.

recipes
recipe_id (PK) · output_item_id (FK → items) · smelt_duration_seconds

One row per craftable item's recipe. Linked to its ingredients via recipe_ingredients.

recipe_ingredients
recipe_id (FK → recipes) · ingredient_item_id (FK → items) · quantity

Many-to-many junction table. Each row is one ingredient line in a recipe.

fuel_types & smelter_recipes
Manage smelting economy separately from crafting. fuel_types defines burn duration; smelter_recipes maps input → output items with a smelt duration.

🗂️ Tab-by-Tab Guide

📦 Items

The primary data entry tab. Use the form on the left to add new items or edit existing ones. The table on the right lists every item in the database.

  • Item ID must be SCREAMING_SNAKE_CASE (auto-formatted) and globally unique — this is the primary key used in Unity.
  • Enabling isCraftable reveals the Crafting Recipe section — fill it in immediately to avoid a Balance Advisor error.
  • Base TTA (time-to-acquire in seconds) is used for raw resources only. It is the foundational unit that the labor cost of all downstream recipes is built from.
  • Click ✏️ Edit on any row to load it back into the form. The banner at the top confirms you are in edit mode.
⚗️ Recipes

Register and manage crafting recipes independently of items. Each recipe has a unique Recipe ID, an output item, and one or more ingredient rows.

  • Use the + Add Ingredient button to build multi-ingredient recipes.
  • A recipe's output item must already exist in the Items tab first.
  • If an item is marked is_craftable = 1 but has no recipe, the Balance Advisor will flag it as an Error.
🏭 Stations

Crafting stations are the in-world structures the player builds to unlock recipe categories (e.g., a Fabricator, a Med Bay, an Engineering Bench). Register stations here and assign them to recipe categories.

🔥 Smelter

Manages the smelting sub-system separately from the crafting system. Two forms are available:

  • Fuel Types — define each fuel item and how long it burns (in seconds).
  • Smelter Recipes — map an input item + quantity to an output item + quantity with a smelt duration.
  • The Smelter Balance Analysis card at the bottom calculates cycles-per-fuel-unit and cross-tier efficiency to catch smelting economy exploits.
🎯 Balance Advisor Includes AI Assistant

The most important tab for maintaining a healthy game economy. Contains two panels:

⚖️ Balance Advisor (static analysis)

Click ▶ Run Analysis to scan the full database. Flags are colour-coded:

  • ● Error — data integrity problem that will cause broken behaviour in Unity (e.g., craftable item with no recipe, inverted cost hierarchy).
  • ◆ Warning — likely pacing problem that won't crash the game but will hurt the player experience.
  • ℹ Info — improvement suggestion (e.g., high-value item with zero crafting time).

Each flag has an ✏️ Edit Item shortcut that loads the offending item directly into the Items form.

🤖 AI Design Assistant

Uses GitHub Models (GPT-4o) to generate new item suggestions contextualised to your existing registry. Configure all 8 constraint controls before generating:

  • Target Tier — constrain suggestions to a specific progression tier.
  • Acquisition — force found/scavenged or crafted only.
  • Item Purpose — equipment, player upgrade, structural, consumable, or resource.
  • Thematic Focus — life support, hull repair, avionics, propulsion, or power systems.
  • Rarity Feel — influences base TTA and crafting time values the AI outputs.
  • Craft Complexity — guides ingredient count in the AI's narrative description.
  • Requires Unlock — force lock/unlock behaviour.
  • # of Suggestions — request 1 to 5 suggestions per call.

Review each card and click ✅ Approve & Inject to write the item directly to novacraft_db. Then return to the Items tab to assign a recipe if needed.

⚠️ Requires a valid GITHUB_TOKEN environment variable.

📊 Data View

A read-only master spreadsheet of every item in the database. Use the search box to filter by name or ID. Useful for a quick audit before running a balance pass or exporting to Unity.

🔧 Header Action Buttons

⚙️ Run DB Migration

Sends a POST /api/db/migrate request that applies any pending schema changes (new columns, new tables). Always run this after pulling changes from the repository that include schema updates. It is fully idempotent — safe to run multiple times.

⬇️ Export Unity JSON

Downloads the entire item registry as novacraft_items_export.json via GET /api/export/unity. Drop this file into the Unity project's StreamingAssets/ folder to update the game's data at runtime.

📡 API Endpoint Reference

Method Endpoint Description
GET/api/dataFetches full workspace state (all items, recipes, stations, etc.) in one call
GET/api/itemsList all items
POST/api/itemsCreate a new item
PUT/api/items/:idUpdate an existing item
DELETE/api/items/:idDelete item and any recipes that output it
GET/api/recipesList all recipes with their ingredients
POST/api/recipesCreate a new recipe
DELETE/api/recipes/:idDelete a recipe
GET/api/stationsList all crafting stations
GET/api/fuel-typesList all fuel types
GET/api/smelter-recipesList all smelter recipes
GET/api/balance/analysisRun full balance static analysis — returns flags array + summary
GET/api/smelter/analysisRun smelter economy analysis
GET/api/suggestAI item suggestions — accepts query params: tier, acquisition, purpose, theme, rarity, complexity, requiresUnlock, count
GET/api/export/unityDownload full item registry as Unity-ready JSON file
POST/api/db/migrateRun idempotent DB schema migration

🛠️ Developer Conventions

Adding a new API route
  1. Create routes/myFeature.js using express.Router().
  2. Always obtain a connection via pool.getConnection() inside a try/catch and release it with conn.end() in the finally block.
  3. Mount it in server.js with app.use('/api', require('./routes/myFeature')).
  4. If the logic is non-trivial, extract it into a services/myFeatureService.js pure function and import it into the route.
Adding a new frontend module
  1. Create your JS file under public/js/ in the appropriate subdirectory (renders/, editors/, forms/, analysis/).
  2. Add a <script src="..."> tag at the bottom of public/index.html. Load order matters — the comment block documents the required order: state → utils → renders → editors → forms → analysis → api → app.
  3. All functions are global — use descriptive names to avoid collisions (e.g., runSmelterAnalysis not just run).
Item ID naming convention

All item IDs must be SCREAMING_SNAKE_CASE — e.g., HULL_PATCH_KIT, ENGINE_MANIFOLD_MK2. The form field auto-uppercases input. This ID is the stable reference used in Unity ScriptableObjects and must never change once an item is in production.

The Unity export contract

The JSON structure exported by GET /api/export/unity is consumed directly by ItemData.cs in Unity. If you add a new column to the items table, you must also update the export route and the Unity ScriptableObject to match.

CraftFlow Workbench · NovaCraft Balance Engine · Running on port 3000