Skip to main content

A comprehensive full-stack calorie tracking application with Flask backend, React frontend, and AI-powered features

Project description

CalorIA ๐ŸŽ

A comprehensive full-stack calorie tracking application built with Flask backend, React frontend, MongoDB database, and a custom CLI for easy management. The application is fully containerized with Docker for seamless deployment. image

โœจ Features

  • ๐Ÿ—๏ธ Full-Stack Architecture: Flask REST API backend with React frontend
  • ๐Ÿ—„๏ธ MongoDB Database: NoSQL database for flexible data storage
  • โšก Custom CLI Tool: Command-line interface for managing the application
  • ๐Ÿณ Docker Support: Fully containerized with docker-compose
  • ๐Ÿ‘ค User Management: User registration and profile management
  • ๐Ÿฝ๏ธ Meal Tracking: Log and track daily meals and nutrition
  • โค๏ธ Health Monitoring: Track weight and water intake
  • ๐Ÿ’ป Modern UI: Responsive React frontend with component-based architecture
  • ๐Ÿ”— REST API: Comprehensive API endpoints for all features
  • ๐ŸŒฑ Database Seeding: Built-in script for populating test data
  • ๐Ÿงช AI-Powered Research: Intelligent ingredient and recipe discovery using OpenAI or Ollama
  • ๐Ÿ“ Letter-Based Research: Systematic research organized by alphabet for comprehensive coverage

๐Ÿ“ Project Structure

CalorIA/
โ”œโ”€โ”€ CalorIA/
โ”‚   โ”œโ”€โ”€ __init__.py              # Python package initialization
โ”‚   โ”œโ”€โ”€ cli.py                   # Custom CLI commands
โ”‚   โ”œโ”€โ”€ types.py                 # Type definitions
โ”‚   โ”œโ”€โ”€ research/                # AI-powered research system
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py         # Research package initialization
โ”‚   โ”‚   โ”œโ”€โ”€ tools.py            # Base research classes and utilities
โ”‚   โ”‚   โ”œโ”€โ”€ ingredients.py      # Ingredient research functionality
โ”‚   โ”‚   โ””โ”€โ”€ recipes.py          # Recipe research functionality
โ”‚   โ”œโ”€โ”€ backend/                 # Flask backend application
โ”‚   โ”‚   โ”œโ”€โ”€ app.py              # Main Flask application
โ”‚   โ”‚   โ”œโ”€โ”€ requirements.txt     # Python dependencies
โ”‚   โ”‚   โ””โ”€โ”€ package-lock.json
โ”‚   โ”œโ”€โ”€ frontend/               # React frontend application
โ”‚   โ”‚   โ”œโ”€โ”€ src/                # React source code
โ”‚   โ”‚   โ”œโ”€โ”€ public/             # Public assets
โ”‚   โ”‚   โ”œโ”€โ”€ package.json        # Node.js dependencies
โ”‚   โ”‚   โ””โ”€โ”€ build/              # Production build (generated)
โ”‚   โ””โ”€โ”€ mixins/                 # Shared modules and routes
โ”‚       โ”œโ”€โ”€ modules/            # Business logic modules
โ”‚       โ”‚   โ”œโ”€โ”€ activities.py   # Activity tracking functionality
โ”‚       โ”‚   โ”œโ”€โ”€ ingredients.py  # Ingredient management
โ”‚       โ”‚   โ”œโ”€โ”€ meals.py        # Meal tracking and management
โ”‚       โ”‚   โ”œโ”€โ”€ recipes.py      # Recipe management
โ”‚       โ”‚   โ”œโ”€โ”€ users.py        # User management
โ”‚       โ”‚   โ”œโ”€โ”€ water.py        # Water intake tracking
โ”‚       โ”‚   โ””โ”€โ”€ weight.py       # Weight tracking
โ”‚       โ”œโ”€โ”€ routes/             # API route handlers
โ”‚       โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚       โ”‚   โ”œโ”€โ”€ activity_routes.py # Activity endpoints
โ”‚       โ”‚   โ”œโ”€โ”€ auth_routes.py     # Authentication endpoints
โ”‚       โ”‚   โ”œโ”€โ”€ dashboard_routes.py # Dashboard data endpoints
โ”‚       โ”‚   โ”œโ”€โ”€ health_routes.py   # Health monitoring endpoints
โ”‚       โ”‚   โ”œโ”€โ”€ ingredient_routes.py # Ingredient CRUD endpoints
โ”‚       โ”‚   โ”œโ”€โ”€ meal_routes.py     # Meal tracking endpoints
โ”‚       โ”‚   โ”œโ”€โ”€ recipe_routes.py   # Recipe management endpoints
โ”‚       โ”‚   โ”œโ”€โ”€ user_routes.py     # User management endpoints
โ”‚       โ”‚   โ”œโ”€โ”€ water_routes.py    # Water intake endpoints
โ”‚       โ”‚   โ””โ”€โ”€ weight_routes.py   # Weight tracking endpoints
โ”‚       โ”œโ”€โ”€ jwt_utils.py         # JWT utilities
โ”‚       โ”œโ”€โ”€ mongo.py            # MongoDB connection utilities
โ”‚       โ””โ”€โ”€ tools.py            # General utilities
โ”œโ”€โ”€ docker-compose.yml          # Docker composition configuration
โ”œโ”€โ”€ Dockerfile                  # Docker image configuration
โ”œโ”€โ”€ setup.py                    # Python package setup
โ”œโ”€โ”€ .env.copy                   # Environment variables template
โ””โ”€โ”€ README.md                   # This file

