How chacha0044/cft works
Project Type and Purpose
• This is a full-stack MERN application (“Carbon Footprint Tracker”) that lets users log monthly lifestyle data (food, transport, electricity, waste), calculates CO₂ emissions, generates personalized suggestions, and shows community leaderboards.
• Frontend: React + TailwindCSS + Framer Motion, hosted on Vercel.
• Backend: Node.js + Express + Mongoose, hosted on Render.
• Database: MongoDB Atlas.
• Integrations: Nodemailer (SMTP), IMAP polling for email verification, GitHub Actions for CI/CD.
File Structure
• Top level:
• client/ → React SPA (public assets, src/components, src/api, src/context, src/hooks, src/utils)
• middleware/ → Express authentication and error‐handling middleware
• models/ → Mongoose schemas (User, CarbonEntry)
• routes/ → REST endpoints (/api/auth, /api/footprint)
• utils/ → core business logic (emission calculator, email templates, IMAP poller, mail sender)
• server.js → Express app bootstrap
• vercel.json, .github/workflows → CI/CD and hosting configs
• Key patterns:
• REST API layer (routes → controllers → services/util functions → models)
• Middleware chain (authentication, input sanitization, rate limiting)
• React component tree (Auth, Dashboard, Footprint, History, Leaderboard)
Extract Architecture Details from the README
• Authentication flows: registration, verification via email, secure HTTP-only cookies, JWT/session fallback
• Emission calculation engine with validation and caps
• Data visualization: pie charts, bar charts, animated UX
• Security: Helmet, CORS, DOMPurify, bcrypt, rate-limiting
• Deployment: Vercel (client), Render (server), MongoDB Atlas (DB)
Main Components
a. Frontend (React SPA on Vercel)
• Auth pages (Login, Register, VerifyEmail)
• Dashboard & Charts (ChartPage.js, Dashboard.js)
• Footprint modules (EditFootprintForm, History)
• Shared utilities (API client wrapper, loading/context hooks)
b. Backend (Express Monolith on Render)
• HTTP server (server.js)
• Middleware layer (authmiddleware.js, rate limiter, Helmet, CORS)
• Route handlers (/api/auth, /api/footprint)
• Business logic (utils/calculateEmissions.js, emailTemplate.js, imapPoller.js, sendEmail.js)
• Data layer (Mongoose models: User, CarbonEntry)
c. Database (MongoDB Atlas)
• Collections: users, carbonentries
d. External Services
• SMTP provider for Nodemailer
• IMAP server for inbound email polling
• GitHub Actions for CI/CD
e. Hosting/Deployment
• Vercel (frontend)
• Render (backend)
• Environment variables (MONGO_URI, JWT_SECRET, SMTP creds)
Relationships and Data Flow
• User’s browser → HTTPS → React SPA → fetch() calls → Express API endpoints
• Express middleware → route handlers → utils (validation, emission calculation) → Mongoose → MongoDB Atlas
• Email flows: backend → Nodemailer → user inbox → user clicks verification link → Express GET /api/auth/verify/:token
• CI/CD: GitHub Actions triggers tests and automatic deploys to Vercel/Render
Architectural Patterns and Design Principles
• Layered architecture: Presentation → API → Business logic → Data access
• RESTful design for API endpoints
• Modular code organization: routes, middleware, models, utils
• Secure-by-default: HTTP‐only cookies, Helmet, input sanitization
• Single Page Application separated from API (“decoupled full-stack”)
Detail without Overthinking
• Break the system into as many logical components as needed to reflect the file tree and README
• Keep it modular: future features (e.g., new categories, gamification) can slot into existing layers