Skip to content

Latest commit

 

History

History
104 lines (76 loc) · 2.55 KB

File metadata and controls

104 lines (76 loc) · 2.55 KB

Backend Development

Prerequisites

  • Go 1.23+
  • Task
  • sqlc (installed via go tool)

Quick Start

# From repo root
task api:serve

The server will:

  1. Create the SQLite database if it doesn't exist
  2. Run all migrations (schema + seed data)
  3. Start listening on http://localhost:8080

Project Structure

services/api/
├── cmd/                    # CLI commands (serve, users, deals)
├── internal/
│   ├── api/                # HTTP handlers and middleware
│   ├── config/             # Configuration structs
│   ├── db/                 # Database (sqlc generated + migrations)
│   ├── notify/             # Push notification service
│   ├── rules/              # Deal trigger evaluation
│   └── sources/            # External data sources (MLB, etc.)
├── db/
│   ├── queries.sql         # sqlc query definitions
│   └── sqlc.yaml           # sqlc configuration
└── docs/                   # Documentation

Database

SQLite database with goose migrations.

Migrations

Located in internal/db/migrations/. Run automatically on server start.

# Wipe database and start fresh
task api:clean
task api:serve

Adding New Migrations

  1. Create a new file: internal/db/migrations/NNN_description.sql
  2. Use goose format:
-- +goose Up
CREATE TABLE ...;

-- +goose Down
DROP TABLE ...;

Updating Queries

  1. Edit db/queries.sql
  2. Regenerate: task api:sqlc

CLI Commands

./bin/freebie serve              # Start API server
./bin/freebie users list         # List all users
./bin/freebie deals list         # List active deals
./bin/freebie deals create       # Create test deal
./bin/freebie deals trigger ID   # Trigger specific event
./bin/freebie notify test        # Send test notification to all users
./bin/freebie notify send ID     # Send notification to specific user

Configuration

Configuration via flags, environment variables, or config file.

Flag Env Var Default
--db FREEBIE_DATABASE_PATH freebie.db
--host FREEBIE_SERVER_HOST 0.0.0.0
--port FREEBIE_SERVER_PORT 8080
--debug - false

Testing

task api:test

Deployment

Deployed to DigitalOcean Kubernetes (DOKS). See deployment guide for full instructions.