Welcome to the backend of a cozy crafting-focused RPG! ✨
- Explore gathering locations to collect resources: 🌲 Forest, ⛏️ Mine, 🧱 Quarry
- Learn and use recipes to craft items 🛠️
- Manage your inventory 🎒
- Level up by gaining experience ⭐ and improve your skills: Mining, Woodcutting, Crafting
This API powers those mechanics with clean REST endpoints, TypeScript types, in-memory storage, and input validation.
- Node.js 18+
- npm 9+
npm install# Compile TypeScript
npm run build
# Development server (auto-reload)
npm run dev
# Run compiled server
npm start
# Tests (Jest + Supertest)
npm testThe server runs at http://localhost:3000 and all endpoints are prefixed with /api.
Base URL: http://localhost:3000/api
Player: id, name, level, experience, skills { mining, woodcutting, crafting }, inventory, createdAtInventoryItem: itemId, name, quantityRecipe: id, name, materials[], result, experienceGain- Gathering locations: forest, mine, quarry (see
src/utils/data.ts)
In-memory Map (non-persistent). Repository: src/repositories/playersRepository.ts.
- Input validation with Zod in controllers
- Simple error middleware in
src/middleware/errorHandler.ts
Base URL: http://localhost:3000/api
-
👤 Players
- POST
/api/players— Create a new player- Body:
{ "name": string } - 201: Player
- Body:
- GET
/api/players/:id— Get player- 200: Player | 404 if not found
- PUT
/api/players/:id— Update player stats- Optional body:
{ level?: number, experience?: number, skills?: { mining: number; woodcutting: number; crafting: number } } - 200: Player | 400 invalid data | 404 if not found
- Optional body:
- POST
-
🎒 Inventory
- GET
/api/players/:id/inventory— View inventory- 200:
InventoryItem[]
- 200:
- DELETE
/api/players/:id/inventory/:itemId?quantity=1— Discard items- Query:
quantity(optional, default 1) - 204 no content | 400 if not applicable | 404 if player not found
- Query:
- GET
-
⛏️ Gathering
- GET
/api/locations— List locations- 200:
[ { id: "forest"|"mine"|"quarry", location, skill } ]
- 200:
- POST
/api/players/:id/gather— Gather resources- Body:
{ "locationId": "forest" | "mine" | "quarry" } - 200:
{ ok: true, drops: {itemId,name,quantity}[], experienceGain, player } - 400: invalid location | player not found
- Body:
- GET
-
🛠️ Crafting
- GET
/api/recipes— List recipes- 200:
Recipe[]
- 200:
- GET
/api/players/:id/recipes— Learnable recipes (MVP: all)- 200:
Recipe[]
- 200:
- POST
/api/players/:id/craft— Craft- Body:
{ "recipeId": string } - 200:
{ ok: true, result, experienceGain, player } - 400: insufficient materials | invalid recipe | player not found
- Body:
- GET
- Wooden Sword:
5 × Oak Wood→Wooden Sword(+10 XP) - Iron Helmet:
3 × Iron Ore + 1 × Stone→Iron Helmet(+20 XP) - Magic Ring:
1 × Rare Gem + 2 × Copper Ore→Magic Ring(+50 XP)
# Create player
curl -s -X POST http://localhost:3000/api/players \
-H "Content-Type: application/json" \
-d '{"name":"Karina"}'
# Gather in Forest
curl -s -X POST http://localhost:3000/api/players/PLAYER_ID/gather \
-H "Content-Type: application/json" \
-d '{"locationId":"forest"}'
# List recipes
curl -s http://localhost:3000/api/recipes
# Craft wooden sword
curl -s -X POST http://localhost:3000/api/players/PLAYER_ID/craft \
-H "Content-Type: application/json" \
-d '{"recipeId":"wooden_sword"}'- Tests in
src/__tests__/app.test.ts - Run:
npm test
- Import
postman_collection.json - Useful variables:
playerId,itemId
- This project uses in-memory storage: restarting the server resets the state.
- XP/leveling is simple: level increases every
level * 100XP.