# mhmdsami/globetrotter architecture

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

- Interactive diagram: https://gitdiagram.com/mhmdsami/globetrotter
- Repository: https://github.com/mhmdsami/globetrotter

## Overview

##### Project type and purpose
- This is a full‑stack web application called “globetrotter”—a trivia game where users sign up, answer location challenges, and see fun facts.
- The repo splits into two clearly delineated parts:
- server/ – a Hono‑based REST API in TypeScript with Prisma (ODM) backed by MongoDB
- www/ – a Next.js 13 (App Router) React frontend with built‑in API routes

##### File structure
Top level:
- server/
– prisma/schema.prisma → DB schema
– src/index.ts → Hono app entrypoint
– src/routes/{user,challenge,game}.ts → REST endpoints
– src/middlewares → auth & validation
– src/utils → config, db client, seed data loader, transformers
– .env.example → DATABASE_URL, JWT secrets
- www/
– next.config.ts, .env.example → FRONTEND_API_URL, etc.
– src/app → App‑Router pages, layouts, auth vs main sections
– src/app/api/generate‑challenge‑card/route.ts → edge function for card generation
– src/api/*.ts → client wrappers for calling server REST API
– src/components, src/contexts, src/utils → UI building blocks, global styles, context providers

##### Key insights from README
- Frontend: React + Next.js + TailwindCSS
- Backend: Hono (lightweight, type-safe), Prisma (ODM), MongoDB
- Two processes: `npm run dev` in server/ and www/
- API documented in Postman

##### Final advice
- Both runtime flows (HTTP requests) and build/dev tooling (Prisma migrations, seed scripts) if relevant to your audience
- Don’t overthink—maximally decompose into logical layers and services to give a comprehensive yet readable overview

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["Client Browser"]:::frontend
        AppServer["Next.js App Server"]:::frontend
        EdgeFunction["Generate Challenge Card API (Edge Function)"]:::frontend
        APILib["API Client Wrappers"]:::frontend
        UIComponents["Shared UI Components"]:::frontend
        Contexts["Context Providers & Hooks"]:::frontend
        UtilitiesFE["Frontend Utilities"]:::frontend
        LayoutAuth["Auth Layout & Pages"]:::frontend
        LayoutMain["Main App Layout & Pages"]:::frontend
        RootLayout["Root Layout & Homepage"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        HonoServer["Hono API Server"]:::backend
        AuthMW["Authentication Middleware"]:::backend
        ValMW["Validation Middleware"]:::backend
        RouteIndex["Route Aggregator"]:::backend
        UserRoute["User Routes"]:::backend
        ChallengeRoute["Challenge Routes"]:::backend
        GameRoute["Game Routes"]:::backend

        subgraph "Prisma & DB Utilities"
            Prisma["Prisma ORM & Schema"]:::backend
            userSchema["User TS Schema"]:::backend
            challengeSchema["Challenge TS Schema"]:::backend
            gameSchema["Game TS Schema"]:::backend
            DBClient["DB Client Initialization"]:::backend
            ConfigLoader["Configuration Loader"]:::backend
            SeedScript["Data Seeding Script"]:::backend
            Transformer["Response Transformers"]:::backend
        end
    end

    %% Database
    subgraph "Database"
        MongoDB["MongoDB"]:::database
    end

    %% External Services
    subgraph "External Services"
        ExternalService["AI/Image Generation Service"]:::external
    end

    %% Connections
    Browser -->|"renders UI"| AppServer
    AppServer -->|"serves pages"| Browser

    Browser -->|"/api/generate-challenge-card"| EdgeFunction
    EdgeFunction -->|"calls"| ExternalService
    ExternalService -->|"response"| EdgeFunction
    EdgeFunction -->|"image data"| Browser

    Browser -->|"fetch via wrappers"| APILib
    APILib -->|"HTTP requests"| HonoServer

    HonoServer -->|"use middleware"| AuthMW
    HonoServer -->|"use middleware"| ValMW
    AuthMW --> RouteIndex
    ValMW --> RouteIndex

    RouteIndex --> UserRoute
    RouteIndex --> ChallengeRoute
    RouteIndex --> GameRoute

    UserRoute --> Prisma
    ChallengeRoute --> Prisma
    GameRoute --> Prisma

    Prisma --> userSchema
    Prisma --> challengeSchema
    Prisma --> gameSchema
    Prisma --> DBClient
    DBClient --> MongoDB

    DBClient --> ConfigLoader
    DBClient --> SeedScript
    DBClient --> Transformer

    %% Click Events - Backend
    click HonoServer "https://github.com/mhmdsami/globetrotter/blob/main/server/src/index.ts"
    click RouteIndex "https://github.com/mhmdsami/globetrotter/blob/main/server/src/routes/index.ts"
    click UserRoute "https://github.com/mhmdsami/globetrotter/blob/main/server/src/routes/user.ts"
    click ChallengeRoute "https://github.com/mhmdsami/globetrotter/blob/main/server/src/routes/challenge.ts"
    click GameRoute "https://github.com/mhmdsami/globetrotter/blob/main/server/src/routes/game.ts"
    click AuthMW "https://github.com/mhmdsami/globetrotter/blob/main/server/src/middlewares/authenticate-user.ts"
    click ValMW "https://github.com/mhmdsami/globetrotter/blob/main/server/src/middlewares/validator.ts"
    click Prisma "https://github.com/mhmdsami/globetrotter/blob/main/server/prisma/schema.prisma"
    click userSchema "https://github.com/mhmdsami/globetrotter/blob/main/server/src/schema/user.ts"
    click challengeSchema "https://github.com/mhmdsami/globetrotter/blob/main/server/src/schema/challenge.ts"
    click gameSchema "https://github.com/mhmdsami/globetrotter/blob/main/server/src/schema/game.ts"
    click DBClient "https://github.com/mhmdsami/globetrotter/blob/main/server/src/utils/db.ts"
    click ConfigLoader "https://github.com/mhmdsami/globetrotter/blob/main/server/src/utils/config.ts"
    click SeedScript "https://github.com/mhmdsami/globetrotter/blob/main/server/src/utils/data/seed.ts"
    click Transformer "https://github.com/mhmdsami/globetrotter/blob/main/server/src/utils/transformers.ts"

    %% Click Events - Frontend
    click LayoutAuth "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(auth)/layout.tsx"
    click SignIn "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(auth)/sign-in/page.tsx"
    click SignUp "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(auth)/sign-up/page.tsx"
    click CheckAuth "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(auth)/components/check-authenticated.tsx"
    click LayoutMain "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(main)/layout.tsx"
    click DashboardPage "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(main)/dashboard/page.tsx"
    click ChallengeModal "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(main)/dashboard/components/challenge-modal.tsx"
    click ClueCard "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(main)/dashboard/components/clue-card.tsx"
    click Logout "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(main)/dashboard/components/logout.tsx"
    click ProtectedRoute "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(main)/dashboard/components/protected-route.tsx"
    click ChallengeDetail "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(main)/challenge/[id]/page.tsx"
    click GameSession "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(main)/game/[sessionId]/page.tsx"
    click ResultModal "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/(main)/game/[sessionId]/result-modal.tsx"
    click RootLayout "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/layout.tsx"
    click Homepage "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/page.tsx"
    click EdgeFunction "https://github.com/mhmdsami/globetrotter/blob/main/www/src/app/api/generate-challenge-card/route.ts"
    click APIConfig "https://github.com/mhmdsami/globetrotter/blob/main/www/src/api/config.ts"
    click UserAPI "https://github.com/mhmdsami/globetrotter/blob/main/www/src/api/user.ts"
    click ChallengeAPI "https://github.com/mhmdsami/globetrotter/blob/main/www/src/api/challenge.ts"
    click GameAPI "https://github.com/mhmdsami/globetrotter/blob/main/www/src/api/game.ts"
    click Button "https://github.com/mhmdsami/globetrotter/blob/main/www/src/components/button.tsx"
    click Input "https://github.com/mhmdsami/globetrotter/blob/main/www/src/components/input.tsx"
    click Label "https://github.com/mhmdsami/globetrotter/blob/main/www/src/components/label.tsx"
    click Dialog "https://github.com/mhmdsami/globetrotter/blob/main/www/src/components/dialog.tsx"
    click ToastComp "https://github.com/mhmdsami/globetrotter/blob/main/www/src/components/toast.tsx"
    click ContextIndex "https://github.com/mhmdsami/globetrotter/blob/main/www/src/contexts/index.tsx"
    click QueryContext "https://github.com/mhmdsami/globetrotter/blob/main/www/src/contexts/query.tsx"
    click Keys "https://github.com/mhmdsami/globetrotter/blob/main/www/src/utils/keys.ts"
    click UIUtils "https://github.com/mhmdsami/globetrotter/blob/main/www/src/utils/ui.ts"
    click ToastWrapper "https://github.com/mhmdsami/globetrotter/blob/main/www/src/utils/with-toast.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085;
    classDef backend fill:#d4edda,stroke:#155724;
    classDef database fill:#fff3cd,stroke:#856404;
    classDef external fill:#e2e3e5,stroke:#6c757d;
```