๐Ÿš€ Local Development Setup

Prerequisites

Before running the application locally, ensure you have the following installed:

Environment Configuration

  1. Copy the environment template and configure your settings:

    cp .env.copy .env
    
  2. Edit the .env file with your configuration:

    MONGODB_URI=mongodb://localhost:27017/caloria
    FLASK_DEBUG=1
    SECRET_KEY=your-secret-key-here
    
    # AI Research Configuration (optional)
    AI_PROVIDER=openai  # or 'ollama'
    OPENAI_API_KEY=your_openai_api_key_here
    OPENAI_MODEL=gpt-4
    OLLAMA_BASE_URL=http://localhost:11434
    OLLAMA_MODEL=llama2
    

Installation Steps

  1. Clone the repository:

    git clone <repository-url>
    cd CalorIA
    
  2. Install Python dependencies:

    pip install -r CalorIA/backend/requirements.txt
    
  3. Install Node.js dependencies:

    cd CalorIA/frontend
    npm install
    cd ../..
    
  4. Install the CLI tool:

    pip install -e .
    
  5. Start MongoDB (if running locally):

    mongod
    
  6. Seed the database (optional):

    caloria seed
    

๐Ÿ’ป CLI Usage

The caloria CLI provides several commands to manage the application:

Available Commands

  • caloria backend - Start the Flask backend server

    caloria backend --host 127.0.0.1 --port 4032 --debug
    
    • --host: Host to bind to (default: 127.0.0.1)
    • --port: Port to bind to (default: 4032)
    • --debug: Run in debug mode
  • caloria frontend - Start the React development server

    caloria frontend --port 3000
    
    • --port: Port for development server (default: 3000)
  • caloria build - Build the React frontend for production

    caloria build --output-dir build
    
    • --output-dir: Output directory for build (default: build)
  • caloria seed - Seed the database with sample data

    caloria seed
    
  • caloria unseed - Remove all system-generated sample data from the database

    caloria unseed --confirm
    
    • --confirm: Confirm deletion without prompting
  • caloria research-ingredients - Research and add missing ingredients using AI

    caloria research-ingredients --category Vegetables --letters A,B,C --max-ingredients 10
    
    • --category: Specific category to research (Vegetables, Proteins, Fruits, etc.)
    • --letters: Comma-separated letters to research (e.g., "A,B,C")
    • --max-ingredients: Maximum number of ingredients to add
    • --dry-run: Show what would be added without actually adding
  • caloria research-recipes - Research and add missing recipes using AI

    caloria research-recipes --category breakfast --letters A,B,C --max-recipes 5
    
    • --category: Specific category to research (breakfast, lunch, dinner, etc.)
    • --letters: Comma-separated letters to research (e.g., "A,B,C")
    • --max-recipes: Maximum number of recipes to add
    • --dry-run: Show what would be added without actually adding

