Know your carbon. Build the habit. See the change.
EcoLoop is an AI-powered sustainability platform that helps users understand, track, and reduce their carbon footprint through simple natural-language descriptions of their day.
flowchart TD
U[User Input] -->|"I drove 12km, ate a burger"| AI[AI Extraction]
AI -->|Structured JSON| VAL{Zod Validation}
VAL -->|Passed| CO2[COβ Engine]
VAL -->|Failed| REJ[Reject / Retry]
CO2 -->|Deterministic Calculation| DB[(Supabase PostgreSQL)]
DB --> DASH[Dashboard Update]
DB --> HABIT[Habit Engine]
HABIT -->|Personalized Action| ACT[Action Card]
ACT --> TRACK[Progress Tracking]
TRACK -->|Streak Update| U
graph TB
subgraph Browser["Browser"]
UI[React Components]
RQ[React Query Cache]
ZS[Zustand Stores]
end
subgraph NextJS["Next.js 16"]
subgraph AppRouter["App Router"]
LANDING["/ Landing"]
LOGIN["/login Auth"]
CHAT["/chat Core Loop"]
DASHBOARD["/dashboard Analytics"]
end
TRPC[tRPC API Layer]
PROXY[Proxy / Auth Guard]
end
subgraph Services["Service Layer"]
AI_SVC[AI Service]
CO2_SVC[COβ Engine]
HABIT_SVC[Habit Engine]
DASH_SVC[Dashboard Service]
end
subgraph External["External Services"]
CLAUDE[Anthropic Claude]
SUPABASE[Supabase]
PG[(PostgreSQL)]
end
UI --> TRPC --> Services
AI_SVC --> CLAUDE
CO2_SVC --> SUPABASE --> PG
HABIT_SVC --> SUPABASE
DASH_SVC --> SUPABASE
PROXY --> SUPABASE
| Layer | Technology | Purpose |
|---|---|---|
| Framework | Next.js 16 | App Router, SSR, ISR |
| Language | TypeScript 5 (strict) | End-to-end type safety |
| API | tRPC 11 | Type-safe RPC layer |
| Database | Supabase PostgreSQL | Data storage + auth |
| Auth | Supabase Auth | Google OAuth + Magic Link |
| Security | Row Level Security | Per-user data isolation |
| Validation | Zod 4 | Schema enforcement |
| Styling | Tailwind CSS 4 | Utility-first CSS |
| Components | shadcn/ui + Base UI | Accessible primitives |
| Animation | Framer Motion | Motion system |
| 3D | React Three Fiber + Drei | Carbon Field visualization |
| Charts | Recharts | Analytics visualizations |
| State | Zustand + React Query | Client + server state |
| AI | Vercel AI SDK | Claude (paid) β Groq (free fallback) |
| Rate Limit | In-memory | 20 req/hr per user |
| Testing | Vitest | Unit + integration tests |
| Feature | Status | Description |
|---|---|---|
| AI Activity Extraction | β | Natural language β structured activities (Claude or free Groq) |
| COβ Calculation Engine | β | Deterministic, source-cited emission factors |
| Personal Dashboard | β | Weekly trends, category breakdown, comparisons |
| Carbon Field | β | Three.js particle visualization of impact |
| Habit Engine | β | Personalized daily micro-actions based on biggest contributor |
| Streak System | β | Consecutive days tracked (log + action required) |
| Google OAuth | β | One-click social authentication |
| Magic Link | β | Passwordless email authentication |
| Onboarding | β | Country, transport, and diet personalization |
| Rate Limiting | β | 20 requests/hour for AI chat |
| Accessibility | β | WCAG 2.2 AA, keyboard nav, screen readers |
| Responsive | β | Mobile-first, adaptive particle count |
| Unit Tests | β | 31 tests across COβ engine and AI defense |
src/
βββ app/ # Next.js App Router pages
β βββ (app)/ # Authenticated route group
β β βββ chat/ # Core logging experience
β β βββ dashboard/ # Analytics dashboard
β β βββ onboarding/ # Profile setup
β β βββ profile/ # Account page
β β βββ settings/ # Preferences
β βββ api/trpc/[trpc]/ # tRPC API endpoint
β βββ auth/callback/ # OAuth callback handler
β βββ login/ # Authentication page
β βββ layout.tsx # Root layout
β
βββ components/ # React components
β βββ ui/ # shadcn/ui primitives
β βββ app-nav.tsx # Authenticated nav bar
β βββ auth-provider.tsx # Supabase auth listener
β βββ carbon-field.tsx # Three.js particle system
β βββ chat-input.tsx # Activity input form
β βββ chat-history.tsx # Activity history display
β βββ dashboard-client.tsx # Dashboard with charts
β βββ login-form.tsx # OAuth + Magic Link form
β βββ onboarding-form.tsx # Profile setup wizard
β βββ action-card.tsx # Daily micro-action card
β βββ skip-link.tsx # Accessibility skip link
β
βββ server/ # Backend logic
β βββ api/ # tRPC layer
β β βββ context.ts # Request context
β β βββ trpc.ts # tRPC instance + middleware
β β βββ root.ts # Root router
β β βββ rate-limit.ts # In-memory rate limiter
β β βββ routers/ # Feature routers
β β βββ chat.ts # Core loop orchestrator
β β βββ dashboard.ts # Metrics aggregation
β β βββ habits.ts # Action selection + streaks
β β βββ profile.ts # User profile CRUD
β βββ services/ # Pure business logic
β β βββ ai/ # Claude extraction + defense
β β βββ co2/ # Deterministic COβ engine
β β βββ habits/ # Action selection + streak logic
β β βββ dashboard/ # Aggregation + trends
β β βββ analytics/ # Activity DB operations
β β βββ auth/ # Profile management
β βββ db/ # Supabase clients
β β βββ supabase-server.ts # Server-side (cookies)
β β βββ supabase-browser.ts # Client-side
β β βββ supabase-middleware.ts# Proxy auth
β βββ validators/ # Zod schemas
β
βββ stores/ # Zustand stores
β βββ auth-store.ts # Authentication state
β βββ chat-store.ts # Chat entries
β
βββ hooks/ # Custom React hooks
β βββ use-auth.ts # Auth operations
β βββ use-media-query.ts # Responsive detection
β
βββ lib/ # Shared utilities
β βββ trpc-client.ts # tRPC React client
β βββ trpc-provider.tsx # tRPC + React Query provider
β βββ utils.ts # cn() helper
β
βββ types/ # TypeScript type definitions
β βββ index.ts # All shared types
β
βββ constants/ # Application constants
β βββ index.ts # Rate limits, targets, config
β
βββ tests/ # Unit tests
βββ co2-engine.test.ts # COβ engine (21 tests)
βββ ai-defense.test.ts # AI defense (10 tests)
supabase/
βββ migrations/ # Database migrations
βββ 00001_schema.sql # Tables, enums, RLS, triggers
βββ 00002_seed_emission_factors.sql # 46 emission factors
βββ 00003_seed_micro_actions.sql # 24 micro-actions
# 1. Clone
git clone [https://github.com/Muneer320/EcoLoop.git && cd EcoLoop
# 2. Install
npm install
# 3. Configure environment
cp .env.example .env.local
# Fill in Supabase URL, Supabase Anon Key
# Set either ANTHROPIC_API_KEY (Claude) or GROQ_API_KEY (free) β or both
# 4. Set up Supabase
# Run migrations in supabase/migrations/ against your Supabase project
# 5. Run development server
npm run dev
# 6. Open
open http://localhost:3000EcoLoop supports two AI providers with automatic fallback:
| Priority | Provider | Model | Key Required | Cost |
|---|---|---|---|---|
| 1st | Anthropic Claude | claude-sonnet-4-20250514 |
ANTHROPIC_API_KEY |
Paid |
| 2nd | Groq | llama-3.3-70b-versatile |
GROQ_API_KEY |
Free |
If ANTHROPIC_API_KEY is set, Claude is used. Otherwise, Groq is used automatically. Set either key β or both to have a paid primary and a free fallback.
# Run all tests
npm test
# Watch mode
npm run test:watchCoverage:
| Module | Tests | Status |
|---|---|---|
| COβ Engine | 21 | β |
| AI Defense | 10 | β |
| Total | 31 | β |
- Row Level Security β Every user-owned table enforces
auth.uid() = user_id - Input Validation β Zod schemas at every boundary (user input, AI output, API requests)
- Rate Limiting β 20 AI calls/hour per user
- Prompt Injection Defense β Incoming messages scanned for known attack patterns
- CSP Ready β Content Security Policy headers configured
- PKCE Authentication β Secure OAuth 2.0 code exchange
- No Secrets in Client β All sensitive keys server-side only
All COβ calculations are deterministic and sourced from peer-reviewed data:
| Source | Used For |
|---|---|
| DEFRA 2024 | Transport, electricity, natural gas |
| IPCC | Global averages, climate reporting |
| Our World In Data | Food items, consumer goods |
| IEA | Electricity generation by country |
Every factor includes a citation stored in the emission_factors table.
What EcoLoop is:
- An invisible-systems visualizer (atmosphere, particles, depth)
- Inspired by Apple, Linear, and Arc Browser
- Information-first with ambient visual enhancement
What EcoLoop is NOT:
- No leaves, trees, forests, or globes
- No green-washing imagery
- No sustainability clichΓ©s
- No gamification gimmicks
MIT Β© EcoLoop
Built for the hackathon. Polished for the planet.