# yadav036/bethere architecture

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

- Interactive diagram: https://gitdiagram.com/yadav036/bethere
- Repository: https://github.com/yadav036/bethere

## Overview

##### Project Type and Purpose
- Snap Events is a full-stack, real-time event coordination web application.
- Frontend and backend are both implemented with Next.js (React + API routes).
- Purpose: Allow users to authenticate, create/join events, share live locations, compute ETAs.

##### File Structure Analysis
- Top-level “app” directory follows Next.js 13+ App Router:
- app/api – serverless API endpoints (auth, events, invites, places, users)
- app/(routes) – React server components/pages (home, login, signup, event pages)
- app/layout.tsx, globals.css – top-level layout and styling
- “components” – reusable UI components organized by domain (auth, event, invites, ui library).
- “hooks” – custom React hooks (location reporter, toast, mobile detection).
- “lib” – shared utilities (API client, auth handlers, JWT, Prisma client, Google Maps integration).
- “prisma” – database schema and migrations.
- Configuration files: next.config.mjs, tsconfig.json, postcss.config.mjs.
- Styling: Tailwind CSS with shadcn/ui components in components/ui and styles/globals.css.

##### README Insights
- Architecture: frontend + backend via Next.js API routes.
- Database: Prisma ORM (PostgreSQL or equivalent).
- Authentication: JWT stored in cookies or local storage.
- External service: Google Maps Directions API for ETA and geocoding.
- Live location: browser Geolocation API with polling via useLocationReporter hook.

##### Diagramming the Architecture
a. Main Components
- Next.js Frontend (React pages + UI components)
- Next.js Backend (API route handlers)
- Database (PostgreSQL via Prisma ORM)
- External Services:
– Google Maps API (Directions, Geocoding, Autocomplete)
- Browser:
– Geolocation API
- State Management:
– React Hooks, SWR or built-in fetch caching
b. Relationships and Interactions
- User browser ↔ Next.js Frontend (HTTP GET pages, Web UI interactions)
- Frontend ↔ API routes (HTTP REST calls for auth, events, invites, location updates)
- API routes ↔ Database (Prisma client CRUD operations)
- API routes ↔ Google Maps API (ETA calculation, place autocomplete, geocoding)
- useLocationReporter hook in browser sends POST location every 10s → API → DB
c. Architectural Patterns
- Server-Side Rendering / Server Components (Next.js App Router)
- Client-Side Data Fetching (fetch hooks, React state)
- RESTful API Endpoints (under app/api)
- ORM Layer (Prisma) separating data access
- Layered separation: UI → Business Logic (API routes / lib) → Data Layer (Prisma)
d. Key Technologies
- Next.js (frontend SSR/SSG, API routes)
- React + TypeScript
- Tailwind CSS + shadcn/ui
- Prisma ORM + PostgreSQL
- JWT for authentication (lib/jwt.ts, lib/auth.ts)
- Browser Geolocation API
- Google Maps Directions & Places API

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client (Browser & Frontend)" 
        direction TB
        Browser["Browser"]:::client
        ReactPages["Next.js React Pages"]:::client
        Hooks["Custom Hooks"]:::client
    end

    %% Server Side
    subgraph "Server (Next.js API & Business Logic)"
        direction TB
        subgraph "API Routes" 
            direction TB
            AuthAPI["Auth API Routes"]:::server
            EventsAPI["Events API Routes"]:::server
            InvitesAPI["Invites API Routes"]:::server
            PlacesAPI["Places API Routes"]:::server
            UsersAPI["Users API Routes"]:::server
        end
        Utils["Shared Utilities (lib)"]:::server
    end

    %% Database
    Database["PostgreSQL (Prisma ORM)"]:::db

    %% External Services
    External["Google Maps API"]:::external

    %% Relationships
    Browser -->|"renders pages"| ReactPages
    ReactPages -->|calls| AuthAPI
    ReactPages -->|calls| EventsAPI
    ReactPages -->|calls| InvitesAPI
    ReactPages -->|calls| PlacesAPI
    ReactPages -->|calls| UsersAPI

    Hooks -->|POST location| EventsAPI

    AuthAPI -->|CRUD| Database
    EventsAPI -->|CRUD| Database
    InvitesAPI -->|CRUD| Database
    PlacesAPI -->|CRUD| Database
    UsersAPI -->|CRUD| Database

    EventsAPI -->|calls| External
    PlacesAPI -->|calls| External

    Utils -->|used by| AuthAPI
    Utils -->|used by| EventsAPI
    Utils -->|used by| InvitesAPI
    Utils -->|used by| PlacesAPI
    Utils -->|used by| UsersAPI
    ReactPages -->|imports from| Utils
    Hooks -->|imports from| Utils

    %% Click Events
    click ReactPages "https://github.com/yadav036/bethere/tree/main/app/"
    click Hooks "https://github.com/yadav036/bethere/tree/main/hooks/"
    click AuthAPI "https://github.com/yadav036/bethere/tree/main/app/api/auth/"
    click EventsAPI "https://github.com/yadav036/bethere/tree/main/app/api/events/"
    click InvitesAPI "https://github.com/yadav036/bethere/tree/main/app/api/invites/"
    click PlacesAPI "https://github.com/yadav036/bethere/tree/main/app/api/places/"
    click UsersAPI "https://github.com/yadav036/bethere/blob/main/app/api/users/search/route.ts"
    click Utils "https://github.com/yadav036/bethere/tree/main/lib/"
    click Database "https://github.com/yadav036/bethere/tree/main/prisma/"
    click External "https://github.com/yadav036/bethere/blob/main/lib/google.ts"

    %% Styles
    classDef client fill:#CCE5FF,stroke:#3399FF,color:#000
    classDef server fill:#D5F5E3,stroke:#27AE60,color:#000
    classDef db fill:#E8DAEF,stroke:#9B59B6,color:#000
    classDef external fill:#FDEBD0,stroke:#E67E22,stroke-dasharray: 5 5,color:#000
```
