Rankster backend is a Go API built with Gin, GORM, and PostgreSQL. It powers:
- social rank posts
- survey posts in the feed
- category discovery
- subscriber-only user stats
The API currently runs on port 8000 by default.
- Go
- Gin
- GORM
- PostgreSQL
Make sure these are installed before running the project:
- Go
1.21+ - PostgreSQL
14+
You can verify with:
go version
psql --version- Clone the repository and enter it:
git clone <your-repo-url>
cd rankster-backend- Create the PostgreSQL database:
createdb ranksterIf createdb is not available, use:
psql -d postgres -c 'CREATE DATABASE rankster;'- Export the database connection string:
export DATABASE_URL='postgresql://<your-postgres-user>@localhost:5432/rankster?sslmode=disable'Example:
export DATABASE_URL='postgresql://tntons@localhost:5432/rankster?sslmode=disable'- If your Go install tries to auto-download a newer toolchain, force the local one:
export GOTOOLCHAIN=local- Download dependencies:
go mod download- Start the backend:
go run ./cmd/apiThe API will start on:
http://localhost:8000
The backend currently bootstraps itself automatically:
- GORM auto-migrates the required tables
- seed data is inserted if the database is empty
That means a fresh local database is enough to get started.
DATABASE_URL: PostgreSQL connection stringHOST: API bind host, default0.0.0.0PORT: API port, default8000PUBLIC_BASE_URL: public API origin used for locally stored asset URLs, defaulthttp://localhost:8000ENABLE_MOCK_AUTH: set totrueonly for local/dev mock-login testing, defaultfalseUPLOAD_DIR: local upload directory used when cloud storage is not configured, defaultuploadsCLOUDINARY_URL: optional Cloudinary API URL for durable image uploads, for examplecloudinary://API_KEY:API_SECRET@CLOUD_NAMECLOUDINARY_FOLDER: optional Cloudinary folder prefix, defaultrankster/uploadsGOTOOLCHAIN: recommendedlocalif your machine has an older but compatible local Go toolchain
Health check:
curl http://localhost:8000/healthzMain feed:
curl 'http://localhost:8000/feed/main'Search categories:
curl 'http://localhost:8000/search/categories?q=coffee'The local seed creates sample users, categories, assets, rank posts, and one survey post.
Sample seeded user:
alice- user id:
c17147fe-5ca5-4d36-9c8a-b8215660f12f
Use this header for authenticated local testing:
-H 'Authorization: Bearer c17147fe-5ca5-4d36-9c8a-b8215660f12f'Subscriber-only stats endpoint:
curl -H 'Authorization: Bearer c17147fe-5ca5-4d36-9c8a-b8215660f12f' \
http://localhost:8000/user/statsCreate a rank post:
curl -X POST http://localhost:8000/rank/create \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer c17147fe-5ca5-4d36-9c8a-b8215660f12f' \
-d '{
"categoryId": "1a669446-b6ce-4d60-8787-ace8343d1940",
"templateId": "a46cc484-84fe-4c3c-91e5-d42195391be0",
"tierKey": "B",
"imageAssetId": "17ded82a-e65e-419e-9f14-6800a932b6fd",
"caption": "Cold Brew belongs in B tier",
"subjectTitle": "Cold Brew"
}'Recommended local database:
- PostgreSQL
Why PostgreSQL:
- strong relational support for social graph + rankings
- good JSON support for survey targeting and flexible metadata
- reliable indexing and query performance for feed/search workloads
cmd/api: application entrypointinternal/config: environment configinternal/db: database connection, migration, and seedinginternal/models: GORM modelsinternal/handlers: HTTP handlersinternal/server: router setupdocs/architecture.md: architecture notesdocs/erd.mmd: Mermaid ERDopenapi.yaml: API contract
If Go fails with a toolchain download error:
export GOTOOLCHAIN=localIf PostgreSQL is not running:
brew services start postgresql@14If the port is already in use:
lsof -nP -iTCP:8000 -sTCP:LISTENThen either stop that process or override the port:
PORT=8001 go run ./cmd/apidocs/architecture.mddocs/erd.mmdopenapi.yaml