A comprehensive full-stack web application that helps users track, analyze, and reduce their carbon footprint by monitoring emissions from daily activities across travel, food, and energy consumption.
- Features
- Tech Stack
- Prerequisites
- Installation
- Environment Variables
- Database Setup
- Running the Application
- Project Structure
- API Endpoints
- Usage Guide
- Screenshots
- Contributing
- License
- Secure user registration and login with JWT authentication
- Password hashing with bcrypt
- Profile management (update name, email, change password)
- Session management with 7-day token expiration
- Real-time carbon footprint statistics
- Total COβ emissions tracking
- Monthly emissions comparison
- Category breakdown (Travel, Food, Energy)
- Environmental impact calculations:
- Trees needed to offset emissions
- Driving distance equivalent
- Energy consumption equivalent
- Recent activities feed
- Monthly goal tracker with progress visualization
- CRUD Operations: Create, read, update, and delete activities
- Quick Templates: Pre-filled templates for common activities:
- π Car Commute
βοΈ Flight- π Beef Meal
- π‘ Home Electricity
- Advanced Filtering:
- Search by name or description
- Filter by type (travel, food, energy)
- Date range filtering
- Sort by date, COβ, or name
- Pagination (10 items per page)
- CSV Export: Download activity data for external analysis
- Monthly trend visualization with interactive bar charts
- Category-wise emissions breakdown
- Global Benchmarking: Compare against worldwide averages
- Performance ratings (Excellent, Good, Average, High, Very High)
- Best/Worst month analysis
- Top 5 highest emission activities
- Year-over-year comparison
- Detailed insights and recommendations
- Customizable monthly COβ reduction goals
- Email notification preferences
- Weekly report settings
- Account management
- Framework: React 18 with TypeScript
- Styling: Tailwind CSS
- Build Tool: Vite
- Routing: React Router v6
- HTTP Client: Fetch API
- State Management: React Hooks (useState, useEffect)
- Runtime: Node.js
- Framework: Express.js with TypeScript
- Database: PostgreSQL (Neon)
- ORM: Prisma
- Authentication: JWT (jsonwebtoken)
- Password Hashing: bcrypt
- Environment: dotenv
- Version Control: Git
- Deployment: Render (Backend), Vercel (Frontend)
- Database Hosting: Neon PostgreSQL
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher) - Download
- npm or yarn - Comes with Node.js
- PostgreSQL database (or Neon account) - Neon
- Git - Download
git clone https://github.com/yourusername/greentrack.git
cd greentrackcd backend
npm installcd ../frontend
npm installCreate a .env file in the backend directory:
# Database
DATABASE_URL="postgresql://username:password@host:5432/database?sslmode=require"
# JWT Secret (use a strong random string)
JWT_SECRET="your-super-secret-jwt-key-change-this-in-production"
# Server Port
PORT=5000
# Node Environment
NODE_ENV=developmentNote: You can use the .env.example file as a template:
cd backend
cp .env.example .env
# Then edit .env with your actual valuesCreate or update frontend/src/config.ts:
export const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:9000';For production, create .env in the frontend directory:
VITE_API_URL=https://your-backend-url.com- Sign up at Neon
- Create a new project
- Copy the connection string
- Add it to your
backend/.envfile asDATABASE_URL
cd backend
# Generate Prisma Client
npx prisma generate
# Run migrations to create database tables
npx prisma migrate dev --name init
# (Optional) Open Prisma Studio to view your database
npx prisma studioThe application uses two main models:
- User: Stores user authentication and profile data
- Activity: Stores carbon emission activities with relationships to users
cd backend
npm run devBackend will run on http://localhost:9000
cd frontend
npm run devFrontend will run on http://localhost:5173
cd frontend
npm run buildcd backend
npm run build
npm startgreentrack/
βββ backend/
β βββ prisma/
β β βββ schema.prisma # Database schema
β β βββ migrations/ # Database migrations
β βββ src/
β β βββ routes/
β β β βββ auth.ts # Authentication routes
β β β βββ activities.ts # Activity CRUD routes
β β βββ index.ts # Express app entry point
β βββ .env # Environment variables
β βββ .env.example # Environment template
β βββ package.json
β βββ tsconfig.json
β
βββ frontend/
β βββ src/
β β βββ pages/
β β β βββ Login.tsx # Login page
β β β βββ Signup.tsx # Registration page
β β β βββ Dashboard.tsx # Main dashboard
β β β βββ Activities.tsx # Activity management
β β β βββ Analytics.tsx # Analytics & reports
β β β βββ Profile.tsx # User profile & settings
β β βββ App.tsx # Main app component
β β βββ main.tsx # React entry point
β β βββ config.ts # API configuration
β β βββ index.css # Global styles
β βββ public/
β βββ package.json
β βββ tailwind.config.js
β βββ vite.config.ts
β βββ vercel.json # Vercel deployment config
β
βββ README.md
βββ render.yaml # Render deployment config
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/auth/signup |
Register new user | No |
| POST | /api/auth/login |
Login user | No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/activities |
Get all activities (with filters) | Yes |
| GET | /api/activities/:id |
Get single activity | Yes |
| POST | /api/activities |
Create new activity | Yes |
| PUT | /api/activities/:id |
Update activity | Yes |
| DELETE | /api/activities/:id |
Delete activity | Yes |
page- Page number (default: 1)limit- Items per page (default: 10)sortBy- Sort field: date, carbonCO2, name (default: date)sortOrder- asc or desc (default: desc)search- Search in name/descriptiontype- Filter by type: travel, food, energystartDate- Filter from date (ISO format)endDate- Filter to date (ISO format)
- Navigate to
http://localhost:5173/signup - Fill in your name, email, and password
- Click "Create Account"
- Go to the Activities page
- Click "Add New Activity" or use a quick template
- Fill in the details:
- Type (Travel, Food, or Energy)
- Name and description
- Amount and unit
- COβ emissions in kg
- Date
- Click "Create"
- See your total emissions
- Check monthly trends
- View category breakdown
- Track your progress toward goals
- Go to the Analytics page
- View monthly trends
- Compare against global benchmarks
- Identify your highest emission activities
- Get performance ratings
- Go to Activities page
- Apply any filters you want
- Click "Export to CSV"
- Open in Excel or Google Sheets
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Carbon emission benchmarks based on global averages
- Icons and emojis for enhanced user experience
- Inspired by the need for personal environmental accountability
For questions or support, please open an issue on GitHub.
Made with π for a greener planet