# Job tracker A private tracker for job applications, served at `/jobs/` on adam-french.co.uk. It has four main areas: - **Applications** (`/jobs/`): the list, the pipeline view and the Quick Reference snippets. - **Dashboard** (`/jobs/dashboard`): funnel counts, conversion rates and time-to-milestone metrics. - **Leads inbox** (`/jobs/leads`): postings the server finds on Greenhouse, Lever and Ashby boards and in Adzuna and Reed searches, scored by Claude against a search profile. - **Capture userscript** (`web/public/job-capture.user.js`): adds the posting open in the browser. Applications include explicit follow-up dates, contacts, activity history and structured posting metadata. The leads inbox supports filtering and bulk dismiss, restore and tracking actions. It was split out of the `web_server` repo, where it lived inside the site's Go backend, Python service and Vue app. It is now one Go binary that serves its own Vue SPA. It runs as one container behind the site's nginx and borrows the site's login. ## Layout ``` cmd/jobtracker/ main: reads the environment, wires everything, registers routes internal/auth/ is this request the admin? (asks the site backend) internal/claude/ the two Claude calls: read a posting, score a lead internal/graph/ gqlgen GraphQL: schema/*.graphql is the source of truth internal/handlers/ REST: capture routes, capture token, SPA file server internal/models/ GORM models (six tables) internal/services/ lead pipeline, job sources, upsert, status vocabulary web/ Vue 3 + Vite SPA, built for base /jobs/ ``` ## Routes Everything is served under `BASE_PATH` (`/jobs`). nginx proxies the prefix through unchanged. | Path | Auth | What | |---|---|---| | `/jobs/`, `/jobs/dashboard`, `/jobs/leads`, `/jobs/settings` | none (the data behind them is admin-only) | SPA | | `POST /jobs/api/graphql` | `@admin` on every field | everything the pages show and edit | | `/jobs/api/capture`, `/capture/status`, `/capture/extract` | bearer capture token | the userscript | | `/jobs/api/admin/capture-token` (GET/POST/DELETE) | admin | the token, from the Settings page | | `GET /jobs/api/health` | open | healthcheck: process up and database reachable | ## Auth There are no accounts here. `internal/auth` forwards the browser's `Cookie` header to the site backend's `GET /auth/validate-admin`, which is the same check nginx uses for `/radio/admin` and `/sb`, and treats a 2xx as "admin". - **Expired access token:** `validate-admin` falls back to the refresh token and answers with new cookies. Those `Set-Cookie` headers are relayed to the browser. - **Caching:** a "yes" is cached for 30 seconds per cookie, so logging out takes up to 30 seconds to reach the tracker. - **Lapsed session:** the SPA sends the browser to the site's `/admin/login?redirect=/jobs/...` (`web/src/session.js`). `AUTH_MODE=dev` admits everyone, for the standalone compose. It is refused unless `DEV_MODE=true`. ## Development ``` make check # go vet + go test, and a vite build make generate # after editing internal/graph/schema/*.graphql make dev # docker compose up --build: tracker + Postgres, seeded, no login ``` Then open http://localhost:8080/jobs/. Set `CLAUDE_API_KEY` in your shell or a `.env` to try the Claude features. For SPA hot reload, run `make dev` (or the Go binary) and then `cd web && npm run dev`. Vite proxies `/jobs/api` to `localhost:8080`; see `web/vite.config.js`. Every variable is listed and explained in `.env.example`. ## Running inside web_server The site's `docker-compose.yml` runs the published image as service `jobs`, with an explicit `environment:` list rather than `env_file`, so the site's other secrets stay out of the container. The site's nginx routes `/jobs/` to it. The site's Postgres container holds the data, in its own `jobs` database and role. `./jobs-data` is mounted at `/data`; the container runs as uid 1000, so `chown 1000 jobs-data` on the host. ### Deploying A push to `main` here runs `.gitea/workflows/ci.yaml`. It tests, builds and pushes `adam-french.co.uk/adamf/job-tracker:` and `:latest`, then rolls the site onto the new image and waits for the container's healthcheck. A tracker that does not come up healthy fails the run, with its last log lines in the output. The roll-out is the same command you would run by hand on the host: ``` cd ~/deploy/web_server && docker compose pull jobs && docker compose up -d --no-deps jobs ``` To pin a version, set `JOBS_IMAGE_TAG=` in the site's `.env`. While it is pinned, pushes here still publish but change nothing live. To roll back, pin the last good sha. ### One-off: registry setup The image lives in this Gitea's container registry. Two things make that less simple than it sounds: - Docker always talks to `/v2/` at the root of the host, whatever Gitea's `ROOT_URL` says (`/gitea/`). - Gitea advertises its token endpoint at `https://adam-french.co.uk/v2/token`, on the apex domain. The site redirects the apex to `www`. So the apex server block in web_server's `nginx/nginx.conf.template` proxies `/v2/` to Gitea and redirects everything else. That was added in web_server commit `da2ab9f`. 1. **Check Gitea's registry is on.** On stpvm, straight to the Gitea LXC (the name is pinned to its LAN IP in /etc/hosts): ``` curl -si http://git.adam-french.co.uk:3000/v2/ | head -5 ``` You want a `401` with `Www-Authenticate: Bearer realm="https://adam-french.co.uk/v2/token"`. A `404` means packages are off: add `[packages]` with `ENABLED = true` to Gitea's `app.ini.template` and recreate Gitea. 2. **Check nginx routes it.** `curl -si https://adam-french.co.uk/v2/` should give the same `401`, not a `301` to `www`. If you are setting up a fresh site, the route to copy is `location /v2/` in the apex `server` block of `nginx/nginx.conf.template`. 3. **Make a token.** In Gitea, go to Settings → Applications and create a token with **package: read and write**. 4. **Round trip a throwaway image** on the host: ``` docker login adam-french.co.uk -u adamf # the token is the password docker pull alpine:3.22 docker tag alpine:3.22 adam-french.co.uk/adamf/registry-test:1 docker push adam-french.co.uk/adamf/registry-test:1 docker rmi adam-french.co.uk/adamf/registry-test:1 docker pull adam-french.co.uk/adamf/registry-test:1 ``` Delete the test package afterwards, from your profile → Packages → registry-test → Settings. If the push fails, the error says where: - **`unauthorized`:** the token's scope is wrong, or `https://adam-french.co.uk/v2/token` isn't reaching Gitea (it should answer `401` or JSON, not a `301`). - **`413`:** the `client_max_body_size 0` line isn't in effect. - **HTML, a redirect, or "invalid character '<'":** `/v2/` is not reaching Gitea. 5. **Give CI the credentials.** In this repo's Settings → Actions → Secrets, add `REGISTRY_USER` (`adamf`) and `REGISTRY_TOKEN` (the token). The next push to `main` publishes the image. The host also has to be logged in to pull the image. The `docker login` in step 4 covers that; it is stored in that user's `~/.docker/config.json`. ### One-off cutover from the old in-backend tracker This was written while the tracker still had its email pipeline. Steps 4 and 5's Microsoft Graph parts (`msgraph_token.json`, the Entra redirect URI) no longer apply. Do the registry setup above first: step 6 needs the image. Run these on the host, in this order: 1. **Stop the old schedulers.** On the old backend, set `EMAIL_SYNC_ENABLED=false` and `JOB_LEADS_ENABLED=false`, so mail and boards are never processed twice. 2. **Create the database and role.** Use the values you put in the site's `.env` as `POSTGRES_JOBS_USER`, `POSTGRES_JOBS_PASSWORD` and `POSTGRES_JOBS_DB`: ``` docker exec db psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" \ -c "CREATE ROLE jobs LOGIN PASSWORD '…'" -c "CREATE DATABASE jobs OWNER jobs" ``` 3. **Copy the six tables**, with their schema and sequences. AutoMigrate then finds nothing to do: ``` docker exec db pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" --no-owner --no-privileges \ -t job_applications -t job_app_references -t processed_emails \ -t job_sources -t job_leads -t job_search_profiles \ | docker exec -i db psql -U jobs -d jobs -v ON_ERROR_STOP=1 ``` Then compare `SELECT count(*)` on each table in the two databases. 4. **Move the token files:** ``` mkdir -p jobs-data cp backend/token/msgraph_token.json backend/token/job_capture_token.json jobs-data/ sudo chown -R 1000:1000 jobs-data ``` 5. **Point Microsoft at the new callback.** In the Entra app registration, add the redirect URI `https://adam-french.co.uk/jobs/api/email/callback`, and set `MSGRAPH_REDIRECT_URI` to the same value. 6. **Deploy and check.** Deploy `web_server` with the `jobs` service and routes, then re-enable the two schedulers, now read by `jobs`. Check: - the tracker loads - "Check now" on Leads works - "Sync now" on Settings works - a capture from a real posting appears in the tracker The old tables stay in the site database until they are dropped by hand. GORM never drops anything, so this is safe until you are sure. ## The email pipeline (removed) The tracker used to read the mailbox (Microsoft Graph or IMAP), have Claude classify recruitment mail, and create or advance applications. It was taken out while it is not in use. The last commit that has it is tagged `email-pipeline-last`; reverting the commit that removed it brings it back. Its `processed_emails` table is still migrated and still holds its history, so a restored pipeline does not process old mail again. Once the removal is deployed, the `EMAIL_*`, `MSGRAPH_*` and `IMAP_*` variables can come out of the site's `jobs` service, and `msgraph_token.json` out of `jobs-data`. ## Things that are easy to get wrong - **The status vocabulary has copies.** `enum JobStatus` (GraphQL) and `services.statusOrder` are tied by a test. Two copies are not checked and must be edited by hand: `web/src/views/jobStatus.js` and `STATUS_LABELS` in the userscript. - **Bump the userscript's `@version` on every edit**, or installed copies never update. - **`BASE_PATH` and Vite's `base` must agree.** The SPA's asset URLs and router base are fixed at build time.