This is the backend for Caso Abierto, a police‑investigation game built in Unity. It generates AI‑powered cases, stores them in PostgreSQL, generates representative images, and exposes a REST API for the game client. Full project (Unity + this server): CasoAbierto
- Generate new cases via OpenRouter
- Persist cases (players, evidence, timeline, characters) in PostgreSQL
- Generate case images via Together AI and store the binary in the database
- Serve images on demand as
image/png - Expose API endpoints for Unity (or any HTTP client) to create and fetch data
- Node.js + Express for the HTTP server
- postgres (npm package) for PostgreSQL queries
- OpenRouter for AI text generation
- Together AI for image generation
- Clone this repo
git clone https://github.com/samuelrubiodev/active-case-server.git cd active‑case‑server - Install dependencies
npm install
- Copy environment file
cp .env.example .env.local
- Edit
.env.localwith your keys and database URLDATABASE_URL=postgres://user:pass@host:port/db DATABASE_URL= # For example: postgresql://postgres:password@localhost:5432/mydb OPENROUTER_API= # For get API key, visit https://openrouter.ai/settings/keys OPENROUTER_URL=https://openrouter.ai/api/v1 OPENROUTER_MODEL=google/gemini-2.0-flash-001 TOGETHER_API= # For get API key, visit https://together.xyz IMAGE_MODEL_FREE=black-forest-labs/FLUX.1-schnell-Free
- In supabase go into your project and execute these lines of code from the database file
- Start the server
npm run devStart
The API will listen on port 3001 by default (configurable in src/server/server.js).
| Method | Path | Description |
|---|---|---|
| POST | /case/new |
Generate a new AI case, persist it (without image and case data) and return {caseID} |
| POST | /case/:ID |
Fetch all data for case ID (player, evidence, timeline, characters, etc.) |
| GET | /case/:ID/image |
The image of case in binary (image/png) |
| Method | Path | Description |
|---|---|---|
| GET | /players/:playerID/case |
Get all cases for player playerID |
| GET | /players/new |
Create a new player (returns new ID) |
Feel free to open issues or pull requests — any improvements to schema validation, error‑handling, or performance optimizations are welcome!