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.
Prerequisites
Section titled “Prerequisites”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)
1. Create a new project
Section titled “1. Create a new project”mkdir myapp && cd myappshipq initshipq init creates:
go.mod(if one doesn’t exist)shipq.ini— the project configuration file- Updates
.gitignoreto exclude.shipq/working directories
2. Set up your database
Section titled “2. Set up your database”shipq db setupThis command:
- Uses
DATABASE_URLfrom your environment if set - Otherwise auto-detects: MySQL if
mysqldis on PATH, Postgres ifpostgresis on PATH, otherwise SQLite - Creates both dev and test databases
- Writes the resolved
database_urlintoshipq.ini
3. Add authentication
Section titled “3. Add authentication”shipq authshipq signupshipq auth generates:
- Database migrations for
organizations,accounts, andsessionstables - 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:
go mod tidygo test ./api/auth/spec/... -v -count=14. Define your schema
Section titled “4. Define your schema”Create a migration for a pets table:
shipq migrate new pets name:string species:string age:intThis 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:
shipq migrate upThis runs the schema compiler:
- Discovers all migration files in
migrations/ - Executes them to build a canonical
MigrationPlan - Writes
shipq/db/migrate/schema.json - Generates typed schema bindings in
shipq/db/schema/schema.go - Applies the schema to both dev and test databases
5. Generate CRUD endpoints
Section titled “5. Generate CRUD endpoints”shipq resource pets allThis generates a complete set of CRUD handlers for the pets table:
| Operation | Method | Route | Handler |
|---|---|---|---|
| Create | POST | /pets | api/pets/create.go |
| Get One | GET | /pets/:id | api/pets/get_one.go |
| List | GET | /pets | api/pets/list.go |
| Update | PATCH | /pets/:id | api/pets/update.go |
| Delete | DELETE | /pets/:id | api/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:
shipq resource pets all --publicTidy up dependencies:
go mod tidy6. Compile the handler registry
Section titled “6. Compile the handler registry”shipq handler compileThis 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 /openapiin dev/test) - Generates a docs UI (served at
GET /docsin dev/test) - Generates an admin UI
- Generates an HTTP test client and test harness
- Generates TypeScript HTTP client code (and optional framework helpers)
7. Run tests
Section titled “7. Run tests”go test ./... -vShipQ 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)
8. Start the server
Section titled “8. Start the server”go run ./cmd/server# orshipq start serverYour API is now running. If you’re in dev/test mode, visit:
GET /docs— Interactive API documentationGET /openapi— Raw OpenAPI 3.1 JSON spec
What you’ve built
Section titled “What you’ve built”In just a few commands, you now have:
- ✅ Cookie-based authentication (login, logout, signup, session management)
- ✅ Full CRUD for
petswith 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
Iteration workflow
Section titled “Iteration workflow”As you develop your app, the workflow is:
# Schema changed? Re-run migrationsshipq migrate up
# Query definitions changed? Recompile queriesshipq db compile
# Handlers or routes changed? Recompile the handler registryshipq handler compileNext steps
Section titled “Next steps”- Core Concepts: The Compiler Chain — Understand how ShipQ’s three compilers feed each other
- Guide: Queries (PortSQL) — Write custom queries beyond generated CRUD
- Guide: Multi-Tenancy — Add organization-scoped data isolation
- Guide: Workers & Channels — Add background jobs and real-time WebSocket channels
- E2E Example — A longer walkthrough building a complete application