How rajkram/greenearth works
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).