# vaibhavsingh9798/geo-based-domain-switcher architecture

> Architecture diagram of the GitHub repository vaibhavsingh9798/geo-based-domain-switcher, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vaibhavsingh9798/geo-based-domain-switcher
- Repository: https://github.com/vaibhavsingh9798/geo-based-domain-switcher

## Overview

##### Project type and purpose
- Project type: Full-stack web application built with Next.js (app router API + React components).
- Purpose: Render a landing page, detect a visitor’s country via an internal API route (`/api/get-country`), and redirect or display messages based on geolocation.

##### File structure
- Top-level directories:
- app/ – Next.js App Router (page.tsx, layout.tsx, global CSS, API routes under app/api)
- components/ – Reusable React components (`DomainMessage.tsx`, `GeoRedirect.tsx`)
- lib/ – Business-logic helpers (`geo.ts` to fetch geolocation)
- Configuration files: `next.config.ts`, `tsconfig.json`, ESLint and PostCSS configs.
- Server-side code lives alongside UI code: API route under `app/api/get-country/route.ts`.

##### README for additional insights
- Bootstrapped via `create-next-app`
- Uses Next.js features: app directory, automatic font optimization via `next/font`.
- No external database is mentioned—only use of a geolocation API inside `lib/geo.ts`.

a. Main components
1. Client (Browser)
2. Next.js Server (App Router + Server-Side Rendering)
– app/layout.tsx, app/page.tsx
– React Server Components
3. Next.js API Route: `/api/get-country` (app/api/get-country/route.ts)
4. Business Logic Layer: `lib/geo.ts` (abstraction over external geolocation service)
5. External Geolocation Service (third-party HTTP API)
b. Relationships and Interactions
1. User ➔ HTTP GET / (root) ➔ Next.js Server ➔ Server Component (`page.tsx`) renders HTML.
2. Rendering logic may invoke client-side or server-side data fetch:
– Client calls `/api/get-country`
– Next.js Server routes to `route.ts`
3. `route.ts` invokes `lib/geo.ts` ➔ performs HTTP request to External Geo API ➔ returns JSON.
4. API Route responds to Client; UI components (`GeoRedirect`, `DomainMessage`) consume that JSON to drive redirect or display.
c. Architectural patterns and principles
- Monolithic Serverless / SSR pattern (Next.js App Router) combining page rendering and lightweight API endpoints.
- Separation of concerns:
- UI components under `components/`
- Layout and routing under `app/`
- Business logic under `lib/`
- Server Components vs. Client Components: can highlight which components run server-side (page.tsx) vs. client (GeoRedirect).
d. Key technologies
- Next.js App Router, React 18 Server Components
- Node.js runtime (Vercel serverless functions)
- Typescript (`.ts`, `.tsx`)
- PostCSS / global CSS (app/globals.css)

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["Client Browser"]:::ui

    subgraph "Next.js Server"
        direction TB

        subgraph "App Router (SSR)"
            direction TB
            Layout["layout.tsx\n(app/layout.tsx)"]:::ui
            Page["page.tsx\n(app/page.tsx)"]:::ui
            Styles["globals.css\n(app/globals.css)"]:::ui
        end

        subgraph "UI Components"
            direction TB
            DomainMessage["DomainMessage\n(components/DomainMessage.tsx)"]:::ui
            GeoRedirect["GeoRedirect\n(components/GeoRedirect.tsx)"]:::ui
        end

        subgraph "API Routes"
            direction TB
            APIRoute["get-country\n(route.ts)\n(app/api/get-country/route.ts)"]:::api
        end

        subgraph "Business Logic"
            direction TB
            GeoLogic["geo.ts\n(lib/geo.ts)"]:::api
        end
    end

    External["External Geolocation API"]:::ext

    User -->|GET /| Page
    Page -->|"renders"| DomainMessage
    Page -->|"renders"| GeoRedirect
    User -.->|fetch /api/get-country| APIRoute
    APIRoute -->|"calls"| GeoLogic
    GeoLogic -->|"HTTP request"| External
    APIRoute -->|"returns JSON"| User

    click Layout "https://github.com/vaibhavsingh9798/geo-based-domain-switcher/blob/main/app/layout.tsx"
    click Page "https://github.com/vaibhavsingh9798/geo-based-domain-switcher/blob/main/app/page.tsx"
    click Styles "https://github.com/vaibhavsingh9798/geo-based-domain-switcher/blob/main/app/globals.css"
    click APIRoute "https://github.com/vaibhavsingh9798/geo-based-domain-switcher/blob/main/app/api/get-country/route.ts"
    click GeoLogic "https://github.com/vaibhavsingh9798/geo-based-domain-switcher/blob/main/lib/geo.ts"
    click DomainMessage "https://github.com/vaibhavsingh9798/geo-based-domain-switcher/blob/main/components/DomainMessage.tsx"
    click GeoRedirect "https://github.com/vaibhavsingh9798/geo-based-domain-switcher/blob/main/components/GeoRedirect.tsx"

    classDef ui fill:#E0F7FA,stroke:#0288D1,stroke-width:1px
    classDef api fill:#C8E6C9,stroke:#2E7D32,stroke-width:1px
    classDef ext fill:#FFE0B2,stroke:#EF6C00,stroke-width:1px
```
