Skip to content

Quickstart

This guide walks you through building a fully functional API from scratch using ShipQ. By the end, you’ll have authentication, CRUD endpoints for a pets resource, generated tests, an OpenAPI spec, and a running server.

Make sure you have:

  • Go 1.21+ installed
  • ShipQ CLI built (see Installation)
  • A database engine available (Postgres, MySQL, or none — ShipQ will fall back to SQLite)
Terminal window
mkdir myapp && cd myapp
shipq init

shipq init creates:

  • go.mod (if one doesn’t exist)
  • shipq.ini — the project configuration file
  • Updates .gitignore to exclude .shipq/ working directories
Terminal window
shipq db setup

This command:

  • Uses DATABASE_URL from your environment if set
  • Otherwise auto-detects: MySQL if mysqld is on PATH, Postgres if postgres is on PATH, otherwise SQLite
  • Creates both dev and test databases
  • Writes the resolved database_url into shipq.ini
Terminal window
shipq auth
shipq signup

shipq auth generates:

  • Database migrations for organizations, accounts, and sessions tables
  • Login/logout/me handlers in api/auth/
  • Cookie-based session management (signed cookies via COOKIE_SECRET)
  • Auth middleware
  • Generated tests in api/auth/spec/

shipq signup adds a registration endpoint on top of the auth system.

Run a quick sanity check:

Terminal window
go mod tidy
go test ./api/auth/spec/... -v -count=1

Create a migration for a pets table:

Terminal window
shipq migrate new pets name:string species:string age:int

This generates a Go migration file in migrations/ using ShipQ’s typed DDL builder. The column grammar supports types like string, text, int, decimal, datetime, bool, and foreign keys via references.

Apply the migration:

Terminal window
shipq migrate up

This runs the schema compiler:

  1. Discovers all migration files in migrations/
  2. Executes them to build a canonical MigrationPlan
  3. Writes shipq/db/migrate/schema.json
  4. Generates typed schema bindings in shipq/db/schema/schema.go
  5. Applies the schema to both dev and test databases
Terminal window
shipq resource pets all

This generates a complete set of CRUD handlers for the pets table:

OperationMethodRouteHandler
CreatePOST/petsapi/pets/create.go
Get OneGET/pets/:idapi/pets/get_one.go
ListGET/petsapi/pets/list.go
UpdatePATCH/pets/:idapi/pets/update.go
DeleteDELETE/pets/:idapi/pets/soft_delete.go

It also generates:

  • api/pets/register.go — handler registration
  • Query definitions in querydefs/
  • Test files in api/pets/spec/

Since we ran shipq auth first, all routes are auth-protected by default. To make public routes instead, use the --public flag:

Terminal window
shipq resource pets all --public

Tidy up dependencies:

Terminal window
go mod tidy
Terminal window
shipq handler compile

This is the final compilation step. It:

  • Discovers all registered handlers across your api/ packages
  • Generates cmd/server/main.go (the runnable server)
  • Generates an OpenAPI 3.1 JSON spec (served at GET /openapi in dev/test)
  • Generates a docs UI (served at GET /docs in dev/test)
  • Generates an admin UI
  • Generates an HTTP test client and test harness
  • Generates TypeScript HTTP client code (and optional framework helpers)
Terminal window
go test ./... -v

ShipQ generates comprehensive tests including:

  • Auth endpoint tests (login, logout, session management)
  • CRUD endpoint tests (create, read, update, delete)
  • 401 tests for auth-protected routes (when auth is enabled)
  • Tenancy isolation tests (when scoping is configured)
  • RBAC tests (when roles are configured)
Terminal window
go run ./cmd/server
# or
shipq start server

Your API is now running. If you’re in dev/test mode, visit:

  • GET /docs — Interactive API documentation
  • GET /openapi — Raw OpenAPI 3.1 JSON spec

In just a few commands, you now have:

  • ✅ Cookie-based authentication (login, logout, signup, session management)
  • ✅ Full CRUD for pets with typed query runners
  • ✅ Auto-generated tests that actually pass
  • ✅ OpenAPI spec + docs UI + admin UI
  • ✅ TypeScript HTTP client ready for your frontend
  • ✅ A self-contained Go project with no external ShipQ dependency

As you develop your app, the workflow is:

Terminal window
# Schema changed? Re-run migrations
shipq migrate up
# Query definitions changed? Recompile queries
shipq db compile
# Handlers or routes changed? Recompile the handler registry
shipq handler compile