Server Development
How to set up and run the Mosaic Go server locally for development
Server Development
The Mosaic production server is built with Go using chi, pgx, and goose. This guide covers local development setup.
Looking for the Rust tree? It lives in
server/as a reference implementation and is not the deployed backend.
Prerequisites
- Go 1.26+
- PostgreSQL 15+ with pgvector extension
- FFmpeg (optional, for video processing)
Setup
1. Clone and enter the server directory
git clone https://github.com/crayonlu/Mosaic
cd Mosaic/server-go2. Configure environment
cp .env.example .env
# Edit .env with your database credentials3. Set up the database
Create a PostgreSQL database:
createdb mosaic
# or
psql -c "CREATE DATABASE mosaic;"Enable the pgvector extension:
psql -d mosaic -c "CREATE EXTENSION IF NOT EXISTS vector;"4. Run the server
go run ./cmd/mosaic-serverThe server will:
- Read configuration from
.env - Connect to PostgreSQL
- Apply pending migrations through goose
- Start listening on the configured port (default: 8080)
Project Structure
server-go/
βββ cmd/
β βββ mosaic-server/ # Entry point
β βββ baseline-sqlx/ # One-time migration bookkeeping
βββ internal/
β βββ config/ # Environment configuration
β βββ httpapi/ # Routing, handlers, middleware
β βββ service/ # Business logic
β βββ store/ # PostgreSQL access
β βββ domain/ # Types and shared contracts
β βββ adapters/ # AI and external integrations
β βββ auth/ # JWT and password hashing
β βββ media/ # Image and video processing
β βββ storage/ # File storage (local/S3)
βββ migrations/ # SQL migration files
βββ third-party/ # Bundled licenses
βββ Dockerfile
βββ .env.exampleKey Dependencies
| Package | Purpose |
|---|---|
| chi | HTTP router |
| pgx | PostgreSQL driver and connection pool |
| goose | Migration runner |
| golang-jwt | JWT authentication |
| golang.org/x/crypto | Password hashing |
| pgvector | Vector embeddings for semantic search |
Common Commands
go run ./cmd/mosaic-server # Start the server
go build ./... # Build all packages
go test ./... # Run tests
go vet ./... # Static checksDatabase Migrations
Migrations live in server-go/migrations/ (just migrations/ once you are in
that directory) and run automatically on startup via goose. Each migration is a
timestamped SQL file that must start with a -- +goose Up directive; a
-- +goose Down section is optional. The applied set is recorded in the
goose_db_version table. To add a new migration:
touch migrations/$(date -u +"%Y%m%d%H%M%S")_your_description.sqlWrite the -- +goose Up SQL in the file. On the next server restart, it is
applied automatically. The Go tree mirrors the Rust tree's migrations and adds
the goose directives; the SQL bodies are the same.