No description
Find a file
Jon Seager 2309a696cc
feat(infrastructure): implement Gear repository and HTTP client
Add SQL repository and HTTP client implementations for Gear entity.

SQL Repository (infrastructure/repositories/gear.rs):
- SqlGearRepository with CRUD operations
- order_clause() for sorting: Make/Model (case-insensitive), Category, CreatedAt
- build_where_clause() for category filtering
- to_domain() converts GearRecord to domain Gear with category parsing
- Uses push_update_field! macro for partial updates
- Proper error handling with RepositoryError types

HTTP Client (infrastructure/client/gear.rs):
- GearClient for CLI access to API endpoints
- Methods: create(), list(), get(), update(), delete()
- Supports optional category filter in list()
- Error context with anyhow for user-friendly messages

Module Registration:
- Register gear module in infrastructure/repositories/mod.rs
- Register gear module and gear() method in infrastructure/client/mod.rs

Follows the exact patterns from BagRepository and BagsClient.
2026-02-02 15:19:19 +00:00
.github chore: update copliot instructions 2025-11-25 21:42:20 +00:00
migrations feat(domain): add Gear entity with database migrations 2026-02-02 15:14:23 +00:00
scripts feat!: use numeric, database-generated IDs throughout 2025-11-25 18:21:04 +00:00
src feat(infrastructure): implement Gear repository and HTTP client 2026-02-02 15:19:19 +00:00
templates fix: remove superfluous /bags/:id/finish endpoint 2025-11-27 14:24:26 +00:00
tests test(server): add integration tests for datastar endpoints 2026-02-02 14:02:55 +00:00
.gitignore chore: add result* to the .gitignore 2025-11-24 16:52:19 +00:00
Cargo.lock feat: improved trace logging 2025-11-26 12:01:53 +00:00
Cargo.toml feat: improved trace logging 2025-11-26 12:01:53 +00:00
CLAUDE.md docs: document datastar patterns for Claude 2026-02-02 13:50:39 +00:00
flake.lock feat: bootstrap brewlog platform 2025-11-24 11:44:12 +00:00
flake.nix feat!: use numeric, database-generated IDs throughout 2025-11-25 18:21:04 +00:00
README.md feat: add username/password flags to create-token command 2025-11-26 16:32:40 +00:00

B{rew}log

B{rew}log is a self-hosted coffee logging platform for tracking your roasters, roasts, brews, cafes and brewing gear.

The application is distributed as a single Rust binary that powers both an HTTP server and a command-line client for the API. There is a web frontend built with Tailwind CSS that enables client-side reactivity with Datastar.

Note

This project was built with significant assistance from Github Copilot. I used it as a test-bed for trying out newer agentic coding workflows, and to get some basic experience with Datastar, which had attracted my attention.

Basic usage

B{rew}log ships as one executable. You decide whether it acts as a server or a client.

First-time setup

On first start, you must set an admin username and password via the BREWLOG_ADMIN_USERNAME and BREWLOG_ADMIN_PASSWORD environment variables:

BREWLOG_ADMIN_USERNAME="admin" BREWLOG_ADMIN_PASSWORD="your-secure-password" brewlog serve

This creates the admin user in the database. On subsequent starts, the environment variables are not required.

Authentication

Brewlog supports two authentication methods:

  1. Web Frontend: Session-based authentication via login page
  2. CLI/API: Token-based authentication via Bearer tokens

Web Authentication

  1. Start the server and browse to the frontend
  2. Click "Login" in the navigation bar
  3. Sign in with username admin and your password
  4. You're now authenticated and can create/update/delete records

CLI/API Authentication

First, create an API token:

brewlog create-token --name "my-cli-token"
# You will be prompted for username and password.
# Alternatively, you can provide them via flags:
# brewlog create-token --name "my-cli-token" --username admin --password secret

# Username: admin
# Password: ********
#
# Token created successfully!
# Token ID: nye9BDqnLL
# Token Name: my-cli-token
#
# ⚠  Save this token securely - it will not be shown again:
#
# dEadB3efDeadb33fdeadb33F...
#
# Export it in your environment:
#   export BREWLOG_TOKEN=dEadB3efDeadb33fdeadb33F...

Export the token and use it for all CLI commands:

export BREWLOG_TOKEN="dEadB3efDeadb33fdeadb33F..."
export BREWLOG_URL=http://localhost:3000

# Now all write operations work
brewlog add-roaster \
  --name "Radical Roasters" \
  --country "UK" \
  --city "Bristol" \
  --homepage "https://radicalroasters.co.uk"

brewlog add-roast \
  --roaster-id "deadbeef" \
  --name "Chelbesa Lot 2" \
  --origin "Ethiopia" \
  --region "Gedeo" \
  --producer "Chelbesa Cooperative" \
  --process "Washed" \
  --tasting-notes "Blueberry, Jasmine"

Token Management

# List your active tokens
brewlog list-tokens

# Revoke a token
brewlog revoke-token --id abc123

API Usage

For direct API access, include your token as a Bearer token:

curl http://localhost:3000/api/v1/roasters \
  -H "Authorization: Bearer dEadB3efDeadb33fdeadb33F..." \
  --json '{"name":"Radical Roasters","country":"UK"}'

Note: All read operations (GET requests) are public and don't require authentication. Only write operations (POST/PUT/DELETE) require authentication.

Installation

At present, the only way to use brewlog is to build it from source:

git clone https://github.com/jnsgruk/brewlog.git
cd brewlog
cargo build --release

The resulting binary lives at target/release/brewlog.

During development you can run directly:

cargo run -- serve

Testing

The project includes a number of unit and integration tests, all of which can be executed with cargo:

cargo test