No description
  • Go 99.4%
  • Nix 0.6%
Find a file
2026-02-10 12:45:16 +01:00
api errors 2026-02-10 09:36:40 +01:00
cache errors 2026-02-10 09:36:40 +01:00
db errors 2026-02-10 09:36:40 +01:00
handlers start user of the week 2026-02-10 12:45:16 +01:00
migrations start user of the week 2026-02-10 12:45:16 +01:00
queries start user of the week 2026-02-10 12:45:16 +01:00
schemas remove enums 2026-02-03 18:18:43 +01:00
services start user of the week 2026-02-10 12:45:16 +01:00
sql start user of the week 2026-02-10 12:45:16 +01:00
tmp errors 2026-02-10 09:36:40 +01:00
utils start user of the week 2026-02-10 12:45:16 +01:00
.air.toml air 2025-06-20 18:12:28 +02:00
.example.env add port 2026-02-03 17:56:28 +01:00
.gitignore gitignore 2025-08-28 22:42:13 +02:00
docker-compose.yaml create collections 2025-11-04 16:52:37 +01:00
flake.lock air 2025-06-20 18:12:28 +02:00
flake.nix migrations 2025-12-27 23:25:37 +01:00
go.mod mod 2025-11-04 19:10:05 +01:00
go.sum create collections 2025-11-04 16:52:37 +01:00
LICENSE Initial commit 2025-06-16 20:55:45 +02:00
main.go start user of the week 2026-02-10 12:45:16 +01:00
README.md update readme 2026-02-03 17:56:24 +01:00
sqlc.yaml migrations 2025-12-27 23:25:37 +01:00

wysi-server

This is the database and REST API meant to serve the wysi-client

It is mostly just a proxy for the osu! API, although it also stores additional data for use on wysi.

Prerequisites

If you have Nix installed, you can use the dev shell with:

nix develop

Getting Started

  1. Copy the environment file:
cp .example.env .env
  1. Edit the .env file with your preferred editor and set the required values:

    • OSU_ID and OSU_SECRET from your osu! OAuth application
    • JWT_SECRET - generate a secure random string
    • Database credentials
  2. Install dependencies:

go mod download
  1. Generate SQL code:
sqlc generate
  1. Start the database and cache:
docker compose up -d
  1. Run database migrations:
goose up
  1. Start the server:
# Development with hot reload
air

# Or run directly
go run .

The server will start on port 1323.

Development

Project Structure

.
├── api/          # External API clients (osu! API)
├── cache/        # Redis cache initialization
├── db/           # Database connection
├── handlers/     # HTTP request handlers
├── migrations/   # Database migrations (goose)
├── queries/      # SQL queries for sqlc
├── schemas/      # Data structures and types
├── services/     # Business logic
├── sql/          # Generated SQL code (sqlc)
└── utils/        # Helper functions

Database Migrations

Migrations are managed with goose. The environment variables are already configured in .env.

# Create a new migration
goose create migration_name sql

# Apply migrations
goose up

# Rollback last migration
goose down

# Check migration status
goose status

Regenerating SQL Code

After modifying files in queries/, regenerate the Go code:

sqlc generate

API Endpoints

Public Endpoints

  • GET / - Health check
  • GET /search?query={term} - Search users/beatmaps
  • POST /login - Authenticate with osu! OAuth code
  • GET /users/:userId - Get user profile
  • GET /users/:userId/scores/:scoreCategory - Get user scores
  • GET /users/:userId/beatmaps/:beatmapsetCategory - Get user beatmaps
  • GET /users/:userId/most - Get most played beatmaps
  • GET /users/:userId/setup - Get user setup
  • GET /users/:userId/collections - Get user collections
  • GET /beatmap/:mapId/scores - Get beatmap scores
  • GET /rankings/:mode/:category/:page - Get rankings
  • GET /scores/:scoreId - Get score details
  • GET /medals - Get medals list

Protected Endpoints (requires JWT)

  • PUT /users/:userId/setup - Update user setup
  • PUT /users/:userId/collections - Create collection
  • DELETE /users/:userId/collections/:collectionId - Delete collection

Environment Variables

Variable Description Required
WEB_ORIGIN Allowed CORS origin Yes
APP_ENV Environment (dev/prod) Yes
JWT_SECRET Secret for signing JWTs Yes
OSU_ID osu! OAuth client ID Yes
OSU_SECRET osu! OAuth client secret Yes
OSU_REDIRECT osu! OAuth redirect URL Yes
DB_USER Database username Yes
DB_PASS Database password Yes
DB_NAME Database name Yes
DB_HOST Database host Yes

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test your changes locally
  5. Submit a pull request

License

See LICENSE file for details.