No description
- Go 99.4%
- Nix 0.6%
| api | ||
| cache | ||
| db | ||
| handlers | ||
| migrations | ||
| queries | ||
| schemas | ||
| services | ||
| sql | ||
| tmp | ||
| utils | ||
| .air.toml | ||
| .example.env | ||
| .gitignore | ||
| docker-compose.yaml | ||
| flake.lock | ||
| flake.nix | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| main.go | ||
| README.md | ||
| sqlc.yaml | ||
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
- Go 1.24.3+
- sqlc
- Docker
- Docker Compose
If you have Nix installed, you can use the dev shell with:
nix develop
Getting Started
- Copy the environment file:
cp .example.env .env
-
Edit the
.envfile with your preferred editor and set the required values:OSU_IDandOSU_SECRETfrom your osu! OAuth applicationJWT_SECRET- generate a secure random string- Database credentials
-
Install dependencies:
go mod download
- Generate SQL code:
sqlc generate
- Start the database and cache:
docker compose up -d
- Run database migrations:
goose up
- 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 checkGET /search?query={term}- Search users/beatmapsPOST /login- Authenticate with osu! OAuth codeGET /users/:userId- Get user profileGET /users/:userId/scores/:scoreCategory- Get user scoresGET /users/:userId/beatmaps/:beatmapsetCategory- Get user beatmapsGET /users/:userId/most- Get most played beatmapsGET /users/:userId/setup- Get user setupGET /users/:userId/collections- Get user collectionsGET /beatmap/:mapId/scores- Get beatmap scoresGET /rankings/:mode/:category/:page- Get rankingsGET /scores/:scoreId- Get score detailsGET /medals- Get medals list
Protected Endpoints (requires JWT)
PUT /users/:userId/setup- Update user setupPUT /users/:userId/collections- Create collectionDELETE /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
- Fork the repository
- Create a feature branch
- Make your changes
- Test your changes locally
- Submit a pull request
License
See LICENSE file for details.