How gcaguilar/bizidashboard works
1. Overall shape
BiziDashboard is a full-stack TanStack Start application that serves both public SEO pages and a data-rich dashboard, while also exposing a large API surface for mobile apps and operational jobs. The same repo contains the web app, backend route handlers, analytics SQL/logic, ingestion jobs, and database schema/migrations.
2. Primary runtime boundaries
There are three major execution modes:
- the main web/API server running on Bun, handling SSR pages and /api/* routes,
- background jobs/cron workers that collect GBFS snapshots and compute analytics,
- database maintenance/ops scripts used for schema repair, migrations, audits, and QA.
Docker Compose and separate job/server entrypoints keep those concerns isolated even though they share code.
3. Ingestion pipeline
The collection flow starts from scheduled cron jobs or manual triggers and ends in GET/POST /api/collect, which is protected by ops API keys. That endpoint pulls live GBFS data from city-specific discovery URLs, validates it, and writes snapshot data plus run metadata into PostgreSQL. Collection runs are tracked as first-class records, including request IDs, warnings, errors, and trigger source.
4. Storage model
Persistence is PostgreSQL via Prisma, but the key architectural choice is multi-tenant by schema: each city lives in its own schema with its own operational and analytics tables. This means city isolation happens at the database layer rather than in application logic. Redis is used separately for short-lived concerns such as rate limiting, job locks, cache, and token/session-related flows.
5. Analytics subsystem
The src/analytics area is a dedicated analytical engine on top of stored snapshots. It contains rollups, watermarks, retention rules, time buckets, and domain queries for rankings, heatmaps, hourly/daily trends, alerts, rebalancing, and pattern analysis. The API routes in src/app/api/* expose those derived datasets, while dashboard widgets consume them through server functions and client hooks.
6. Dashboard and public UI
The UI is split between public content pages and the authenticated/operational dashboard. Public pages cover city exploration, station pages, statistics, reports, and SEO landing pages; the dashboard provides richer operational and research views such as alerts, station detail, flow analysis, redistribution, and system health. TanStack Router routes are generated and grouped by feature area, with server functions supplying page-specific data.
7. Mobile and authenticated API surface
The repo also supports a mobile app integration path. Mobile endpoints require bearer auth plus installation identity, and some geo/auth routes support signed requests with timestamp/signature enforcement. Refresh tokens are hashed at rest and rotated on use, so the auth boundary is designed to detect token reuse and revoke compromised installations.
8. Public vs protected API boundaries
The API design is intentionally tiered:
- some endpoints are low-cost and anonymous, such as status, stations, rankings, alerts, patterns, heatmap, docs, and app versions,
- heavier public reads require a public API key,
- ops and mobile mutation/auth routes require stricter auth and rate limits.
This split matters architecturally because it separates public browsing traffic from sensitive operational and mobile flows.
9. External service dependencies
The application depends on several external systems that shape its behavior:
- GBFS feeds as the source of live bike-system data,
- Nominatim/OpenStreetMap for geocoding and reverse geocoding,
- Sentry for client/server error reporting,
- Umami for privacy-conscious analytics,
- MapLibre for map rendering in the public/dashboard UI.
These services are not decorative; they directly affect data acquisition, location search, observability, and dashboard features.
10. SEO and content generation
A large portion of the repo is dedicated to SEO-friendly pages and machine-readable outputs such as sitemap, robots, llm text files, manifests, and city/station/district landing pages. This suggests the site is both a data product and a discovery surface, with structured data, breadcrumbs, and page metadata treated as core architecture rather than afterthoughts.
11. Operational safety and resilience
There is a strong ops layer around security, auditability, and health checking. The app emits structured logs, attaches request IDs, validates startup configuration, applies CSP rules, rate limits sensitive endpoints, and exposes live/ready probes separately from richer status pages. Scripts and SQL helpers exist for schema fixes, migration from SQLite, database health checks, retention cleanup, and site-audit/vitals gates.
12. Code organization and data flow
The repo’s internal layering is consistent: route handlers and server functions sit at the edge, src/lib holds shared domain logic, src/services wraps external data sources and validation, src/analytics computes derived datasets, and src/jobs orchestrates periodic work. The main data flow is: external GBFS feed → collection API/job → PostgreSQL schema for the active city → analytics rollups/queries → public dashboard/API consumers, with Redis and observability systems supporting the edges.
Main entry points: index.ts API surface · index.tsx Dashboard UI · rollup-engine.ts Analytics engine · routeTree.gen.ts Route tree
Components 18
Runtimes
Primary execution modes for the app, jobs, and ops scripts.
- Web server · SSR pages and API routes for the main application.
src/server-entry.ts - Background jobs · Scheduled collection and analytics aggregation jobs.
src/jobs/standalone.ts - Ops scripts · Schema repair, audits, cleanup, and operational utilities.
ops/start-server.mjs
Platform
Shared data, security, analytics, and infrastructure layers.
- Analytics engine · Derived datasets, time buckets, retention, watermarks, and analytical queries.
src/analytics/rollup-engine.ts - Collection pipeline · Feed validation, snapshot capture, and collection run tracking.
src/lib/collection-pipeline.ts - Data storage · Persistence layer and city-scoped schema model.
src/services/data-storage.ts - Auth & access · API keys, bearer/mobile auth, signatures, rate limits, and route protection.
src/lib/security/route-protection.ts - Cache & Redis · Redis-backed locks, rate limiting, and short-lived cached data.
src/lib/cache/cache.ts - Geo services · Forward and reverse geocoding integrations used by search and map features.
src/lib/geo/nominatim.ts - Observability · Structured logging, request context, Sentry, health, and metrics.
src/lib/observability.ts - Shared domain · Common domain models, routes, formatting, and public-facing helpers.
src/lib/routes.ts
Surfaces
Public site, dashboard, and API entrypoints.
- Route tree · Generated route map and browser-side routing boundary.
src/routeTree.gen.ts - Public pages · SEO landing pages, city pages, stations, and reports.
src/app/index.tsx - Dashboard UI · Authenticated operational and research interface.
src/app/dashboard/index.tsx - API surface · Public, protected, ops, and mobile API endpoints.
src/app/api/status/index.ts - Server functions · Per-page data loading and feature-specific server logic.
src/server-functions/dashboard.ts - SEO assets · Sitemap, robots, manifests, and machine-readable text outputs.
src/app/sitemap[.]xml.ts - Mobile API · Installation-bound mobile endpoints and token rotation flows.
src/app/api/install/register/index.ts
Connections 22
- Web server → Route tree: serves · The Bun server hosts the generated TanStack route tree.
- Route tree → Public pages: maps · Routes resolve to public SEO pages and discovery surfaces.
- Route tree → Dashboard UI: maps · Routes resolve to authenticated dashboard views.
- Web server → API surface: hosts · The server exposes the HTTP API surface.
- Public pages → Server functions: loads data · Public pages use server functions for page-specific data.
- Dashboard UI → Server functions: loads data · Dashboard views rely on server functions and hooks.
- Server functions → Shared domain: uses · Server functions share domain helpers and navigation logic.
- API surface → Auth & access: protected by · API endpoints are tiered by public, ops, and mobile auth rules.
- API surface → Collection pipeline: triggers · Collection endpoint accepts ops-triggered ingestion requests.
- Background jobs → Collection pipeline: runs · Cron/worker jobs initiate feed collection.
- Collection pipeline → Data storage: writes · Validated snapshots and run metadata are persisted in PostgreSQL.
- Background jobs → Analytics engine: computes · Background aggregation builds rollups and derived datasets.
- Analytics engine → Data storage: reads · Analytical queries operate on stored snapshots and rollup tables.
- Analytics engine → API surface: serves · Analytics-backed endpoints expose rankings, heatmaps, alerts, and trends.
- Dashboard UI → Analytics engine: consumes · Widgets and panels read derived analytics datasets.
- Dashboard UI → Geo services: uses · Maps and station search depend on geocoding services.
- Public pages → SEO assets: emits · Public pages generate sitemap, robots, manifests, and text outputs.
- API surface → Mobile API: includes · The API surface includes mobile registration and token flows.
- Auth & access → Cache & Redis: uses · Rate limits, locks, and short-lived state rely on Redis.
- Observability → Web server: monitors · Runtime instrumentation and error reporting wrap the main server.
- Ops scripts → Data storage: maintains · Ops scripts repair schemas, migrations, and database health.
- Ops scripts → Observability: checks · Audit and vitals scripts validate runtime health and reporting.