No description
  • TypeScript 73.7%
  • HTML 22.2%
  • CSS 2.2%
  • JavaScript 1.3%
  • Shell 0.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ronny-André Bendiksen 7216630b03 docs: remove the finished flight-deletion and mobile-nav to-do notes
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]>
2026-11-19 20:36:47 +00:00
.claude feat: redesign the UI as an aeronautical chart 2026-11-19 07:57:05 +00:00
.scratch feat: redesign the UI as an aeronautical chart 2026-11-19 07:57:05 +00:00
.vscode Initial scaffold: TanStack Start + Drizzle (SQLite) + Better Auth + Shadcn 2026-04-28 10:14:12 +02:00
docs docs: remove the finished flight-deletion and mobile-nav to-do notes 2026-11-19 20:36:47 +00:00
drizzle feat: add flight.co2_kg column with one-time fill migration 2026-11-10 16:03:32 +00:00
factory factory: record merge sha for 004-security-headers-csp 2026-11-10 16:52:41 +00:00
public Switch mono font from JetBrains Mono to self-hosted Departure Mono 2026-05-27 13:20:36 +02:00
scripts feat: upload browser source maps to GlitchTip at build time 2026-11-17 11:59:23 +00:00
src Merge remote-tracking branch 'origin/main' into ui-redesign 2026-11-19 20:34:11 +00:00
.cta.json Initial scaffold: TanStack Start + Drizzle (SQLite) + Better Auth + Shadcn 2026-04-28 10:14:12 +02:00
.cursorrules Initial scaffold: TanStack Start + Drizzle (SQLite) + Better Auth + Shadcn 2026-04-28 10:14:12 +02:00
.dockerignore Production deploy prep (Nixpacks-friendly) 2026-04-28 15:28:25 +02:00
.gitignore Fix FR24 cabin-class import mapping (3 of 4 codes were wrong) 2026-06-04 09:48:27 +02:00
.prettierignore Initial scaffold: TanStack Start + Drizzle (SQLite) + Better Auth + Shadcn 2026-04-28 10:14:12 +02:00
CLAUDE.md Merge remote-tracking branch 'origin/main' into ui-redesign 2026-11-19 20:34:11 +00:00
components.json Initial scaffold: TanStack Start + Drizzle (SQLite) + Better Auth + Shadcn 2026-04-28 10:14:12 +02:00
drizzle.config.ts Green up codebase: fix typecheck, lint, and test infra 2026-05-29 11:11:01 +02:00
eslint.config.js Green up codebase: fix typecheck, lint, and test infra 2026-05-29 11:11:01 +02:00
GLOSSARY.md feat: add admin observability and harden flight tracking 2026-10-06 12:18:56 +02:00
nixpacks.toml Add nixpacks.toml — force Node SSR runtime, not static Vite 2026-04-28 19:24:14 +02:00
package.json Merge remote-tracking branch 'origin/main' into ui-redesign 2026-11-19 20:34:11 +00:00
pnpm-lock.yaml Merge remote-tracking branch 'origin/main' into ui-redesign 2026-11-19 20:34:11 +00:00
pnpm-workspace.yaml feat: upload browser source maps to GlitchTip at build time 2026-11-17 11:59:23 +00:00
PRD.md Departure/arrival times with timezone-aware duration 2026-04-28 12:17:38 +02:00
prettier.config.js Initial scaffold: TanStack Start + Drizzle (SQLite) + Better Auth + Shadcn 2026-04-28 10:14:12 +02:00
README.md Merge remote-tracking branch 'origin/main' into ui-redesign 2026-11-19 20:34:11 +00:00
tsconfig.json Initial scaffold: TanStack Start + Drizzle (SQLite) + Better Auth + Shadcn 2026-04-28 10:14:12 +02:00
vite.config.ts feat: upload browser source maps to GlitchTip at build time 2026-11-17 11:59:23 +00:00
vitest.config.ts Green up codebase: fix typecheck, lint, and test infra 2026-05-29 11:11:01 +02:00

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

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 the start script) takes a *-premigrate.db snapshot 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.mjs with DATABASE_URL set. 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 and pnpm db:backup also 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 scheduled db:backup job, 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 MinIO
    

    Cloudflare 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 a 403 AccessDenied even with valid keys. (A 403 AccessDenied means the keys authenticated but the token/endpoint/bucket-scope is wrong; SignatureDoesNotMatch means 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-*.db on the volume, or download one from the bucket), replace the DB file at DATABASE_URL with it (remove any stale -wal/-shm sidecars), 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_attempt table.
  • 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) reach ENRICH_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.