# gtc-x/gtcfx architecture

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

- Interactive diagram: https://gitdiagram.com/gtc-x/gtcfx
- Repository: https://github.com/gtc-x/gtcfx

## Overview

##### Project type and purpose
- This is a full-stack Next.js application that serves a marketing and content site with internationalization, dynamic routing, and serverless API endpoints.
- The README confirms it was bootstrapped with create-next-app, using Next.js’s App Router under `app/`, dynamic locale routing (`app/[locale]/…`), and API routes under `app/api`.

##### File structure
- Top-level “app” directory:
- `app/[locale]` — localized page hierarchy (React Server Components and Client Components via `.jsx`/`.js`).
- `app/api` — serverless functions (API routes) for email, OTP, CRM, data insertion.
- `app/layout.js`, `app/globals.css`, `app/robots.js`, `app/sitemap.js` — global layout, styles, metadata, and sitemap/robots configuration.
- `app/lp-static` — standalone landing-page variants (static builds with custom layout).
- Supporting directories:
- `config/` — nodemailer configuration.
- `lib/` — shared logic (API helpers, DB connection, utils).
- `helpers/` — localization, index helpers.
- `context/` — React Context providers for location/country details.
- `public/` — static assets (images, fonts, JSON, PDFs).
- `templates/` — email HTML templates.
- Configuration files: `next.config.js`, `tailwind.config.js`, Dockerfile, `.env`, Vercel (`vercel.json`).

##### Key architecture insights from README and code
- Uses file-system routing for pages and API routes.
- Employs Server-Side Rendering (SSR), Static Site Generation (SSG), and Incremental Static Regeneration (ISR) where appropriate.
- Multi-locale support via dynamic folder params.
- Serverless function layer for form submissions, OTP flows, email sending, data persistence (through `lib/db.js`).
- Deployment target: Vercel (serverless, CDN for static files).

##### Diagramming the system
a. Main components
- Client (Browser)
- CDN / Static Assets
- Next.js Runtime (Serverless Functions)
- API Route Layer (serverless endpoints under `app/api`)
- Database / Persistence Layer (`lib/db.js`)
- External Services – SMTP server (via nodemailer), CRM/ERP, third-party APIs
- Localization store (JSON files under `messages/`)
b. Relationships & data flow
- User requests → DNS → CDN (serves static HTML/CSS/JS for SSG pages)
- If page requires SSR/ISR or dynamic locale routing → request goes to Next.js serverless function → React rendering → response
- Client interactions (forms, OTP, newsletter) → HTTP POST to API routes → serverless function logic → writes to DB or calls external SMTP/CRM → returns status
- Build-time reading of message bundles, static props generation for landing pages
c. Architectural patterns & principles
- File-system routing for page/component organization
- Separation of concerns: React components (UI), Context (state), lib/helpers (business logic), API routes (server logic)
- Hybrid rendering modes: SSG for static marketing pages, SSR/ISR for dynamic content
- Serverless architecture: each API endpoint isolated in its own function
d. Relevant technologies
- Next.js (App Router, SSG, SSR, ISR)
- React (Server & Client Components)
- Tailwind CSS (via `tailwind.config.js`)
- Node.js Serverless Functions (Vercel)
- nodemailer (`config/nodemailer.js`)
- Database connector (`lib/db.js` – e.g., MongoDB/Postgres)
- i18n JSON files under `messages/`

