InfiniteCraft with Creative Activity Tracing!
A web game where you combine elements to create new things, powered by a local LLM. Built on @bufferhead's OpenCraft.
- Frontend: Vue 3 + TypeScript + Vite (web UI)
- Backend: Python Flask + Cerebras API (LLM integration)
- Database: SQLite (caches combinations)
- Model: Llama 3.3 70B (via Cerebras Cloud)
- Python 3.8+ installed
- Node.js 18+ installed
- Cerebras API Key
Step 1 - Set up API Key:
Create a .env file in the server/ directory, and paste in the contents that shm will send to u (including the cerebras.ai API key)
Terminal 1 - Start Backend:
cd server
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
python app.pyBackend runs on http://localhost:3000
Terminal 2 - Start Frontend:
cd frontend
npm install # First time only
npm run devFrontend runs on http://localhost:5173
In dev, Vite proxies /api/* and POST / to the backend on port 3000 (see frontend/vite.config.ts). The frontend calls the backend with relative paths by default; set VITE_FLASK_API_URL at build time (e.g. https://cats.shmuh.co) only when the built frontend is hosted somewhere other than the backend, as on Vercel.
You now have both processes running. Open http://localhost:5173 in your browser.
Key files:
server/app.py- Flask routes & API endpointsserver/llm_service.py- Cerebras API integration, new word generation logicserver/models.py- Data models (Material, Recipe)server/global.db- SQLite database that stores materials and combinations
To add a feature:
- Make sure
CEREBRAS_API_KEYis set in your.envfile - Add LLM logic to
llm_service.pyif needed - Add Flask route to
app.py - Test with
curlor Postman:curl -X POST http://localhost:3000 \ -H "Content-Type: application/json" \ -d '{"first": "Water", "second": "Fire"}'
To modify database:
- Schema is initialized in
init_db()function inapp.py - Add new tables or columns there
- Database persists in
global.db
Stores every unique element and its MiniLM embedding
name TEXT PRIMARY KEY (e.g., "Steam")
emoji TEXT (e.g., "🌫️")
firstDiscoveredAt TIMESTAMP (when first created)
discoverer TEXT (username who discovered it)
embedding BLOB (384-dim vector from MiniLM model)
Logs EVERY combination event that occurs
id INTEGER PRIMARY KEY (auto-incrementing)
firstWord TEXT (e.g., "Water")
secondWord TEXT (e.g., "Fire")
resultName TEXT (e.g., "Steam", foreign key to materials)
resultEmoji TEXT (e.g., "🌫️")
username TEXT (who made the combination)
timestamp TIMESTAMP (when it happened)
perUserRank INTEGER (max rank of parents + 1)
isDiscovery BOOLEAN (true if first time this result was found)
-
Frontend detects drop event in ItemCard.vue
- Always POST to
/with{first, second, username} username= extracted from?user=URL param if present, elsenull
- Always POST to
-
Backend processes request immediately:
- Check if combination already cached in
combinationstable - If cached, return cached result immediately
- If not cached, call LLM to generate new combination
- Return
{result, emoji, isDiscovery}to frontend (takes ~1-2 seconds)
- Check if combination already cached in
-
Conditional logging (based on whether username exists):
- If username provided: Spawn background thread to:
- Generate embedding for new material using MiniLM (384 dimensions)
- Add material to
materialstable with embedding (if new discovery) - Calculate
perUserRankbased on parent materials - Log combination event in
combinationstable withisDiscoveryflag
- If username is null: Skip all database operations, just return LLM result
- If username provided: Spawn background thread to:
-
Frontend updates UI:
- Add new item to boxes (visual drag-drop item)
- If
isDiscovery=true, add item to resources list with orange ring border - If
isDiscovery=falseor null, add item without special styling
Key files:
frontend/src/App.vue- Main layout & headerfrontend/src/views/HomeView.vue- Game page entry pointfrontend/src/components/Example.vue- Main game component (drag-drop, combinations)frontend/src/stores/useResourcesStore.ts- Pinia store for discovered elementsfrontend/src/stores/useBoxesStore.ts- Pinia store for drag-drop state
(Pinia handles sharing the live game state across components)
To add a feature:
- Create new
.vuecomponent infrontend/src/components/ - Import it in
HomeView.vueor other parent component - Use Pinia stores for shared state (don't prop drill)
API calls:
const response = await fetch('http://localhost:3000/', {
method: 'POST',
body: JSON.stringify({ first: 'Water', second: 'Fire' })
})
const { result, emoji } = await response.json()Get all discovered materials.
{
"materials": [
{ "name": "Fire", "emoji": "🔥" },
{ "name": "Water", "emoji": "💧" },
{ "name": "Steam", "emoji": "🌫️" }
]
}Combine two words.
Request:
POST /
{
"first": "Water",
"second": "Fire",
"username": "player1" // optional: null if not logged in
}
Response (immediate):
{
"result": "Steam",
"emoji": "🌫️",
"isDiscovery": true // only set if username provided
}
Behavior:
- Always returns result immediately (LLM takes ~1-2 seconds)
- If
usernameprovided: logs to database + calculatesisDiscovery - If
usernamenull: skips database logging,isDiscovery= false
Get all materials and their combination relationships.
{
"nodes": [
{ "id": "Fire", "label": "Fire", "emoji": "🔥" },
{ "id": "Steam", "label": "Steam", "emoji": "🌫️" }
],
"links": [
{ "from1": "Water", "from2": "Fire", "to": "Steam" }
]
}Calculate cosine similarity between two materials' embeddings.
Request:
POST /api/distance
{
"material1": "Fire",
"material2": "Water"
}
Response:
{
"material1": "Fire",
"material2": "Water",
"similarity": 0.42
}
Similarity: 0-1 scale where 1 = identical materials, 0 = completely different
Health check.
{ "status": "ok" }infiniteCATs/
├── frontend/ # Vue 3 web app
│ ├── src/
│ │ ├── main.ts # Entry point
│ │ ├── App.vue # Root component
│ │ ├── views/ # Page-level components
│ │ ├── components/ # Reusable UI components
│ │ └── stores/ # Pinia state management
│ ├── vite.config.ts # Vite configuration
│ └── package.json
│
├── server/ # Python Flask backend
│ ├── app.py # Flask app & routes
│ ├── llm_service.py # Ollama integration
│ ├── models.py # Data models
│ ├── cache.db # SQLite database
│ ├── requirements.txt # Python dependencies
│ └── .env.example # Environment template
│
└── README.md