How devitaliya22/statushive works
Project type and purpose
• This is a full-stack Next.js application that provides uptime/latency monitoring, health checks, and status pages for arbitrary domains.
• It exposes a web UI (React + Next.js App Router) for dashboard, configuration, and status pages.
• It offers a set of REST/edge API routes (Next.js server/edge functions) for pings, metrics ingestion, notifications, and status checks.
• It persists data in a relational database via Prisma and uses Redis for caching/rate-limiting. It also feeds real-time analytics into Tinybird pipelines. Authentication is handled with NextAuth.
File structure
• src/app – the Next.js “app” folder holds UI routes (landing, auth, dashboard, monitors, notifications, statuspage).
• src/app/api – Next.js API endpoints, subdivided into:
– auth (NextAuth)
– edge (geolocation-based monitoring at airport codes)
– health, monitors, notifications (add/send/test), statuspage, subdomain
• prisma – schema + migrations for the main database (e.g., PostgreSQL) including a PingLocation table
• src/lib – shared libraries for authOptions, db (Prisma + Redis), domain logic, env, utilities
• src/tinybird – Tinybird datasource definitions, pipes, and a seed script for analytics ingestion
• components & hooks – client UI components and React hooks for state, debounce, location, toast
• Configuration files – Next.js config (next.config.ts), Tailwind, PostCSS, ESLint, tsconfig, package.json
Main components & boundaries
a. Frontend (Browser)
– Next.js App Router pages & React components (src/app, src/components)
– Tailwind CSS + global styles
b. Backend (Server / Edge)
– Next.js API Routes (Node.js Lambdas / Edge Functions) under src/app/api
– NextAuth (+ session store in Redis or DB)
c. Database & Cache
– Prisma ORM → PostgreSQL (or other SQL)
– Redis for caching, session store, rate limiting
d. Analytics / BI
– Tinybird: HTTP ingestion from server routes → datasources → pipes → public endpoints for dashboards
e. External Services
– Notification providers: Discord, Slack, Email (via SMTP or 3rd-party)
– Domain registry API (subdomain availability checks)
– Hosting/CDN: Vercel (edge functions for geo routes)
Relationships & data flows
1. User interacts with the Next.js UI → SSR/React hydration → client side fetches data via built-in fetch hooks or custom query providers.
2. UI → Next.js server/api routes for CRUD operations on monitors, notifications, status pages.
3. API routes → Prisma → SQL DB for persisting pings, monitor configs, users, notifications.
4. API routes → Redis for caching hot data (recent pings, rate limits, sessions).
5. Ping ingest endpoints (edge functions) execute in geo-distributed edge at airport codes → write ping records → optionally push aggregated events to Tinybird.
6. Tinybird pipelines process raw ping data → expose real-time analytics endpoints → consumed by UI or external dashboards.
7. Notification flows: when a monitor fails → backend calls /notifications/send/* routes → picks provider (Discord/Slack/Email) → calls external API/SNMP.
Architectural patterns & principles
• Monorepo with colocated frontend & backend (Next.js App Router)
• API-first design: every feature has a matching API route under src/app/api
• Edge functions for low-latency geo monitoring
• Shared domain library (src/lib/domain) for business logic, DRY across routes
• Data pipelines (Tinybird) for real-time analytics, separate from the primary DB
• Modular UI components & providers for theming, state, queries
• Secure auth via NextAuth and environment variables
Detailed elements
• For each API group (auth, monitors, edge, notifications) show one representative endpoint.
• Shared lib/domain and lib/env as an inset library used by all backend components.