##### Detail and coverage
- Essential layers: UI, routing, data, external integrations.
- Build-time vs. run-time flows.
- Multi-locale routing is represented (e.g., `app/[locale]`).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client and CDN
    subgraph "Client & Edge"
        direction TB
        Browser["Browser"]:::frontend
        CDN["CDN (Vercel Edge)"]:::edge
        Browser -->|Requests Pages| CDN
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        UI["Client UI Pages<br/>(app/[locale]/)"]:::frontend
        Layout["Global Layout (app/layout.js)"]:::frontend
        Styles["Global Styles (app/globals.css)"]:::frontend
        Tailwind["Tailwind Config<br/>(tailwind.config.js)"]:::frontend
        LPStatic["Static Landing Pages<br/>(app/lp-static/)"]:::frontend
        Router["Middleware<br/>(middleware.js)"]:::frontend
        LocalizationStore["Localization Store<br/>(messages/)"]:::data
        LocalizationHelper["Localization Helpers<br/>(helpers/localization.js)"]:::backend
        ContextProv["React Context Providers<br/>(context/)"]:::frontend

        CDN -->|Serves static| UI
        UI -->|Uses| Layout
        UI -->|Uses| Styles
        UI -->|Uses| Tailwind
        UI -->|Static builds| LPStatic
        UI -->|Dynamic routing| Router
        UI -->|Reads| LocalizationStore
        UI -->|Uses| LocalizationHelper
        UI -->|Wraps with| ContextProv
    end

    %% Server-Side Rendering
    subgraph "Next.js Runtime"
        direction TB
        SSR["SSR/ISR Serverless Function"]:::backend
        CDN -->|SSR Request| SSR
        UI -->|SSR Request| SSR
    end

    %% API Layer
    subgraph "Serverless API Layer"
        direction TB
        APILayer["API Routes (app/api/)"]:::backend
        OTPSend["/api/send-otp"]:::backend
        OTPVerify["/api/verify-otp"]:::backend
        EmailAPI["/api/email"]:::backend
        OtherAPI["Other endpoints"]:::backend
        APILayer --> OTPSend
        APILayer --> OTPVerify
        APILayer --> EmailAPI
        APILayer --> OtherAPI
        UI -->|API Calls| APILayer
        SSR -->|Internal Calls| APILayer
    end

    %% Shared Logic and Config
    subgraph "Business Logic & Config"
        direction TB
        DBConn["DB Connector<br/>(lib/db.js)"]:::data
        APIHelper["Shared API Helpers<br/>(lib/api.js)"]:::backend
        Utils["Utility Functions<br/>(lib/utils.js)"]:::backend
        SMTPConfig["SMTP Config<br/>(config/nodemailer.js)"]:::backend
        EmailTmpl["Email Templates<br/>(templates/email.html)"]:::backend
        Robots["Robots Config<br/>(app/robots.js)"]:::frontend
        Sitemap["Sitemap Config<br/>(app/sitemap.js)"]:::frontend
        NextConfig["Next.js Config<br/>(next.config.js)"]:::backend
        VercelCfg["Vercel Config<br/>(vercel.json)"]:::backend

        APILayer -->|Uses| DBConn
        APILayer -->|Uses| APIHelper
        APILayer -->|Uses| Utils
        APILayer -->|Sends emails via| SMTPConfig
        APILayer -->|Renders| EmailTmpl
        SSR -->|Reads| Robots
        SSR -->|Reads| Sitemap
        SSR -->|Reads| NextConfig
        SSR -->|Reads| VercelCfg
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Database["Database"]:::data
        SMTP["SMTP Service"]:::external
        CRM["CRM/ERP/Third-party"]:::external

        DBConn -->|Connects| Database
        SMTPConfig -->|Connects| SMTP
        APILayer -->|Calls| CRM
    end

    %% Click Events
    click UI "https://github.com/gtc-x/gtcfx/tree/main/app/[locale]/"
    click Layout "https://github.com/gtc-x/gtcfx/blob/main/app/layout.js"
    click Styles "https://github.com/gtc-x/gtcfx/blob/main/app/globals.css"
    click Tailwind "https://github.com/gtc-x/gtcfx/blob/main/tailwind.config.js"
    click LPStatic "https://github.com/gtc-x/gtcfx/tree/main/app/lp-static/"
    click Router "https://github.com/gtc-x/gtcfx/blob/main/middleware.js"
    click LocalizationStore "https://github.com/gtc-x/gtcfx/tree/main/messages/"
    click LocalizationHelper "https://github.com/gtc-x/gtcfx/blob/main/helpers/localization.js"
    click ContextProv "https://github.com/gtc-x/gtcfx/tree/main/context/"
    click OTPSend "https://github.com/gtc-x/gtcfx/blob/main/app/api/send-otp/route.js"
    click OTPVerify "https://github.com/gtc-x/gtcfx/blob/main/app/api/verify-otp/route.js"
    click EmailAPI "https://github.com/gtc-x/gtcfx/blob/main/app/api/email/route.js"
    click APILayer "https://github.com/gtc-x/gtcfx/tree/main/app/api/"
    click DBConn "https://github.com/gtc-x/gtcfx/blob/main/lib/db.js"
    click APIHelper "https://github.com/gtc-x/gtcfx/blob/main/lib/api.js"
    click Utils "https://github.com/gtc-x/gtcfx/blob/main/lib/utils.js"
    click SMTPConfig "https://github.com/gtc-x/gtcfx/blob/main/config/nodemailer.js"
    click EmailTmpl "https://github.com/gtc-x/gtcfx/blob/main/templates/email.html"
    click Robots "https://github.com/gtc-x/gtcfx/blob/main/app/robots.js"
    click Sitemap "https://github.com/gtc-x/gtcfx/blob/main/app/sitemap.js"
    click NextConfig "https://github.com/gtc-x/gtcfx/blob/main/next.config.js"
    click VercelCfg "https://github.com/gtc-x/gtcfx/blob/main/vercel.json"
    click Database "https://github.com/gtc-x/gtcfx/blob/main/lib/db.js"
    click SMTP "https://github.com/gtc-x/gtcfx/blob/main/config/nodemailer.js"
    click CRM "https://github.com/gtc-x/gtcfx/tree/main/app/api/"
    click ContextProv "https://github.com/gtc-x/gtcfx/blob/main/context/location-context.js"
    click ContextProv "https://github.com/gtc-x/gtcfx/blob/main/context/useCountriesDetails.js"
    click ContextProv "https://github.com/gtc-x/gtcfx/blob/main/context/useLocationDetail.js"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#000
    classDef backend fill:#E8F5E9,stroke:#2E7D32,color:#000
    classDef data fill:#FFF3E0,stroke:#E65100,color:#000
    classDef external fill:#FCE4EC,stroke:#C2185B,color:#000
    classDef edge fill:#EDE7F6,stroke:#5E35B1,color:#000
```
