Carbon emissions tracking from grocery receipts using OCR and AI
Want to try the system immediately? We've created a simplified MVP version that works without authentication:
./scripts/start-mvp.shThis script will:
- Kill any processes on ports 3000 and 8000
- Start the OCR service on port 8000
- Start the Next.js app on port 3000
- Install dependencies if needed
- MVP Upload Page: http://localhost:3000/mvp-upload
- Home Page: http://localhost:3000
- OCR Service Health: http://localhost:8000/health
- Last OCR Result: http://localhost:8000/ocr/last
node test-mvp.js- Go to http://localhost:3000/mvp-upload
- Upload a receipt image (PNG, JPG, JPEG)
- Click "Process Receipt"
- View the carbon emissions analysis
Press Ctrl+C in the terminal where you ran the start script.
A full-stack application for tracking carbon emissions from receipts using OCR and AI.
- Node.js 18+
- Python 3.10+
- pnpm (recommended) or npm
- Homebrew (for macOS)
git clone <your-repo-url>
cd emissionarypnpm installcd ocr-service
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtbrew install tesseractcd ocr-service
source venv/bin/activate
python start.pyExpected output: INFO: Uvicorn running on http://0.0.0.0:8000
cd emissionary # Back to project root
pnpm devExpected output: Ready - started server on 0.0.0.0:3000
curl http://127.0.0.1:8000/healthExpected output: {"status":"healthy","service":"OCR-PaddleOCR","groq_configured":true}
curl http://localhost:3000/api/ocrExpected output: {"success":true,"data":{"status":"healthy","service":"OCR-PaddleOCR","timestamp":"..."}}
- Frontend: http://localhost:3000
- OCR API: http://127.0.0.1:8000
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Next.js β β Python OCR β β Supabase β
β Frontend βββββΊβ Service β β Database β
β (Port 3000) β β (Port 8000) β β (External) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Create a .env.local file in the project root:
# OCR Service
OCR_SERVICE_URL=http://127.0.0.1:8000
# Database (Supabase)
DATABASE_URL=your_supabase_database_url
# Authentication (Clerk)
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_key
CLERK_SECRET_KEY=your_clerk_secret
# Optional: Groq API for enhanced OCR
GROQ_API_KEY=your_groq_api_key-
Port already in use:
lsof -i :8000 kill -9 <PID>
-
Missing dependencies:
cd ocr-service source venv/bin/activate pip install -r requirements.txt
-
Tesseract not found:
brew install tesseract # macOS # or sudo apt-get install tesseract-ocr # Ubuntu
-
Check if OCR service is running:
curl http://127.0.0.1:8000/health
-
Verify environment variable:
echo $OCR_SERVICE_URL
-
Restart both services in the correct order:
- Start OCR service first
- Then start Next.js
-
Generate Prisma client:
pnpm db:generate
-
Push schema changes:
pnpm db:push
emissionary/
βββ src/
β βββ app/ # Next.js app router
β βββ components/ # React components
β βββ lib/ # Utilities and services
βββ ocr-service/ # Python OCR microservice
βββ prisma/ # Database schema
βββ public/ # Static assets
- Deploy to any Python hosting service (Railway, Render, etc.)
- Set environment variables
- Update
OCR_SERVICE_URLin Next.js
- Deploy to Vercel, Netlify, or similar
- Set all environment variables
- Ensure OCR service is accessible
GET /health- Health checkPOST /ocr- Process receipt imagePOST /upload- Upload receipt file
GET /api/ocr- Health checkPOST /api/ocr- Process receiptPOST /api/calculate-emissions- Calculate emissions
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details.
- πΈ Receipt Upload: Drag & drop interface for easy receipt upload
- π OCR Processing: AI-powered text extraction from receipt images
- π Carbon Calculations: Accurate emissions calculations using Canadian government data
- π Data Visualization: Beautiful charts showing emissions trends and breakdowns
- π¨π¦ Canadian Focus: Compare your emissions with Canadian averages
- π Secure Authentication: Built-in user management with Clerk
- π± Responsive Design: Works seamlessly on desktop and mobile
- Node.js 20+
- Python 3.8+ (for OCR service)
- PostgreSQL database (Supabase recommended)
git clone <repository-url>
cd emissionary
pnpm installCreate a .env.local file:
# Database
DATABASE_URL="your-supabase-database-url"
DIRECT_URL="your-supabase-direct-url"
# Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY="your-clerk-publishable-key"
CLERK_SECRET_KEY="your-clerk-secret-key"
# OCR Service
OCR_SERVICE_URL="http://localhost:8000"
# OpenAI (optional, for enhanced parsing)
OPENAI_API_KEY="your-openai-api-key"# Generate Prisma client
pnpm db:generate
# Push schema to database
pnpm db:pushpnpm devVisit http://localhost:3000 to see the application.
cd ocr-service
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
python main.pyThe OCR service will be available at http://localhost:8000.
The application uses the following main tables:
- users: User profiles and authentication data
- receipts: Receipt metadata (merchant, total, date, etc.)
- receipt_items: Individual items from receipts
- emissions_logs: Carbon footprint calculations and breakdowns
POST /api/ocr- Process receipt images and extract text/items
POST /api/calculate-emissions- Calculate carbon footprint from items
- All database operations are handled through Prisma client
The application uses comprehensive emissions factors based on:
- Canadian Government Data: Official emissions statistics
- FAO Database: Global food production emissions
- Category-based Calculations: Detailed breakdown by food type
- Meat & Dairy: Beef, pork, chicken, milk, cheese, eggs
- Seafood: Fish, shrimp, salmon
- Grains: Wheat, rice, corn, oats
- Fruits & Vegetables: Apples, bananas, tomatoes, potatoes
- Nuts & Seeds: Almonds, walnuts, peanuts
- Beverages: Coffee, tea, juice
- Processed Foods: Bread, pasta, chocolate, cereal
- Snacks & Condiments: Cookies, candy, ketchup, oils
- Stats Cards: Total receipts, emissions, comparison with average
- Emissions Timeline: Line chart showing trends over time
- Category Breakdown: Pie chart of emissions by food category
- Comparison Chart: Bar chart comparing user vs Canadian average
- Recent Receipts: List of latest uploads with emissions data
- Drag & Drop: Intuitive file upload interface
- Image Preview: Visual confirmation of uploaded receipt
- OCR Processing: Real-time progress indicator
- Results Display: Extracted items with confidence scores
- Emissions Calculation: Automatic carbon footprint computation
- Connect your repository to Vercel
- Set environment variables
- Deploy automatically on push
cd ocr-service
railway login
railway init
railway up- Create new Web Service
- Set build command:
pip install -r requirements.txt - Set start command:
uvicorn main:app --host 0.0.0.0 --port $PORT
cd ocr-service
docker build -t emissionary-ocr .
docker run -p 8000:8000 emissionary-ocrUse Supabase for easy PostgreSQL hosting with automatic backups and scaling.
- Authentication: Clerk handles all user authentication
- Row Level Security: Supabase RLS policies protect user data
- Input Validation: Zod schemas validate all API inputs
- CORS: Properly configured for production environments
The application is fully responsive and optimized for mobile devices:
- Touch-friendly upload interface
- Responsive charts and tables
- Mobile-optimized navigation
- Camera integration for receipt capture
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow TypeScript best practices
- Use Prettier for code formatting
- Write meaningful commit messages
- Test your changes thoroughly
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- Canadian Government: For emissions data and statistics
- FAO: For global food emissions factors
- Clerk: For authentication infrastructure
- Supabase: For database and hosting
- shadcn/ui: For beautiful UI components
- Recharts: For data visualization
For support, email support@emissionary.app or join our Discord community.
Made with β€οΈ for a greener future