- TypeScript 73.7%
- HTML 22.2%
- CSS 2.2%
- JavaScript 1.3%
- Shell 0.6%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Both are done: flights can be deleted from their detail page, and phones get the bottom tab bar. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
| .claude | ||
| .scratch | ||
| .vscode | ||
| docs | ||
| drizzle | ||
| factory | ||
| public | ||
| scripts | ||
| src | ||
| .cta.json | ||
| .cursorrules | ||
| .dockerignore | ||
| .gitignore | ||
| .prettierignore | ||
| CLAUDE.md | ||
| components.json | ||
| drizzle.config.ts | ||
| eslint.config.js | ||
| GLOSSARY.md | ||
| nixpacks.toml | ||
| package.json | ||
| pnpm-lock.yaml | ||
| pnpm-workspace.yaml | ||
| PRD.md | ||
| prettier.config.js | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.ts | ||
| vitest.config.ts | ||
Fliary
A private flight log for aviation enthusiasts. Record every flight you've taken, see them on a personal world map, and watch your stats grow.
The product spec lives in PRD.md. This file covers running and contributing.
Stack
- Framework: TanStack Start (React, file-based routing, server functions, SSR)
- Database: SQLite via
better-sqlite3— single-file, no daemon - ORM: Drizzle
- Auth: Better Auth (email + password)
- Map: MapLibre GL JS with Carto basemap
- Flight enrichment: AeroDataBox on RapidAPI
- UI: Shadcn UI + Tailwind v4
- Build / lint: Vite 8, Vitest, ESLint + Prettier
Prerequisites
- Node 20+ (developed on 25)
- pnpm 10+
Setup
git clone <this repo>
cd fliary
pnpm install
Environment variables
Copy .env.local.example to .env.local (or create one) and fill in:
# Database file (relative to repo root)
DATABASE_URL="dev.db"
# Better Auth
BETTER_AUTH_URL=http://localhost:3000
BETTER_AUTH_SECRET=<generate with: pnpm dlx @better-auth/cli secret>
# Optional: AeroDataBox flight enrichment (free RapidAPI tier = 100 req/month)
RAPIDAPI_KEY=
# Optional: comma-separated list of admin emails (gates the /admin page)
ADMIN_EMAILS=
# Optional: GlitchTip (Sentry-protocol) error reporting, browser + server.
# Read at runtime, so it can be changed in Dokploy without a rebuild.
GLITCHTIP_DSN=
# Optional: defaults to NODE_ENV; GLITCHTIP_RELEASE tags events with a version
GLITCHTIP_ENVIRONMENT=
GLITCHTIP_RELEASE=
# Optional, build time: upload browser source maps on every `pnpm build`.
# Token needs the project:releases scope. GLITCHTIP_URL
# defaults to the origin of GLITCHTIP_DSN. Without these the upload is skipped.
GLITCHTIP_AUTH_TOKEN=
GLITCHTIP_ORG=
GLITCHTIP_PROJECT=
GLITCHTIP_URL=
Database
Create the schema and seed the reference data:
pnpm db:migrate # apply Drizzle migrations
pnpm db:seed # download + import airports/airlines/aircraft (~5s, ~10MB)
The seed is idempotent: re-running skips populated tables but backfills new columns (e.g. airport timezones).
Run
pnpm dev
App runs at http://localhost:3000. Sign up at /signup and start logging flights.
Useful commands
| Command | What it does |
|---|---|
pnpm dev |
Vite dev server with HMR |
pnpm build |
Production build |
pnpm preview |
Serve the built bundle locally |
pnpm test |
Run Vitest |
pnpm lint |
ESLint |
pnpm format |
Prettier write + ESLint --fix |
pnpm db:generate |
Generate a Drizzle migration from schema changes |
pnpm db:migrate |
Apply pending migrations to the SQLite file |
pnpm db:seed |
Seed / backfill reference data (airports, airlines, aircraft, timezones) |
pnpm db:studio |
Open Drizzle Studio against the local DB |
Project layout
src/
├── routes/
│ ├── __root.tsx root layout (header, session in context)
│ ├── index.tsx landing page (redirects to /dashboard if signed in)
│ ├── signin.tsx, signup.tsx auth pages
│ ├── api/
│ │ ├── auth/$.ts Better Auth handler
│ │ └── export.ts JSON data export
│ └── _authed/ pathless layout that gates on session
│ ├── dashboard.tsx map + stats
│ ├── globe.tsx 3D spinning globe visualization
│ ├── flights/
│ │ ├── index.tsx list (delete-with-undo)
│ │ ├── new.tsx log a flight
│ │ └── $id/
│ │ ├── index.tsx detail
│ │ └── edit.tsx edit
│ ├── aircraft/
│ │ ├── index.tsx every aircraft (by tail number) you've flown
│ │ └── $tail.tsx per-aircraft detail page
│ ├── settings.tsx units / password / import / export / delete account
│ └── admin/
│ ├── index.tsx quota, data summary, ref health, activity
│ ├── airports.tsx airport CRUD
│ ├── airlines.tsx airline CRUD
│ └── aircraft-types.tsx aircraft type CRUD
│
├── components/
│ ├── flight-form.tsx shared by /new and /edit
│ ├── flight-map.tsx MapLibre 2D map (client-only)
│ ├── flight-globe.tsx MapLibre 3D globe (client-only)
│ ├── admin-nav.tsx admin sub-page navigation
│ └── ui/ Shadcn primitives (incl. reference-combobox.tsx)
│
├── server/
│ ├── auth-session.ts requireUserId / requireAdmin
│ ├── external/aerodatabox.ts typed fetch wrappers
│ ├── queries/
│ │ ├── reference.ts autocomplete searches
│ │ ├── flights.ts listFlights / getFlight
│ │ ├── fleet.ts fleet aggregates by tail number
│ │ ├── aircraft.ts aircraft detail + enrichment triggers
│ │ ├── enrichment.ts flight-number lookup + aircraft refinement
│ │ ├── _enrichment-internal.ts helpers (caches, db) — server-only
│ │ ├── dashboard.ts aggregates + map data
│ │ ├── admin.ts admin stats + clear cache
│ │ ├── admin-references.ts reference data queries for admin
│ │ └── session.ts current-session + isAdmin
│ └── mutations/
│ ├── flights.ts create / update / delete
│ ├── import-fr24.ts FR24 CSV import
│ └── admin-references.ts reference data CRUD mutations
│
├── db/
│ ├── schema.ts application tables + re-exports auth-schema
│ ├── auth-schema.ts generated by @better-auth/cli
│ └── index.ts Drizzle + WAL + foreign_keys pragma
│
└── lib/
├── auth.ts, auth-client.ts Better Auth (server + client)
├── distance.ts Haversine + km↔mi
├── flight-display.ts shared formatters (date, country, duration, cabin)
├── fr24-parser.ts FR24 CSV parsing logic
└── utils.ts cn() helper
scripts/seed/ one-shot reference data importers (airports, airlines, aircraft)
drizzle/ migrations (versioned)
Reference data sources
Seeded once at install via pnpm db:seed:
- Airports — OurAirports CSV, filtered to
scheduled_service = yes(~4,400 rows). Public domain. - Airlines — OpenFlights
airlines.dat(~6,200 rows). CC-BY-SA — attributed in the landing page footer. - Aircraft types — OpenFlights
planes.dat(~250 rows). Same license. - Airport timezones — computed from lat/lon at seed time via
tz-lookup. Used for converting local departure/arrival times to UTC for duration math.
Deployment notes
better-sqlite3 is a synchronous Node-only native module, so deploy targets must:
- Run a long-lived Node process (no edge runtimes / Cloudflare Workers / Vercel Functions)
- Provide a persistent disk volume for the SQLite file
Suitable: a single VPS, Fly.io machine with a volume, Railway, or any container host with mounted storage.
Backups
Do not back up the live DB with a plain cp — in WAL mode that can miss
un-checkpointed changes in the -wal file. Use the backup script, which runs
VACUUM INTO to write a consistent single-file snapshot:
pnpm db:backup # writes <dir-of-DATABASE_URL>/backups/fliary-<timestamp>.db
BACKUP_KEEP=30 pnpm db:backup # keep the newest 30 (default 14)
-
Automatic pre-migration backup:
scripts/migrate.mjs(run on every container boot via thestartscript) takes a*-premigrate.dbsnapshot before applying migrations, so a bad migration is recoverable. -
Scheduled backups: add a daily job in your host's scheduler (e.g. a Dokploy scheduled task / cron) running
node scripts/backup.mjswithDATABASE_URLset. Backups land on the same volume — this protects against bad migrations, accidental deletes, and corruption, but not loss of the volume itself. -
Off-volume copies (S3-compatible): set the
BACKUP_S3_*env vars below andpnpm db:backupalso uploads each snapshot to your bucket (Cloudflare R2, AWS S3, Backblaze B2, MinIO, …) — so a loss of the volume isn't fatal. Upload runs only in the scheduleddb:backupjob, not the pre-migration backup. The job exits non-zero if the upload fails, so monitoring can alert.BACKUP_S3_BUCKET=fliary-backups BACKUP_S3_ENDPOINT=https://<account>.r2.cloudflarestorage.com # omit for AWS S3 BACKUP_S3_REGION=auto # 'auto' for R2; a real region for AWS S3 BACKUP_S3_ACCESS_KEY_ID=... # omit to use the default IAM/credential chain BACKUP_S3_SECRET_ACCESS_KEY=... BACKUP_S3_PREFIX=fliary/ # optional key prefix BACKUP_S3_FORCE_PATH_STYLE=true # optional, needed for MinIOCloudflare R2 token: create an R2 API token with Object Read & Write scoped to the bucket. Jurisdiction matters: a bucket created in the EU jurisdiction must use the EU endpoint host
https://<account>.eu.r2.cloudflarestorage.com— using the default host gives a403 AccessDeniedeven with valid keys. (A403 AccessDeniedmeans the keys authenticated but the token/endpoint/bucket-scope is wrong;SignatureDoesNotMatchmeans the keys themselves are wrong.)S3 retention is not managed by the script — configure a bucket lifecycle rule to expire old objects (e.g. delete after 90 days). Local retention is still governed by
BACKUP_KEEP. -
Restore: stop the app, fetch a snapshot (
backups/fliary-*.dbon the volume, or download one from the bucket), replace the DB file atDATABASE_URLwith it (remove any stale-wal/-shmsidecars), restart.
Admin diagnostics and user activity
The API-call table on /admin includes the endpoint and expandable error
details: category, HTTP status when available, and a sanitized message. Error
messages are capped at 1,000 characters; credentials, URLs and stack traces
are excluded. Provider errors only contribute a supported JSON message field,
not a raw response body. These details follow the API log's 90-day retention.
Older failures say Details were not recorded.
/admin/users shows Last sign-in and Last active in UTC. Sign-in is
recorded for successful password login or verification auto-login. Activity
includes authenticated page navigation and server actions, with updates
throttled to once per five minutes per user. An idle tab does not send a
heartbeat, so this is not an online-presence indicator. Failed logins,
impersonation and background enrichment do not count as the user's activity.
Tracking starts when the feature is deployed. Not recorded means no timestamp has been observed, not that the user has never signed in. History survives logout and session revocation, and is removed when the account is deleted. Activity data is stored separately from Better Auth's user fields and can only be read through an admin-authorized query. The additive migration is applied by the normal startup migration command.
Scheduled aircraft enrichment
Flights are enriched while they are entered, but the actual registration may not be known until after departure. Run the recent-flight enrichment command once a day to revisit flights from the previous seven calendar days:
pnpm enrich:recent
The job finds missing registrations using an exact flight-number, date, and route match, then fetches registration details to fill in an empty aircraft type. A type that is already set (by the user or at log time) is never replaced. Seat, airline, route, times, and notes are never changed.
Quota protection (RapidAPI free tier = 100 calls/month, shared with interactive enrichment):
- Per flight, misses are retried with backoff — first run, then 2 days later,
then 4 days later — tracked in the
enrichment_attempttable. - At most
ENRICH_JOB_MAX_CALLS(default 10) paid calls per run. - The run stops once this month's paid calls (all sources, from
api_call_log) reachENRICH_JOB_MONTHLY_BUDGET(default 70), reserving the rest for interactive use. - It stops on a missing key, a 429, or 3 consecutive failures (exit code 1). Budget stops exit 0.
- A lock row in
job_lock(30-minute lease) prevents overlapping runs.
In production, add one Dokploy scheduled task around 12:15 UTC with the same
environment and /app/data volume as the web app. The command needs
DATABASE_URL and RAPIDAPI_KEY.
License
Choose your own.