146 lines
6.6 KiB
Markdown
146 lines
6.6 KiB
Markdown
# My Garage
|
|
|
|
Track your cars: rego/WoF expiry, service history as a simple timeline
|
|
(with PNG/PDF attachments and notes), reminders for upcoming maintenance
|
|
(service, wheel rotation, alignment, or fully custom items like spark
|
|
plugs), and a per-car knowledgebase for procedures, common problems, and
|
|
reference info (coolant type, torque specs, etc). Log in via OIDC; each
|
|
user gets their own private garage.
|
|
|
|
(Internally the repo/Go module is still named `vlog` — that's just the
|
|
project's internal codename, not shown anywhere in the UI.)
|
|
|
|
## Stack
|
|
|
|
- **Backend**: Go (stdlib `net/http`, Go 1.22+ pattern routing), `sqlx` over
|
|
`database/sql` (no ORM), applied at startup with no separate migrate step.
|
|
- **Frontend**: Svelte 5 + Tailwind v4, built with Vite as a plain SPA (not
|
|
SvelteKit) and embedded into the Go binary — one process, one container.
|
|
- **Auth**: OIDC authorization-code flow against your existing OIDC
|
|
provider → the backend mints its own JWT, stored as an httpOnly session
|
|
cookie.
|
|
- **DB**: Postgres (production, bring your own) or SQLite (local dev/testing,
|
|
zero external dependency) — see `DB_DRIVER` below.
|
|
- **Files**: AWS S3 (production) or local disk (local dev/testing) — see
|
|
`STORAGE_DRIVER` below. Uploads/downloads are always proxied through the
|
|
Go backend, never presigned URLs.
|
|
- **Reminders**: computed at request time from a single SQL query — no
|
|
scheduler, no email.
|
|
- **TLS**: none of this app's business — put it behind whatever reverse
|
|
proxy you already run (e.g. an existing Caddy instance on the same server).
|
|
|
|
## Repo layout
|
|
|
|
```
|
|
backend/ Go API + embedded frontend + schema (postgres + sqlite)
|
|
frontend/ Svelte SPA (source only — build output isn't committed)
|
|
deploy/ docker-compose.yml, .env.example
|
|
scripts/ build-frontend.sh — builds the SPA and copies it into
|
|
backend/cmd/server/web for local (non-Docker) `go build`
|
|
```
|
|
|
|
## Configuration
|
|
|
|
All configuration is environment variables — see `deploy/.env.example` for
|
|
the full list and a description of each. The two driver toggles:
|
|
|
|
- **`DB_DRIVER`**: `postgres` (default) or `sqlite`. With `sqlite`,
|
|
`DATABASE_URL` is a file path (e.g. `./data/vlog.db`) instead of a DSN, and
|
|
the schema is applied idempotently on startup — no golang-migrate, no
|
|
external DB needed. Good for local dev/testing, and just as fine for a
|
|
real single-server/personal-use deployment (see `deploy/docker-compose.yml`)
|
|
— use Postgres only if you actually need a separate DB server.
|
|
- **`STORAGE_DRIVER`**: `s3` (default) or `local`. With `local`, uploads are
|
|
written under `LOCAL_STORAGE_PATH` (default `./data/uploads`) instead of
|
|
S3 — no AWS credentials needed. Same story: fine for production too as
|
|
long as the volume backing `LOCAL_STORAGE_PATH` is actually durable (i.e.
|
|
a real disk/volume, not ephemeral container storage) — use S3 if you want
|
|
uploads off-box.
|
|
|
|
Everything else (`OIDC_*`, `PUBLIC_BASE_URL`, `JWT_SIGNING_SECRET`) is
|
|
required regardless — there's no toggle for OIDC, you'll need a real (or
|
|
locally-run) OIDC provider either way. Register `OIDC_REDIRECT_URL`
|
|
(`https://<your-domain>/api/auth/callback`) with it before logging in.
|
|
|
|
## Running locally (no Postgres, no S3)
|
|
|
|
```sh
|
|
export DB_DRIVER=sqlite
|
|
export DATABASE_URL=./data/vlog.db
|
|
export STORAGE_DRIVER=local
|
|
export LOCAL_STORAGE_PATH=./data/uploads
|
|
# ...plus OIDC_*, PUBLIC_BASE_URL, JWT_SIGNING_SECRET (still required)
|
|
|
|
./scripts/build-frontend.sh # builds the SPA into backend/cmd/server/web
|
|
cd backend
|
|
go run ./cmd/server
|
|
```
|
|
|
|
For frontend-only iteration, `cd frontend && npm run dev` runs the Vite
|
|
dev server on its own port and proxies `/api/*` to `http://localhost:8080`
|
|
(see `frontend/vite.config.js`), so you can run the Go server and the Vite
|
|
dev server side by side.
|
|
|
|
## Deploying
|
|
|
|
`deploy/docker-compose.yml` is wired for `DB_DRIVER=sqlite` +
|
|
`STORAGE_DRIVER=local` out of the box — config as literal env values right
|
|
in the file (no separate `.env`), matching the convention used for other
|
|
services on the host: one folder per service, `./data` bind-mounted in,
|
|
published on a `127.0.0.1` port for the host's own Caddy to reverse-proxy
|
|
to. Fill in the `OIDC_*`/`PUBLIC_BASE_URL`/`JWT_SIGNING_SECRET` placeholders
|
|
(still required either way — there's no toggle for OIDC), then:
|
|
|
|
```sh
|
|
cd deploy
|
|
docker compose up -d --build
|
|
```
|
|
|
|
This starts one container: `vlog` (the Go binary, built via
|
|
`backend/Dockerfile`, which builds the frontend and embeds it in the same
|
|
multi-stage build), published on `127.0.0.1:4012` (pick any free port —
|
|
that's what your Caddy config points at). The OIDC provider and TLS
|
|
termination are assumed to already exist — nothing else runs in this
|
|
compose file.
|
|
|
|
Point your existing Caddy config at it:
|
|
|
|
```
|
|
garage.example.com {
|
|
reverse_proxy localhost:4012
|
|
}
|
|
```
|
|
|
|
To use Postgres + S3 instead, swap the relevant env values for the ones in
|
|
`deploy/.env.example` (a full reference list of every var the app reads).
|
|
|
|
The schema applies automatically on every startup — there's no separate
|
|
migrate step to remember, and for SQLite specifically, adding a new column
|
|
to an existing local DB file is also handled automatically (no need to
|
|
delete and recreate it as the schema evolves).
|
|
|
|
## Verification checklist
|
|
|
|
1. `docker compose -f deploy/docker-compose.yml up --build` with real env
|
|
vars pointed at your Postgres, OIDC provider, and S3 bucket (or
|
|
`DB_DRIVER=sqlite` / `STORAGE_DRIVER=local` for a no-external-deps
|
|
smoke test); confirm the schema applies cleanly on a fresh DB.
|
|
2. Walk the OIDC login → callback → cookie-set → `/api/me` round trip in a
|
|
browser; confirm logout clears the session.
|
|
3. Create a car (rego + info + photo); confirm the photo streams back.
|
|
4. Add a service entry with a PNG and a PDF attachment; confirm both show
|
|
up in the timeline and stream back correctly; confirm a renamed `.exe`
|
|
is rejected (content-sniffing, not just extension, decides the type).
|
|
5. Set a car's WoF/rego expiry in the near future and add a custom
|
|
reminder (e.g. "Spark plugs", due in 30 days); confirm both appear on
|
|
the dashboard and in the car's reminders panel.
|
|
6. Log in as a second OIDC user; confirm their garage is empty and they
|
|
get 404s for the first user's car/file IDs.
|
|
7. Edit an existing service entry and reminder (both open as modals);
|
|
confirm changes save and an attached file can be removed from a service
|
|
entry without deleting the whole entry.
|
|
8. Add a knowledgebase entry (e.g. "Coolant type"), edit it, delete it.
|
|
9. Add 21+ service entries (or knowledgebase entries) to one car and confirm
|
|
only the first page (20) loads initially, with a "Load more" button that
|
|
fetches the next page from the server — not one giant unbounded fetch.
|