Skip to content

Latest commit

ย 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒฑ CarbonPals

A gamified web application for tracking carbon emissions and encouraging eco-friendly behavior through interactive pet avatars, points, badges, and social features.

Version License

โœจ Features

๐ŸŽฏ Core Functionality

  • ๐Ÿ’ณ 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)

๐ŸŽฎ Gamification

  • ๐Ÿฅš 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

๐Ÿ‘ฅ Social Features

  • ๐Ÿ“ Feed: Share progress, achievements, and eco-tips
  • ๐Ÿ’ฌ Comments & Likes: Engage with the community
  • ๐ŸŽ–๏ธ Profile: Display badges and stats

๐Ÿ› ๏ธ Tech Stack

Frontend

  • Framework: Next.js 16 (React 19)
  • Styling: Tailwind CSS 4
  • Language: TypeScript
  • Testing: Vitest

Backend

  • Framework: NestJS
  • Language: TypeScript
  • Database: PostgreSQL (Supabase) with RLS policies
  • Authentication: JWT + Supabase Auth
  • Testing: Jest (55 tests passing)
  • API Docs: Swagger/OpenAPI

DevOps

  • Containerization: Docker & Docker Compose
  • Mock Mode: In-memory database for development

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 20+
  • npm or yarn
  • (Optional) Docker & Docker Compose

Option 1: Mock Mode (Easiest - No Setup Required)

Perfect for development and testing without database setup!

Terminal 1 - Backend:

cd backend
npm install
npm run start        # Runs in mock mode by default

Terminal 2 - Frontend:

cd frontend
npm install
npm run dev

Access the app:

Create an account and start tracking! No environment variables needed.

Option 2: Production Mode (With Supabase)

  1. Create Supabase Project: https://supabase.com

  2. Set up database:

    # Run schema.sql in Supabase SQL Editor
    cat schema.sql | pbcopy  # Copy schema
    # Paste in Supabase > SQL Editor > New Query > Run
  3. Configure environment:

    # Backend
    cd backend
    cp .env.example .env
    # Edit .env with your Supabase credentials
    
    # Set DB_MODE=supabase
  4. Start servers (same as Option 1)

Option 3: Docker Compose

docker-compose up

๐Ÿ“ Project Structure

carbonpals/
โ”œโ”€โ”€ 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

๐ŸŽฎ How It Works

Monthly Points Cycle

  1. Month 1: Log expenditures โ†’ Establish baseline (e.g., 500 kg COโ‚‚/month)
  2. Month 2:
    • Track spending (e.g., 400 kg COโ‚‚)
    • Log eco-swaps (e.g., +50 points)
    • End of month: Below baseline! โ†’ +100 reduction points
  3. Month 3:
    • Track spending (e.g., 550 kg COโ‚‚)
    • End of month: Above baseline โ†’ 0 reduction points (failed threshold)

Pet Growth

  • Pet gains XP from eco-swaps only (not emissions!)
  • 50 XP = 1 level
  • Pet evolves: ๐Ÿฅš โ†’ ๐Ÿฃ โ†’ ๐Ÿฅ โ†’ ๐Ÿ“ โ†’ ...

Points Breakdown

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)

๐Ÿงช Testing

Backend Tests (55 passing)

cd backend
npm test                 # All tests
npm test baseline        # Baseline service tests
npm test pets            # Pet progression tests
npm test badges          # Badge unlocking tests

Frontend Tests

cd frontend
npm test

Manual Testing Guide

See TESTING_MONTH_END.md for testing the monthly points finalization flow.

๐Ÿ“š API Documentation

Key Endpoints

Authentication:

  • POST /auth/signup - Create account
  • POST /auth/login - Login
  • GET /auth/me - Get current user

Tracking:

  • POST /expenditures - Log spending
  • POST /eco-swaps - Log eco-action
  • GET /baseline/points - Get points summary
  • GET /baseline/history - Monthly history

Social:

  • GET /social/feed - Get feed
  • POST /social/posts - Create post
  • POST /social/posts/:id/comments - Comment
  • POST /social/posts/:id/like - Like

Gamification:

  • GET /pets/my-pet - Get pet status
  • GET /badges/my-badges - Get unlocked badges
  • GET /leaderboard - Get rankings

Full API docs: http://localhost:3001/api/docs

๐Ÿ”ง Configuration

Environment Variables

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-key

Frontend (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

๐ŸŽฏ Development Workflow

Feature Development

  1. Create feature branch: git checkout -b feature/your-feature
  2. Make changes
  3. Run tests: npm test
  4. Commit: git commit -m "Add feature"
  5. Push: git push origin feature/your-feature
  6. Create PR to dev branch

Code Quality

  • Backend: 55/55 tests passing โœ…
  • Frontend: Build passes โœ…
  • TypeScript: Strict mode enabled
  • Linting: ESLint configured

๐Ÿ“– Documentation

  • 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

๐Ÿ› Troubleshooting

"NetworkError when attempting to fetch resource"

โ†’ Backend not running. Start with cd backend && npm run start

Points not updating after eco-swap

โ†’ Backend restarted with fix applied (see POINTS_SYSTEM_EXPLAINED.md)

Can't sign up

โ†’ Check backend is running on port 3001

๐Ÿšง Roadmap

Phase 2 (Important)

  • User profile page (edit display name, avatar)
  • Auto-trigger badge checks after actions
  • Leaderboard cache for performance

Phase 3 (Nice-to-Have)

  • Pet customization (choose species, colors)
  • Monthly carbon goals
  • Export/reports (PDF, CSV)
  • Push notifications

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Write tests for new features
  4. Ensure all tests pass
  5. Submit a pull request

๐Ÿ“„ License

MIT License - See LICENSE file for details

๐Ÿ™ Acknowledgments

Built with โค๏ธ for a more sustainable future ๐ŸŒ


Happy carbon tracking! ๐ŸŒฑ

About

Gamified carbon emissions tracker with pet avatars

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages