3.5 KiB
3.5 KiB
Calories Calculator API
A FastAPI-based API for tracking calories and nutritional information. This application allows users to register, track their food intake, and calculate their recommended calorie intake based on personal metrics.
Features
- User registration and authentication
- Food database management
- Calorie tracking by meal type
- Daily and weekly calorie summaries
- BMR (Basal Metabolic Rate) and TDEE (Total Daily Energy Expenditure) calculations
- Personalized calorie recommendations based on goals
Getting Started
Prerequisites
- Python 3.8+
- SQLite
Installation
- Clone the repository:
git clone <repository-url>
cd caloriescalculatorapi
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000.
API Documentation
Once the application is running, you can access the interactive API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Authentication
POST /api/v1/auth/register
- Register a new userPOST /api/v1/auth/login
- Login and get access tokenPOST /api/v1/auth/test-token
- Test if the token is valid
Users
GET /api/v1/users/me
- Get current user dataPUT /api/v1/users/me
- Update current user data
Foods
GET /api/v1/foods
- List food itemsPOST /api/v1/foods
- Create a new food itemGET /api/v1/foods/{food_id}
- Get a specific food itemPUT /api/v1/foods/{food_id}
- Update a food itemDELETE /api/v1/foods/{food_id}
- Delete a food itemGET /api/v1/foods/my-foods
- List food items created by the current user
Calorie Entries
GET /api/v1/calorie-entries
- List calorie entriesPOST /api/v1/calorie-entries
- Create a new calorie entryGET /api/v1/calorie-entries/{entry_id}
- Get a specific calorie entryPUT /api/v1/calorie-entries/{entry_id}
- Update a calorie entryDELETE /api/v1/calorie-entries/{entry_id}
- Delete a calorie entryGET /api/v1/calorie-entries/daily-summary
- Get daily calorie summaryGET /api/v1/calorie-entries/weekly-summary
- Get weekly calorie summary
Calculator
POST /api/v1/calculator/calculate
- Calculate recommended caloriesGET /api/v1/calculator/calculate-from-profile
- Calculate recommended calories based on user profile
Project Structure
app/
├── api/ # API endpoints
│ └── v1/
│ ├── endpoints/ # API route handlers
│ └── api.py # API router configuration
├── core/ # Core functionality
│ ├── config.py # Application configuration
│ ├── deps.py # Dependencies
│ └── security.py # Security utilities
├── db/ # Database configuration
│ ├── base.py # SQLAlchemy Base class
│ └── session.py # Database session setup
├── models/ # SQLAlchemy models
├── schemas/ # Pydantic schemas
├── services/ # Business logic
└── utils/ # Utility functions
migrations/ # Alembic migrations
main.py # Application entry point
Development
Running Tests
pytest
Running Linters
ruff check .
License
This project is licensed under the MIT License.