Example Usage

  1. Start the full application (recommended for development):

    # Terminal 1: Start the backend (includes building frontend)
    caloria backend --debug
    
    # Terminal 2: Start the frontend dev server (for hot reloading)
    caloria frontend
    
  2. Production build:

    caloria build
    caloria backend --host 0.0.0.0 --port 4032
    
  3. AI Research Examples:

    # Research vegetables starting with A, B, C
    caloria research-ingredients --category Vegetables --letters A,B,C --max-ingredients 15
    
    # Research breakfast recipes (dry run)
    caloria research-recipes --category breakfast --dry-run
    
    # Research proteins systematically
    caloria research-ingredients --category Proteins --max-ingredients 20
    

๐Ÿณ Docker Usage

Quick Start with Docker

  1. Build and run the entire application:

    docker-compose up --build
    
  2. Run in detached mode:

    docker-compose up -d --build
    
  3. Stop the application:

    docker-compose down
    
  4. View logs:

    docker-compose logs -f
    

Docker Services

The docker-compose configuration includes:

  • app: The main CalorIA application (Flask + React)
    • Exposed on port 4032
    • Automatically builds frontend and runs backend
  • mongo: MongoDB database
    • Exposed on port 27017
    • Data persisted in mongo-data volume

๐Ÿงช AI-Powered Research

CalorIA includes an intelligent AI-powered research system that can discover and add missing ingredients and recipes to your database. The system supports both OpenAI and Ollama as AI providers.

Research Features

  • Letter-Based Research: Systematically research ingredients/recipes by alphabet for comprehensive coverage
  • Category-Specific: Research specific categories like Vegetables, Proteins, Fruits, etc.
  • Duplicate Prevention: Automatically checks for existing items before adding
  • Dry Run Mode: Test research without modifying the database
  • Batch Processing: Process multiple items efficiently with progress tracking

AI Providers

OpenAI (Default)

  • Requires API key
  • Supports GPT-3.5-turbo and GPT-4 models
  • Higher quality responses
  • Requires internet connection

Ollama (Local)

  • Runs locally on your machine
  • Supports various open-source models (Llama, Mistral, etc.)
  • No API costs
  • Works offline

Research Categories

Ingredients:

  • Vegetables, Fruits, Proteins, Grains & Starches
  • Dairy, Oils & Fats, Nuts & Seeds
  • Condiments & Sauces, Sweeteners, Spices
  • Beverages, Supplements, Baking & Flours

Recipes:

  • Breakfast, Lunch, Dinner, Snacks
  • Desserts, Beverages, Appetizers
  • Soups, Salads, Main Courses, Side Dishes

Usage Examples

# Research vegetables starting with specific letters
caloria research-ingredients --category Vegetables --letters A,B,C,D,E

# Research breakfast recipes (systematic approach)
caloria research-recipes --category breakfast --max-recipes 10

# Dry run to see what would be added
caloria research-ingredients --category Proteins --dry-run

# Research with custom limits
caloria research-recipes --category dinner --max-recipes 5 --letters M,N,O

Setting Up AI Providers

For OpenAI:

  1. Get an API key from OpenAI
  2. Add to your .env file:
    AI_PROVIDER=openai
    OPENAI_API_KEY=your_api_key_here
    OPENAI_MODEL=gpt-4
    

For Ollama:

  1. Install Ollama from ollama.ai
  2. Pull a model: ollama pull llama2
  3. Add to your .env file:
    AI_PROVIDER=ollama
    OLLAMA_BASE_URL=http://localhost:11434
    OLLAMA_MODEL=llama2
    

