# prasad-abhay/earth architecture

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

- Interactive diagram: https://gitdiagram.com/prasad-abhay/earth
- Repository: https://github.com/prasad-abhay/earth

## Overview

##### Project Type and Purpose
- It’s a full-stack web application:
– Frontend: React SPA built with Vite, Tailwind CSS, custom UI library under client/components/ui.
– Backend: Node.js/TypeScript server in server/ plus serverless functions in netlify/functions.
– Shared code: API type definitions and utilities under shared/api.ts.
– Deployment: Netlify (netlify.toml), plus local dev via server/index.ts.

##### File Structure for Architectural Boundaries
- Top-level directories:
– client/ → React application
– server/ → Express-style or custom HTTP server
– netlify/functions/ → serverless endpoints (edge functions)
– shared/ → DTOs, API clients, shared types
– public/ → static assets
- Config and build scripts:
– Vite configs (vite.config.ts, vite.config.server.ts)
– Tailwind (tailwind.config.ts), PostCSS (postcss.config.js)
– TypeScript (tsconfig.json)
– Netlify config (netlify.toml)

##### Main Components
- Frontend SPA
– UI components (client/components)
– Pages & routes (client/pages)
– Contexts & hooks (AuthContext, ThemeContext, custom hooks)
– Shared API client (shared/api.ts)
- Backend API
– Netlify Functions (API entrypoints in netlify/functions/api.ts)
– Express server (server/index.ts) and routes (server/routes/*.ts)
– Business logic and controllers (demonstrated in server/routes/demo.ts)
- Database
– MongoDB (hinted by mongodb.txt)
- Deployment Infrastructure
– Netlify CDN & edge functions
– Optional local Node server for development
- External Services
– Authentication provider (if any), third-party APIs, analytics, etc. (not explicitly shown)

##### Relationships and Data Flow
- The React SPA issues HTTP requests (REST or RPC) via shared/api.ts →
Netlify serverless functions OR local Node server →
Business logic →
Database (MongoDB).
- Responses flow back to the SPA, updating UI state via contexts/hooks.
- Static assets (images, robots.txt) served from public/ or Netlify CDN.

##### Architectural Patterns and Principles
- Separation of Concerns:
– UI layer (React) vs. API layer (server/functions) vs. Data layer (MongoDB).
- Shared contract:
– shared/api.ts enforces type safety across client and server.
- Component-based UI:
– Reusable UI primitives under client/components/ui.
- Serverless + Traditional Node mix:

##### Final Checklist
– [ ] All components (frontend, backend, DB, infra) present
– [ ] Data flows and dependencies clearly marked
– [ ] Tech stack labels on each component
– [ ] Optional notes on build & deployment (Vite build → Netlify/CND)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (React + Vite)" 
        SPA["Frontend SPA\n(React + Vite)"]:::frontend
        UIComp["UI Components\n(client/components/ui/)"]:::frontend
        Layout["Dashboard Layout\n(client/components/layout/DashboardLayout.jsx)"]:::frontend
        Pages["Pages & Routes\n(client/pages/)"]:::frontend
        AuthCtx["Auth Context\n(client/contexts/AuthContext.jsx)"]:::frontend
        ThemeCtx["Theme Context\n(client/contexts/ThemeContext.jsx)"]:::frontend
        Hooks["Custom Hooks\n(client/hooks/)"]:::frontend
    end

    %% Shared Library
    SharedAPI["Shared API Client\n(shared/api.ts)"]:::frontend

    %% API Layer
    subgraph "API Layer" 
        NetlifyFn["Netlify Functions\n(netlify/functions/api.ts)"]:::backend
        subgraph "Local Node Server" 
            ServerEntry["Server Entry Point\n(server/index.ts)"]:::backend
            ServerBuild["Server Build Script\n(server/node-build.ts)"]:::backend
            DemoRoute["API Routes & Controllers\n(server/routes/demo.ts)"]:::backend
        end
    end

    %% Data Layer
    MongoDB["MongoDB Atlas\n(mongodb.txt)"]:::datastore

    %% Infrastructure
    subgraph "Infrastructure & Config"
        CDN["Netlify CDN & Static Hosting"]:::infra
        StaticAssets["Static Assets\n(public/ & client/global.css)"]:::infra
        ViteConfig["Vite Config\n(vite.config.ts)"]:::infra
        ViteServerConfig["Vite Server Config\n(vite.config.server.ts)"]:::infra
        TailwindCfg["Tailwind Config\n(tailwind.config.ts)"]:::infra
        PostCSSCfg["PostCSS Config\n(postcss.config.js)"]:::infra
        NetlifyCfg["Netlify Config\n(netlify.toml)"]:::infra
        TSConfig["TypeScript Config\n(tsconfig.json)"]:::infra
    end

    %% Data Flows
    SPA -->|"HTTP/REST via shared types"| SharedAPI
    UIComp --> SharedAPI
    Pages --> SharedAPI
    AuthCtx --> SharedAPI
    ThemeCtx --> SharedAPI
    Hooks --> SharedAPI

    SharedAPI -->|"REST / RPC"| NetlifyFn
    SharedAPI -->|"REST / RPC"| ServerEntry

    NetlifyFn -->|"Database Operations"| MongoDB
    ServerEntry --> DemoRoute
    DemoRoute -->|"Database Operations"| MongoDB

    SPA -->|"Static Assets"| StaticAssets
    CDN --> StaticAssets

    %% Click Events
    click SPA "https://github.com/prasad-abhay/earth/tree/main/client/"
    click UIComp "https://github.com/prasad-abhay/earth/tree/main/client/components/ui/"
    click Layout "https://github.com/prasad-abhay/earth/blob/main/client/components/layout/DashboardLayout.jsx"
    click Pages "https://github.com/prasad-abhay/earth/tree/main/client/pages/"
    click AuthCtx "https://github.com/prasad-abhay/earth/blob/main/client/contexts/AuthContext.jsx"
    click ThemeCtx "https://github.com/prasad-abhay/earth/blob/main/client/contexts/ThemeContext.jsx"
    click Hooks "https://github.com/prasad-abhay/earth/tree/main/client/hooks/"
    click SharedAPI "https://github.com/prasad-abhay/earth/blob/main/shared/api.ts"
    click NetlifyFn "https://github.com/prasad-abhay/earth/blob/main/netlify/functions/api.ts"
    click ServerEntry "https://github.com/prasad-abhay/earth/blob/main/server/index.ts"
    click ServerBuild "https://github.com/prasad-abhay/earth/blob/main/server/node-build.ts"
    click DemoRoute "https://github.com/prasad-abhay/earth/blob/main/server/routes/demo.ts"
    click MongoDB "https://github.com/prasad-abhay/earth/blob/main/mongodb.txt"
    click StaticAssets "https://github.com/prasad-abhay/earth/tree/main/public/"
    click StaticAssets "https://github.com/prasad-abhay/earth/blob/main/client/global.css"
    click ViteConfig "https://github.com/prasad-abhay/earth/blob/main/vite.config.ts"
    click ViteServerConfig "https://github.com/prasad-abhay/earth/blob/main/vite.config.server.ts"
    click TailwindCfg "https://github.com/prasad-abhay/earth/blob/main/tailwind.config.ts"
    click PostCSSCfg "https://github.com/prasad-abhay/earth/blob/main/postcss.config.js"
    click NetlifyCfg "https://github.com/prasad-abhay/earth/blob/main/netlify.toml"
    click TSConfig "https://github.com/prasad-abhay/earth/blob/main/tsconfig.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef backend fill:#DFF5D0,stroke:#333,stroke-width:1px
    classDef datastore fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef infra fill:#F0F0F0,stroke:#333,stroke-width:1px
```
