# pixelhalide/manipalguesser architecture

> Architecture diagram of the GitHub repository pixelhalide/manipalguesser, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pixelhalide/manipalguesser
- Repository: https://github.com/pixelhalide/manipalguesser

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
graph TB
  subgraph "Frontend (Browser)"
    direction TB
    ReactUI["React UI Components"]:::frontend
    Navbar["Navbar"]:::frontend
    NavbarAuth["NavbarAuth"]:::frontend
    SignUpIn["SignUp/In"]:::frontend
    UserIcon["UserIcon"]:::frontend
    GuessScreen["GuessScreen"]:::frontend
    ProgressBar["ProgressBar"]:::frontend
    ResultMap["ResultMap"]:::frontend
    ScoreScreen["ScoreScreen"]:::frontend
    LeafletMap["Leaflet Map"]:::frontend

    ReactUI --> Navbar
    ReactUI --> NavbarAuth
    ReactUI --> SignUpIn
    ReactUI --> UserIcon
    ReactUI --> GuessScreen
    GuessScreen --> ProgressBar
    GuessScreen --> ResultMap
    GuessScreen --> ScoreScreen
    ReactUI --> LeafletMap
  end

  subgraph "Next.js Server"
    direction TB
    subgraph "Pages (SSR/SSG)"
      direction TB
      Home["Home Page"]:::backend
      About["About Page"]:::backend
      Contact["Contact Page"]:::backend
      ContactForm["Contact Form"]:::backend
      Leaderboard["Leaderboard Page"]:::backend
      Board["Board"]:::backend
      BoardSelect["BoardSelect"]:::backend
      PageSelect["PageSelect"]:::backend
      UserPage["User Profile Page"]:::backend
      UserInfo["UserInfo Page"]:::backend
    end
    subgraph "Global Layout & Styles"
      Layout["Layout"]:::backend
      Providers["Providers"]:::backend
      Globals["Global CSS"]:::backend
    end
    subgraph "API Routes"
      NextAuthAPI["NextAuth API"]:::backend
      SignupAPI["Signup API"]:::backend
      AuthHelpers["Client Auth Helpers"]:::backend
    end
    subgraph "Express Server"
      AuthTS["auth.ts"]:::backend
      IndexTS["index.ts"]:::backend
    end

    Home -->|renders| Layout
    About -->|renders| Layout
    Contact -->|renders| Layout
    ContactForm -->|used by| Contact
    Leaderboard -->|renders| Layout
    Leaderboard --> Board
    Leaderboard --> BoardSelect
    Leaderboard --> PageSelect
    UserPage -->|renders| Layout
    UserInfo -->|renders| Layout

    NextAuthAPI -->|auth flows| AuthTS
    SignupAPI -->|signup logic| AuthTS
    AuthHelpers -->|used by| ReactUI
  end

  ReactUI -->|page request| Home
  ReactUI -->|page request| About
  ReactUI -->|page request| Contact
  ReactUI -->|page request| Leaderboard
  ReactUI -->|page request| UserPage

  LeafletMap -->|"tiles"| MapTiles
  ReactUI -->|POST /api/guess| SignupAPI

  subgraph "Database"
    MongoDB[(MongoDB)]:::db
  end

  AuthTS --> MongoDB
  IndexTS --> MongoDB
  NextAuthAPI --> MongoDB
  SignupAPI --> MongoDB

  subgraph "External Services"
    Vercel["Vercel CDN"]:::external
    MapTiles["Map Tile Provider"]:::external
  end

  ReactUI -->|"static assets"| Vercel
  Globals --> Vercel

  subgraph "Batch Job"
    direction TB
    ResetWeekly["resetWeekly.ts"]:::job
    Config["config.json"]:::job
  end

  ResetWeekly --> MongoDB
  Config --> AuthTS
  Config --> ResetWeekly

  classDef frontend fill:#D0E6FF,stroke:#0366D6;
  classDef backend fill:#DFFFE0,stroke:#028A0F;
  classDef db fill:#FFEACD,stroke:#E37A00,stroke-width:2px;
  classDef external fill:#F0D6FF,stroke:#8C1EFF;
  classDef job fill:#E0E0E0,stroke:#555555;

  click ReactUI "https://github.com/pixelhalide/manipalguesser/tree/main/Components/"
  click Navbar "https://github.com/pixelhalide/manipalguesser/blob/main/Components/Navbar.tsx"
  click NavbarAuth "https://github.com/pixelhalide/manipalguesser/blob/main/Components/NavbarAuth.tsx"
  click SignUpIn "https://github.com/pixelhalide/manipalguesser/blob/main/Components/SignUpIn.tsx"
  click UserIcon "https://github.com/pixelhalide/manipalguesser/blob/main/Components/UserIcon.tsx"
  click GuessScreen "https://github.com/pixelhalide/manipalguesser/tree/main/Components/GuessScreen/"
  click ProgressBar "https://github.com/pixelhalide/manipalguesser/blob/main/Components/GuessScreen/ProgressBar.tsx"
  click ResultMap "https://github.com/pixelhalide/manipalguesser/blob/main/Components/GuessScreen/ResultMap.tsx"
  click ScoreScreen "https://github.com/pixelhalide/manipalguesser/blob/main/Components/GuessScreen/ScoreScreen.tsx"
  click LeafletMap "https://github.com/pixelhalide/manipalguesser/blob/main/Components/Map.tsx"
  click Home "https://github.com/pixelhalide/manipalguesser/blob/main/app/page.tsx"
  click About "https://github.com/pixelhalide/manipalguesser/blob/main/app/about/page.tsx"
  click Contact "https://github.com/pixelhalide/manipalguesser/blob/main/app/contact/page.tsx"
  click ContactForm "https://github.com/pixelhalide/manipalguesser/blob/main/app/contact/form.tsx"
  click Leaderboard "https://github.com/pixelhalide/manipalguesser/blob/main/app/leaderboard/page.tsx"
  click Board "https://github.com/pixelhalide/manipalguesser/blob/main/app/leaderboard/Board.tsx"
  click BoardSelect "https://github.com/pixelhalide/manipalguesser/blob/main/app/leaderboard/BoardSelect.tsx"
  click PageSelect "https://github.com/pixelhalide/manipalguesser/blob/main/app/leaderboard/PageSelect.tsx"
  click UserPage "https://github.com/pixelhalide/manipalguesser/blob/main/app/userpage/page.tsx"
  click UserInfo "https://github.com/pixelhalide/manipalguesser/blob/main/app/UserInfo/[userID]/page.tsx"
  click Layout "https://github.com/pixelhalide/manipalguesser/blob/main/app/layout.tsx"
  click Providers "https://github.com/pixelhalide/manipalguesser/blob/main/app/providers.tsx"
  click Globals "https://github.com/pixelhalide/manipalguesser/blob/main/app/globals.css"
  click NextAuthAPI "https://github.com/pixelhalide/manipalguesser/blob/main/app/api/auth/[...nextauth]/route.ts"
  click SignupAPI "https://github.com/pixelhalide/manipalguesser/blob/main/app/api/signup/page.tsx"
  click AuthHelpers "https://github.com/pixelhalide/manipalguesser/blob/main/lib/actions/auth.ts"
  click AuthTS "https://github.com/pixelhalide/manipalguesser/blob/main/auth.ts"
  click IndexTS "https://github.com/pixelhalide/manipalguesser/blob/main/index.ts"
  click Config "https://github.com/pixelhalide/manipalguesser/blob/main/config.json"
  click ResetWeekly "https://github.com/pixelhalide/manipalguesser/blob/main/resetWeekly.ts"
```