๐ŸŒ API Endpoints

The CalorIA REST API provides the following endpoint categories:

Authentication

  • POST /api/auth/login - User login
  • POST /api/auth/register - User registration
  • POST /api/auth/logout - User logout

User Management

  • GET /api/user/<user_id> - Get user information
  • POST /api/user - Create new user
  • PUT /api/user/<user_id> - Update user information
  • DELETE /api/user/<user_id> - Delete user

Ingredients

  • GET /api/ingredients - Get all ingredients (with pagination and search)
    • Query parameters: page, limit, search, is_system
  • GET /api/ingredients/<ingredient_id> - Get specific ingredient
  • POST /api/ingredients - Create new ingredient
  • PUT /api/ingredients/<ingredient_id> - Update ingredient
  • DELETE /api/ingredients/<ingredient_id> - Delete ingredient

Recipes

  • GET /api/recipes - Get all recipes (with pagination and search)
  • GET /api/recipes/<recipe_id> - Get specific recipe
  • POST /api/recipes - Create new recipe
  • PUT /api/recipes/<recipe_id> - Update recipe
  • DELETE /api/recipes/<recipe_id> - Delete recipe

Meal Tracking

  • GET /api/meals/<user_id> - Get user's meals
  • POST /api/meals - Log a new meal
  • PUT /api/meals/<meal_id> - Update meal information
  • DELETE /api/meals/<meal_id> - Delete meal

Health Monitoring

  • GET /api/health/<user_id> - Get health status
  • POST /api/health - Update health metrics

Weight Tracking

  • GET /api/weight/<user_id> - Get weight history
  • POST /api/weight - Log weight entry
  • PUT /api/weight/<entry_id> - Update weight entry
  • DELETE /api/weight/<entry_id> - Delete weight entry

Water Intake

  • GET /api/water/<user_id> - Get water intake history
  • POST /api/water - Log water intake
  • PUT /api/water/<entry_id> - Update water entry
  • DELETE /api/water/<entry_id> - Delete water entry

Dashboard

  • GET /api/dashboard/<user_id> - Get user dashboard data

Development

Project Architecture

  • Backend: Flask application with Blueprint-based routing
  • Frontend: React application with component-based architecture
  • Database: MongoDB with PyMongo driver
  • CLI: Click-based command-line interface
  • Containerization: Docker with multi-stage builds

Key Technologies

  • Backend: Flask, PyMongo, Click
  • Frontend: React, Node.js, npm
  • Database: MongoDB
  • DevOps: Docker, docker-compose
  • Python: 3.7+ compatible

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes and test them
  4. Commit your changes: git commit -m 'Add feature'
  5. Push to the branch: git push origin feature-name
  6. Submit a pull request

Screenshots

Screenshot 2025-08-30 033434 Screenshot 2025-08-30 033509 image

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

caloria-1.0.0.tar.gz (88.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

caloria-1.0.0-py3-none-any.whl (116.6 kB view details)

Uploaded Python 3

File details

Details for the file caloria-1.0.0.tar.gz.

File metadata

  • Download URL: caloria-1.0.0.tar.gz
  • Upload date:
  • Size: 88.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for caloria-1.0.0.tar.gz
Algorithm Hash digest
SHA256 84bd7d5f92e419141706b65c2590593f32a86f2e76af1d0ff6a0af486f359b5d
MD5 378bd96dac416021f12eb1b0cfca68dd
BLAKE2b-256 5226d6352997b9a01da77a24cfde8b6d341065492ba0fbde48ed759586744a78

See more details on using hashes here.

File details

Details for the file caloria-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: caloria-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 116.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for caloria-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5a5e6c930faef65b9c61cbb707786d1917a5a31f0c692b543fba454060d35b0
MD5 2a86f26114f7e070ee8de7ddd2e0cf1a
BLAKE2b-256 8212c2b6e08ebf4c5e549cecacf70cd0f61a773eb9de901f7a8a12702d28010d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page