# karla0311/geoquest architecture

> Architecture diagram of the GitHub repository karla0311/geoquest, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/karla0311/geoquest
- Repository: https://github.com/karla0311/geoquest

## Overview

1. **Overall shape**
   GeoQuest is a two-tier app: a React/Vite client in `client/` and an Express API in `server/`. The browser talks only to the client, and the client talks to the server over HTTP. The server is the main boundary for game logic, persistence, and protected operations.

2. **Client presentation layer**
   The client is a single-page application with route-based screens in `src/pages/` such as Landing, Login/Register, Dashboard, Game, Results, Leaderboard, and Forum. `router.jsx` wires navigation, while `Navbar` and `LeaderboardTable` are shared UI pieces.

3. **Client state and orchestration**
   `AuthContext` and `GameContext` hold cross-page state such as logged-in user/session data and the current quiz/game state. This keeps page components thin: they render UI, call context actions, and delegate server interaction to API services.

4. **Client API boundary**
   The client uses a small service layer in `src/api/` (`authService`, `gameService`, `leaderboardService`, plus a shared `api.js`). This is the only place the UI should know about backend endpoints, which makes the architecture easy to diagram as: pages/components → context/services → server API.

5. **Game flow**
   The quiz flow starts on the client, but the server supplies game content and likely validates/scorers results. The client has local scoring helpers in `src/utils/scoring.js` and formatting helpers like `formatTime.js`, while the server also has its own scoring utility in `server/utils/scoring.js`, suggesting server-side authority for final score computation or validation.

6. **Backend API layer**
   The Express app is split by domain routes in `server/routes/`: auth, game, leaderboard, forum, and stats. Each route maps to a controller in `server/controllers/`, keeping request handling separate from business logic.

7. **Backend business logic and services**
   Controllers delegate to services in `server/services/` (`gameService`, `leaderboardService`, `analyticsService`). This indicates a service-oriented backend structure where controllers parse/validate requests and services perform the actual domain work, data lookup, and persistence coordination.

8. **Data sources and persistence**
   Quiz content appears to come from local JSON files in `server/data/` (`countries.json`, `capitals.json`, `flags.json`). Persistent shared data such as auth, leaderboards, forum content, and analytics likely lives in Supabase, configured through `server/config/supabaseClient.js` and the Supabase environment variables called out in the README.

9. **Security and request protection**
   The server has `authMiddleware`, `rateLimiter`, and `errorHandler`, which defines clear operational boundaries: some routes are protected, public endpoints are throttled, and errors are normalized centrally. `server/utils/validation.js` suggests input checks happen before data reaches the service layer.

10. **Analytics and leaderboard pipeline**
   Game outcomes likely feed into `statsRoutes`/`analyticsController` and leaderboard routes. That creates a post-game flow from client results submission to server-side aggregation, then back out through leaderboard reads to the client leaderboard pages.

11. **Runtime and deployment topology**
   The client runs on Vite at `localhost:5173`, and the server runs independently on `localhost:8000`. They are separate Node 18+ processes, which is important for the diagram: the frontend is not server-rendered, and the API can be developed, secured, and scaled separately.

12. **What to emphasize in an architecture diagram**
   Draw three main boxes: the React SPA, the Express API, and Supabase. Inside the API box, show route/controller/service layering plus shared middleware. Inside the SPA box, show pages, contexts, and API services. Connect the game, auth, leaderboard, forum, and stats flows between the SPA and API, and show local JSON game content as a backend-only static data source.

