# rajkram/greenearth architecture

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

- Interactive diagram: https://gitdiagram.com/rajkram/greenearth
- Repository: https://github.com/rajkram/greenearth

## Overview

##### Project type and purpose
- GreenEarth is a full-stack web application.
- It uses a Node.js server (index.js) to serve static HTML/CSS/JS assets and implement REST-style endpoints.
- Redis (with RedisJSON) is the primary data store, holding users, posts, drafts, and comments.

##### File structure
- Top-level:
- index.js – Node.js entry point, configures server, routes, and Redis client
- package.json – lists Express (or similar) and redis dependencies
- marketplace.json – sample data or config for posts
- Directories:
- html/ – static HTML page templates (homepage, about, post, profile, createpost, allposts)
- css/ – page-specific style sheets
- js/ – page-specific front-end logic (fetch calls to server APIs, DOM updates)
- Pictures/ – screenshots or static images
- No separate “backend/” folder indicates a monolithic server.
- README describes Redis operations (SADD, HMSET, JSON.SET, JSON.GET) for user and post flows.

##### Key insights from README
- Users: signup, login, logout, profile update – all backed by Redis hash and set operations.
- Posts: add/edit/delete/search, comments – all backed by RedisJSON structures.
- Client communicates via AJAX (fetch/XHR) in js/*.js to REST endpoints defined in index.js.
- Static assets served from html/, css/, js/ by the Node server.

##### Main components
a. Client – web browser
- HTML5 pages
- CSS for styling
- JavaScript modules for dynamic behavior and API calls
b. Web Server (Node.js)
- Static file host (serves html/, css/, js/)
- API layer (Express routes in index.js)
- Session/token management (in Redis)
c. Data Store (Redis + RedisJSON)
- Users set & hashes (user accounts, sessions)
- JSON collections (posts, drafts, comments)
d. External Services (optional)
- Redis Cloud Enterprise endpoint
- CDN or object store (if images scale beyond Pictures/)

##### Component interactions & data flows
1. Browser requests an HTML page → Node serves static file.
2. On page load, front-end JS sends AJAX to Node’s REST endpoints (e.g., /api/login, /api/getAllPosts).
3. Node processes request → uses redis client to perform SADD, HMSET, JSON.GET, JSON.SET.
4. Redis returns data → Node formats JSON response → front-end JS updates DOM.
5. User actions (add post, comment) follow same loop.

##### Architectural patterns & principles
- Monolithic, layered architecture:
Layer 1: Presentation (static HTML/CSS/JS)
Layer 2: Application/API (Node.js controller)
Layer 3: Data (Redis/RedisJSON as key-value & document store)
- Clean separation: static asset serving vs. JSON API
- Use of Redis as both session store and primary datastore

##### Technologies & frameworks
- Node.js + Express (or built-in HTTP)
- redis npm client + RedisJSON
- Vanilla JavaScript (ES6 modules) on front end
- Static HTML/CSS

5. Static file serving path (/html, /css, /js) and REST endpoints (/api/signup, /api/allPosts).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Web Browser"]:::presentation
        HTMLTemplates["HTML Templates"]:::presentation
        CSSStyles["CSS Stylesheets"]:::presentation
        JSModules["Front-end JavaScript Modules"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        Server["Node.js Server\n(Static host + API routes)"]:::application
        Package["package.json"]:::application
        Marketplace["marketplace.json"]:::application
        README["README.md"]:::application
    end

    %% Data Layer
    subgraph "Data Layer"
        Redis["Redis + RedisJSON"]:::data
        Users["Users Set & Hashes"]:::data
        Sessions["Sessions & Tokens"]:::data
        Posts["Posts/Comments JSON"]:::data
    end

    %% Static Images
    Pictures["Pictures"]:::presentation

    %% Connections
    Browser -->|requests HTML pages| Server
    Server -->|serves static assets| HTMLTemplates
    Server -->|serves static assets| CSSStyles
    Server -->|serves static assets| JSModules
    Browser -->|loads JS modules| JSModules

    Browser -->|AJAX /api/*| Server
    Server -->|SADD, HMSET| Users
    Server -->|HMSET, JSON.SET| Sessions
    Server -->|JSON.SET, JSON.GET| Posts
    Users -->|data| Redis
    Sessions -->|data| Redis
    Posts -->|data| Redis
    Redis -->|response data| Server
    Server -->|JSON response| Browser

    %% Click Events
    click HTMLTemplates "https://github.com/rajkram/greenearth/tree/main/html/"
    click CSSStyles "https://github.com/rajkram/greenearth/tree/main/css/"
    click JSModules "https://github.com/rajkram/greenearth/tree/main/js/"
    click Server "https://github.com/rajkram/greenearth/blob/main/index.js"
    click Package "https://github.com/rajkram/greenearth/blob/main/package.json"
    click Marketplace "https://github.com/rajkram/greenearth/blob/main/marketplace.json"
    click README "https://github.com/rajkram/greenearth/blob/main/README.md"
    click Pictures "https://github.com/rajkram/greenearth/tree/main/Pictures/"

    %% Styles
    classDef presentation fill:#E0F7FA,stroke:#006064,color:#006064;
    classDef application fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20;
    classDef data fill:#FFF3E0,stroke:#E65100,color:#E65100;
```
