A gamified web application for tracking carbon emissions and encouraging eco-friendly behavior through interactive pet avatars, points, badges, and social features.
- ๐ณ Expenditure Tracking: Log spending across categories (fuel, groceries, electricity, etc.)
- ๐ Carbon Calculation: Automatic conversion of spending to COโ emissions
- ๐ Monthly Baseline: Establish personal carbon baseline with threshold-based points
- โป๏ธ Eco-Swaps: Log eco-friendly actions (biking, public transit, vegetarian meals, secondhand purchases)
- ๐ฅ Pet Avatar: Interactive pixel-art pet that evolves as you earn XP from eco-swaps
- ๐ Points System:
- Reduction Points: Awarded monthly when emissions stay below baseline
- Eco-Swap Points: Instant rewards for sustainable actions
- ๐ Badges: Unlock achievements (First Steps, Carbon Cutter, Planet Saver, Eco Warrior, etc.)
- ๐ Leaderboard: Compete globally on carbon reduction rankings
- ๐ Feed: Share progress, achievements, and eco-tips
- ๐ฌ Comments & Likes: Engage with the community
- ๐๏ธ Profile: Display badges and stats
- Framework: Next.js 16 (React 19)
- Styling: Tailwind CSS 4
- Language: TypeScript
- Testing: Vitest
- Framework: NestJS
- Language: TypeScript
- Database: PostgreSQL (Supabase) with RLS policies
- Authentication: JWT + Supabase Auth
- Testing: Jest (55 tests passing)
- API Docs: Swagger/OpenAPI
- Containerization: Docker & Docker Compose
- Mock Mode: In-memory database for development
- Node.js 20+
- npm or yarn
- (Optional) Docker & Docker Compose
Perfect for development and testing without database setup!
Terminal 1 - Backend:
cd backend
npm install
npm run start # Runs in mock mode by defaultTerminal 2 - Frontend:
cd frontend
npm install
npm run devAccess the app:
- ๐ Frontend: http://localhost:3000
- ๐ Backend API: http://localhost:3001
- ๐ API Docs: http://localhost:3001/api/docs
Create an account and start tracking! No environment variables needed.
-
Create Supabase Project: https://supabase.com
-
Set up database:
# Run schema.sql in Supabase SQL Editor cat schema.sql | pbcopy # Copy schema # Paste in Supabase > SQL Editor > New Query > Run
-
Configure environment:
# Backend cd backend cp .env.example .env # Edit .env with your Supabase credentials # Set DB_MODE=supabase
-
Start servers (same as Option 1)
docker-compose upcarbonpals/
โโโ frontend/ # Next.js React app
โ โโโ app/
โ โ โโโ components/ # Reusable components
โ โ โ โโโ EcoSwaps.tsx # Eco-swap logging UI
โ โ โ โโโ NavBar.tsx # Navigation with auth
โ โ โ โโโ PetAvatar.tsx # Pet visualization
โ โ โโโ contexts/ # React contexts
โ โ โ โโโ AuthContext.tsx # Authentication state
โ โ โโโ feed/ # Social feed page
โ โ โโโ leaderboard/ # Rankings page
โ โ โโโ login/ # Login page
โ โ โโโ signup/ # Signup page
โ โ โโโ page.tsx # Main dashboard
โ โโโ package.json
โ
โโโ backend/ # NestJS API
โ โโโ src/
โ โ โโโ auth/ # Authentication (JWT)
โ โ โโโ baseline/ # Carbon baseline & points
โ โ โโโ badges/ # Achievement system
โ โ โโโ carbon/ # COโ calculations
โ โ โโโ database/ # Database service (mock + real)
โ โ โโโ eco-swaps/ # Eco-friendly actions
โ โ โโโ expenditures/ # Spending tracker
โ โ โโโ leaderboard/ # Rankings
โ โ โโโ pets/ # Pet progression
โ โ โโโ social/ # Feed, posts, comments
โ โโโ package.json
โ
โโโ schema.sql # PostgreSQL schema
โโโ docker-compose.yml # Docker configuration
โ
โโโ Documentation/
โโโ CRITICAL_FEATURES_IMPLEMENTED.md
โโโ AUTH_FIX.md
โโโ POINTS_SYSTEM_EXPLAINED.md
โโโ NETWORK_ERROR_FIX.md
โโโ TESTING_MONTH_END.md
- Month 1: Log expenditures โ Establish baseline (e.g., 500 kg COโ/month)
- Month 2:
- Track spending (e.g., 400 kg COโ)
- Log eco-swaps (e.g., +50 points)
- End of month: Below baseline! โ +100 reduction points
- Month 3:
- Track spending (e.g., 550 kg COโ)
- End of month: Above baseline โ 0 reduction points (failed threshold)
- Pet gains XP from eco-swaps only (not emissions!)
- 50 XP = 1 level
- Pet evolves: ๐ฅ โ ๐ฃ โ ๐ฅ โ ๐ โ ...
| Action | Points |
|---|---|
| Biking to work | 15 |
| Secondhand purchase | 20 |
| Public transit | 10 |
| Vegetarian meal | 5 |
| Plant-based meal | 3 |
| Below baseline (monthly) | floor(baseline - actual) |
cd backend
npm test # All tests
npm test baseline # Baseline service tests
npm test pets # Pet progression tests
npm test badges # Badge unlocking testscd frontend
npm testSee TESTING_MONTH_END.md for testing the monthly points finalization flow.
Authentication:
POST /auth/signup- Create accountPOST /auth/login- LoginGET /auth/me- Get current user
Tracking:
POST /expenditures- Log spendingPOST /eco-swaps- Log eco-actionGET /baseline/points- Get points summaryGET /baseline/history- Monthly history
Social:
GET /social/feed- Get feedPOST /social/posts- Create postPOST /social/posts/:id/comments- CommentPOST /social/posts/:id/like- Like
Gamification:
GET /pets/my-pet- Get pet statusGET /badges/my-badges- Get unlocked badgesGET /leaderboard- Get rankings
Full API docs: http://localhost:3001/api/docs
Backend (backend/.env):
NODE_ENV=development
DB_MODE=mock # or 'supabase'
PORT=3001
# Only needed if DB_MODE=supabase
SUPABASE_URL=your-project-url
SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_KEY=your-service-key
JWT_SECRET=your-secret-keyFrontend (frontend/.env.local):
# Not needed in mock mode!
# Only if using real Supabase
NEXT_PUBLIC_SUPABASE_URL=your-project-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key- Create feature branch:
git checkout -b feature/your-feature - Make changes
- Run tests:
npm test - Commit:
git commit -m "Add feature" - Push:
git push origin feature/your-feature - Create PR to
devbranch
- Backend: 55/55 tests passing โ
- Frontend: Build passes โ
- TypeScript: Strict mode enabled
- Linting: ESLint configured
- AUTH_FIX.md - Authentication system setup
- POINTS_SYSTEM_EXPLAINED.md - How points work
- CRITICAL_FEATURES_IMPLEMENTED.md - Implementation details
- NETWORK_ERROR_FIX.md - Troubleshooting guide
- TESTING_MONTH_END.md - Month-end testing guide
โ Backend not running. Start with cd backend && npm run start
โ Backend restarted with fix applied (see POINTS_SYSTEM_EXPLAINED.md)
โ Check backend is running on port 3001
- User profile page (edit display name, avatar)
- Auto-trigger badge checks after actions
- Leaderboard cache for performance
- Pet customization (choose species, colors)
- Monthly carbon goals
- Export/reports (PDF, CSV)
- Push notifications
- Fork the repository
- Create your feature branch
- Write tests for new features
- Ensure all tests pass
- Submit a pull request
MIT License - See LICENSE file for details
Built with โค๏ธ for a more sustainable future ๐
Happy carbon tracking! ๐ฑ