How srexrg/websight works
Project Type and Purpose
• Full-stack analytics dashboard built with Next.js 15 and TypeScript.
• Uses Supabase for database and authentication, Tailwind CSS/ShadCn for styling, Recharts and React Simple Maps for visuals, jsPDF for report export.
File-Structure Insights
• “app/” – Next.js App Router: top-level pages (/, /dashboard, /docs, /auth, /settings, /website/[domain]).
• “app/api/” – Backend API routes:
– auth/callback/route.ts (OAuth callback)
– events/route.ts (fetch analytics data)
– track/route.ts (receive tracking beacons)
• “public/tracker.js” – Standalone JS snippet injected into user’s sites to emit events.
• “components/” – React UI broken into subfolders: analytics, dashboard, landing, settings, auth, ui primitives.
• “lib/” & “utils/” – Shared business logic: database types, analytics utilities, CORS middleware, Supabase client/server wrappers, PDF export code.
• “utils/supabase/” – Encapsulates Supabase client initialization, server-side helpers, middleware for auth.
• Configs: next.config.ts, tsconfig.json, postcss.config.mjs, tailwind via globals.css.
Core Components and Their Relationships
– Browser/UI Layer
• Landing pages: marketing, quickstart, pricing
• Dashboard pages: real-time charts, custom events overview, world map
• Settings pages: domain management, code snippets
• Auth UI: login-button, sign-out-button components
• UI primitives: buttons, modals, accordions, charts, tooltips
– Tracking Script (public/tracker.js)
• Injected on user sites; captures pageviews/custom events and POSTs to Next.js /api/track
– Next.js Server (app/api/*)
• /api/track: validates CORS, forwards event data to Supabase via server helper
• /api/events: queries Supabase for aggregated metrics, returns JSON for charts
• /api/auth/callback: handles OAuth redirect from Supabase Auth
– Supabase
• Auth: user registration, sign-in via OAuth or email
• Database: event records, custom events schema, user-domain mappings
– External Libraries
• Recharts & React Simple Maps: rendering charts and world maps on client
• jsPDF: PDF report generation on client or server
• Framer Motion: UI animations
Architectural Patterns and Design Principles
• Monolithic Next.js app combining frontend and backend.
• App Router for nested layouts and server components.
• Separation of concerns:
– UI components in “components/”
– Business logic in “lib/” and “utils/”
– Data layer isolated via “utils/supabase/”
• API-first design: all data flows through defined REST endpoints.
• Event-driven tracking: client scripts fire events, server persists and aggregates them.