Main entry points: [`server/services`](https://github.com/karla0311/geoquest/tree/main/server/services) (Services), [`client/src/pages`](https://github.com/karla0311/geoquest/tree/main/client/src/pages) (Screens), [`server/controllers`](https://github.com/karla0311/geoquest/tree/main/server/controllers) (Controllers), [`client/src/context/GameContext.jsx`](https://github.com/karla0311/geoquest/blob/main/client/src/context/GameContext.jsx) (Game State)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client SPA"]
  node_client_spa["GeoQuest UI<br/>react spa<br/>[App.jsx]"]
  node_client_router["Router<br/>navigation<br/>[router.jsx]"]
  node_client_pages["Screens<br/>pages"]
  node_client_state_auth(("Auth State<br/>context<br/>[AuthContext.jsx]"))
  node_client_state_game(("Game State<br/>context<br/>[GameContext.jsx]"))
  node_client_api["API Layer<br/>client services"]
  node_client_ui["Shared UI<br/>components"]
  node_client_utils["Client Utils<br/>helpers"]
end

subgraph group_server["Server API"]
  node_server_api["Express API<br/>node server<br/>[app.js]"]
  node_server_mw["Middleware<br/>cross-cutting"]
  node_server_routes["Routes"]
  node_server_ctrl["Controllers<br/>request handlers"]
  node_server_services["Services"]
  node_server_utils["Server Utils<br/>validation/scoring"]
end

subgraph group_storage["Data Layer"]
  node_server_data[("Quiz Data<br/>static json")]
  node_supabase[("Supabase<br/>external db<br/>[supabaseClient.js]")]
end

node_client_spa -->|"navigation"| node_client_router
node_client_router -->|"renders"| node_client_pages
node_client_pages -->|"reads/writes"| node_client_state_auth
node_client_pages -->|"reads/writes"| node_client_state_game
node_client_pages -->|"uses"| node_client_ui
node_client_pages -->|"calls"| node_client_api
node_client_utils -->|"supports"| node_client_state_game
node_client_api -->|"http"| node_server_api
node_server_api -->|"passes through"| node_server_mw
node_server_mw -->|"guards"| node_server_routes
node_server_routes -->|"dispatches"| node_server_ctrl
node_server_ctrl -->|"delegates"| node_server_services
node_server_services -->|"reads"| node_server_data
node_server_services -->|"persists"| node_supabase
node_server_ctrl -->|"validates"| node_server_utils
node_server_services -->|"scores"| node_server_utils
node_client_state_game -->|"submits results"| node_server_services
node_server_services -->|"returns data"| node_server_ctrl
node_server_ctrl -->|"responds to"| node_client_api

click node_client_spa "https://github.com/karla0311/geoquest/blob/main/client/src/App.jsx"
click node_client_router "https://github.com/karla0311/geoquest/blob/main/client/src/router.jsx"
click node_client_pages "https://github.com/karla0311/geoquest/tree/main/client/src/pages"
click node_client_state_auth "https://github.com/karla0311/geoquest/blob/main/client/src/context/AuthContext.jsx"
click node_client_state_game "https://github.com/karla0311/geoquest/blob/main/client/src/context/GameContext.jsx"
click node_client_api "https://github.com/karla0311/geoquest/tree/main/client/src/api"
click node_client_ui "https://github.com/karla0311/geoquest/tree/main/client/src/components"
click node_client_utils "https://github.com/karla0311/geoquest/tree/main/client/src/utils"
click node_server_api "https://github.com/karla0311/geoquest/blob/main/server/app.js"
click node_server_mw "https://github.com/karla0311/geoquest/tree/main/server/middleware"
click node_server_routes "https://github.com/karla0311/geoquest/tree/main/server/routes"
click node_server_ctrl "https://github.com/karla0311/geoquest/tree/main/server/controllers"
click node_server_services "https://github.com/karla0311/geoquest/tree/main/server/services"
click node_server_utils "https://github.com/karla0311/geoquest/tree/main/server/utils"
click node_server_data "https://github.com/karla0311/geoquest/tree/main/server/data"
click node_supabase "https://github.com/karla0311/geoquest/blob/main/server/config/supabaseClient.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_spa,node_client_router,node_client_pages,node_client_state_auth,node_client_state_game,node_client_api,node_client_ui,node_client_utils toneBlue
class node_server_api,node_server_mw,node_server_routes,node_server_ctrl,node_server_services,node_server_utils toneAmber
class node_server_data,node_supabase toneMint
```

## Components

### Client SPA

React/Vite single-page app

- [GeoQuest UI](https://github.com/karla0311/geoquest/blob/main/client/src/App.jsx): react spa · Browser application shell and user entrypoint · `client/src/App.jsx`
- [Router](https://github.com/karla0311/geoquest/blob/main/client/src/router.jsx): navigation · Maps URLs to page screens · `client/src/router.jsx`
- [Screens](https://github.com/karla0311/geoquest/tree/main/client/src/pages): pages · Landing, auth, dashboard, game, results, leaderboard, forum · `client/src/pages`
- [Auth State](https://github.com/karla0311/geoquest/blob/main/client/src/context/AuthContext.jsx): context · Session and logged-in user state · `client/src/context/AuthContext.jsx`
- [Game State](https://github.com/karla0311/geoquest/blob/main/client/src/context/GameContext.jsx): context · Current quiz and result state · `client/src/context/GameContext.jsx`
- [API Layer](https://github.com/karla0311/geoquest/tree/main/client/src/api): client services · HTTP client and domain service wrappers · `client/src/api`
- [Shared UI](https://github.com/karla0311/geoquest/tree/main/client/src/components): components · Navbar and reusable table UI · `client/src/components`
- [Client Utils](https://github.com/karla0311/geoquest/tree/main/client/src/utils): helpers · Formatting and local scoring helpers · `client/src/utils`

### Server API

Express backend and domain logic

- [Express API](https://github.com/karla0311/geoquest/blob/main/server/app.js): node server · Backend entrypoint and request boundary · `server/app.js`
- [Middleware](https://github.com/karla0311/geoquest/tree/main/server/middleware): cross-cutting · Auth, throttling, and centralized errors · `server/middleware`
- [Routes](https://github.com/karla0311/geoquest/tree/main/server/routes): http routes · Auth, game, leaderboard, forum, and stats endpoints · `server/routes`
- [Controllers](https://github.com/karla0311/geoquest/tree/main/server/controllers): request handlers · Translate requests into domain calls · `server/controllers`
- [Services](https://github.com/karla0311/geoquest/tree/main/server/services): domain services · Game, leaderboard, and analytics logic · `server/services`
- [Server Utils](https://github.com/karla0311/geoquest/tree/main/server/utils): validation/scoring · Server-side scoring and input validation · `server/utils`

### Data Layer

Static content and external persistence

- [Quiz Data](https://github.com/karla0311/geoquest/tree/main/server/data): static json · Countries, capitals, and flags content · `server/data`
- [Supabase](https://github.com/karla0311/geoquest/blob/main/server/config/supabaseClient.js): external db · Persistence for shared app data · `server/config/supabaseClient.js`

## Connections

- GeoQuest UI → Router: navigation · Top-level screen routing
- Router → Screens: renders · Route-based page selection
- Screens → Auth State: reads/writes · Login and session state
- Screens → Game State: reads/writes · Quiz flow state
- Screens → Shared UI: uses · Shared navigation and table components
- Screens → API Layer: calls · Backend requests are initiated from screens and context actions
- Client Utils → Game State: supports · Local scoring and time formatting
- API Layer → Express API: http · Frontend talks to backend over HTTP
- Express API → Middleware: passes through · Requests are filtered and normalized centrally
- Middleware → Routes: guards · Protected routes, rate limits, and error handling
- Routes → Controllers: dispatches · Domain-specific endpoint handling
- Controllers → Services: delegates · Controllers keep logic thin
- Services → Quiz Data: reads · Game content source for quizzes
- Services → Supabase: persists · Shared data storage and retrieval
- Controllers → Server Utils: validates · Input checks and score handling
- Services → Server Utils: scores · Server-side score authority
- Game State → Services: submits results · End-of-game data sent for validation and aggregation
- Services → Controllers: returns data · Leaderboard, forum, auth, and analytics outputs
- Controllers → API Layer: responds to · API responses consumed by the client
