How pixelhalide/manipalguesser works
Project Type and Purpose
• This is a full-stack, geo-guessing web application (“ManipalGuessr”) built with Next.js (React + TypeScript) for the frontend, an Express.js backend, MongoDB for persistence, and NextAuth for authentication.
• The user sees photos of Manipal campus locations, submits guesses via a Leaflet map, earns points based on accuracy, and competes on a leaderboard.
File Structure
• Top-level directories:
• Components/ – Reusable React UI pieces (Navbar, GuessScreen, Map, etc.)
• app/ – Next.js 13+ (App Router) directory: pages, layouts, API routes under app/api.
• lib/actions/ – Client-side helpers (e.g., auth.ts).
• public/locationPictures – Static AVIF images used in the game.
• config.json, resetWeekly.ts – Game configuration and weekly reset script.
• API endpoints: app/api/auth/[...nextauth]/route.ts (NextAuth), app/api/signup/page.tsx (signup).
• auth.ts and index.ts at the root: likely the Express server entry points or custom server integration with Next.js.
• Deployment/config files: next.config.ts, tsconfig.json, postcss.config.mjs, ESLint config.
README for Additional Insights
• Confirms architecture: Next.js + React frontend, Express backend, NextAuth v5, MongoDB, Tailwind, Leaflet, EXIFR for metadata.
• Hosted on Vercel, weekly leaderboard resets via a script.
Diagramming the Architecture
a. Main Components
• Client (Browser / Mobile)
– React UI (Next.js pages and components)
– Leaflet map widget for guesses
• Web Server
– Next.js application (SSR/SSG, static assets)
– Express.js backend (custom API), NextAuth handlers
• Database
– MongoDB (users, scores, weekly leaderboards)
• External Services
– Vercel (hosting/CDN)
– Map tile provider (OpenStreetMap or similar for Leaflet)
• Batch/Utility
– resetWeekly.ts (cron or scheduled function resetting weekly scores)
b. Relationships & Interactions
1. Client requests page → Next.js handles SSR/SSG → returns HTML/CSS/JS
2. Client interacts with React components; places guess on Leaflet map
3. On “submit guess”: frontend → HTTP POST to Next.js API route (e.g., /api/guess)
4. Next.js API route delegates to Express logic (if using custom server) or direct handler
5. Server computes score (using config.json, EXIFR if needed), stores/retrieves data in MongoDB
6. Authentication flows via NextAuth endpoints (/api/auth/*), sessions stored in DB or cookies
7. Leaderboard page → server fetches top scores from MongoDB → returns JSON → client renders
8. Weekly reset: resetWeekly.ts script runs on schedule, connects to MongoDB, resets weekly counters
c. Architectural Patterns & Principles
– Separation of concerns:
• Presentation (React components)
• Business logic (API routes + Express handlers)
• Data layer (MongoDB)
– Next.js App Router: file-based routing for pages and APIs
– Token/session-based authentication with NextAuth
– Static assets (images, CSS) served from /public via Vercel CDN
d. Key Technologies & Frameworks
– Next.js (v15) & React (v19)
– TypeScript end-to-end
– Express.js for custom backend logic
– MongoDB (with an ODM or native driver)
– NextAuth v5 for OIDC / credential-based auth
– Leaflet for map UI
– Tailwind CSS for styling
– EXIFR for extracting image metadata
– Vercel for deployment