A FastAPI application that generates personalized workout and diet plans based on user fitness goals.
The Fitness Planner API is a REST service built with Python and FastAPI that provides:
- BMI calculations and health metrics
- Personalized calorie and macro nutrient recommendations
- Custom workout plans based on goals and equipment availability
- Daily meal plans tailored to dietary preferences
- Complete fitness planning in a single API call
Technology Stack:
- Backend: Python 3.11 with FastAPI
- Testing: pytest with coverage reporting
- Containerization: Docker
- CI/CD: CloudBees Unify with Kaniko
- Install dependencies:
pip install -r requirements.txt- Run the application:
uvicorn app.main:app --reload- Access API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
pytest tests/ -vdocker build -t fitness-planner .
docker run -p 8000:8000 fitness-plannerGET /- API information and available endpointsGET /health- Health check
POST /calculate/bmi- Calculate Body Mass IndexPOST /calculate/calories- Calculate BMR, TDEE, and target caloriesPOST /calculate/macros- Calculate protein/carbs/fat splits
POST /generate/workout- Generate weekly workout planPOST /generate/meal-plan- Generate daily meal planPOST /generate/complete-plan- Generate complete fitness plan (all-in-one)
import requests
profile = {
"age": 30,
"weight": 75, # kg
"height": 180, # cm
"gender": "male",
"activity_level": "moderate",
"goal": "gain_muscle",
"diet_preference": "high_protein",
"equipment": "gym"
}
response = requests.post(
"http://localhost:8000/generate/complete-plan",
json=profile
)
plan = response.json()This project uses CloudBees Unify for continuous integration and deployment with a complete automated pipeline.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CI/CD Pipeline β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Trigger (Push to main/develop OR Manual) β
β β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β JOB 1: TEST β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β 1. Checkout code β β
β β 2. Install dependencies & run pytest β β
β β 3. Publish test results (JUNIT) β β
β β 4. Extract test summary β β
β β 5. Publish test evidence (component) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β (only if tests pass) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β JOB 2: BUILD β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β Calls: build-reusable.yml β β
β β 1. Checkout code β β
β β 2. Configure Docker Hub credentials β β
β β 3. Build image with Kaniko β β
β β 4. Push to Docker Hub (SHA + latest tags) β β
β β 5. Publish build evidence β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Purpose: Orchestrates the entire CI/CD process
Triggers:
- Automatic: Push to
mainordevelopbranches - Manual: workflow_dispatch (can be triggered manually from UI)
Jobs:
Runs comprehensive testing and publishes results:
Steps:
- Checkout code - Uses
cloudbees-io/checkout@v1 - Install & Test - Runs in Python 3.11 Docker container:
pip install -r requirements.txt pytest tests/ -v --junitxml=test-results.xml --cov=app
- Publish Test Results - Uses
cloudbees-io/publish-test-results@v2- Format: JUNIT XML
- Creates test dashboard in CloudBees UI
- Extract Test Summary - Parses test-results.xml to extract:
- Total test cases
- Passed tests
- Failed tests
- Publish Test Evidence - Calls custom component
- Uses:
./.cloudbees/components/publish-test-evidence - Creates audit trail with test metrics, run ID, commit SHA
- Uses:
Builds and pushes Docker image (runs only after test success):
Steps:
- Calls Reusable Workflow -
./.cloudbees/workflows/build-reusable.yml - Passes Inputs:
image-name: fitness-plannerdockerfile-path: ./Dockerfilecontext: .
- Passes Secrets:
DOCKERHUB_USERNAMEDOCKERHUB_TOKEN
Purpose: Reusable workflow for building and pushing Docker images with Kaniko
Trigger: workflow_call (called by other workflows)
Inputs:
image-name(required) - Name of the Docker imagedockerfile-path(optional, default:./Dockerfile)context(optional, default:.)
Secrets:
DOCKERHUB_USERNAME(required)DOCKERHUB_TOKEN(required)
Steps:
- Checkout code -
cloudbees-io/checkout@v1 - Configure Docker Hub credentials -
cloudbees-io/configure-oci-credentials@v1- Registry:
docker.io - Authenticates with Docker Hub
- Registry:
- Build & Push with Kaniko -
cloudbees-io/kaniko@v1- Why Kaniko? Builds images without Docker daemon (more secure)
- Tags created:
docker.io/<username>/<image>:<commit-sha>(specific version)docker.io/<username>/<image>:latest(latest version)
- Publish Build Evidence - Documents:
- Run ID, branch, commit SHA
- Docker image location
- Build status
Purpose: Reusable component for publishing test execution evidence
Type: Custom CloudBees Unify component (kind: action)
Inputs:
total-tests- Total number of test casespassed-tests- Number of passed testsfailed-tests- Number of failed tests
What it does:
- Creates a formatted Markdown evidence document
- Publishes using
cloudbees-io/publish-evidence-item@v1 - Includes:
- Test summary (total/passed/failed)
- Workflow metadata (run ID, branch, commit)
- Test details (framework, type, results file)
Why use a component?
- Eliminates code duplication
- Evidence format defined in ONE place
- Reusable across multiple workflows
- Easy to maintain and update
- Action:
cloudbees-io/publish-test-results@v2 - Format: JUNIT XML
- Purpose: Displays detailed test execution in CloudBees UI
- Shows: Individual test names, pass/fail status, execution times
- Action:
cloudbees-io/publish-evidence-item@v1(via component) - Format: Markdown document
- Purpose: Compliance, audit trail, traceability
- Shows: Summary metrics, workflow info, test metadata
- Why Kaniko?
- No Docker daemon required (runs in userspace)
- More secure for CI/CD pipelines
- Works in containerized environments
- Multi-tag Strategy:
- SHA tag for version tracking
- Latest tag for convenience
- Reusable Workflow:
build-reusable.ymlcan be called from any workflow - Custom Component:
publish-test-evidencecan be used in any job - No Code Duplication: Logic defined once, used everywhere
- Build job only runs if tests pass
- Failed tests block deployment
- Test results and evidence published for every run
Add these secrets in CloudBees Unify platform:
-
DOCKERHUB_USERNAME
- Your Docker Hub username
- Used for authentication
-
DOCKERHUB_TOKEN
- Docker Hub access token (NOT password)
- Create at: Docker Hub β Account Settings β Security β New Access Token
The workflows require these CloudBees permissions:
permissions:
scm-token-own: read
scm-token-org: read
id-token: readfitness-planner/
βββ .cloudbees/
β βββ components/
β β βββ publish-test-evidence/
β β βββ action.yml # Custom evidence component
β βββ workflows/
β βββ ci.yml # Main CI workflow
β βββ build-reusable.yml # Reusable build workflow
βββ app/
β βββ main.py # FastAPI application
β βββ models.py # Pydantic models
β βββ calculators.py # BMI, calorie, macro calculators
β βββ workout_engine.py # Workout plan generation
β βββ diet_engine.py # Meal plan generation
βββ tests/
β βββ test_api.py # API endpoint tests
β βββ test_calculators.py # Calculator tests
β βββ test_workout_engine.py # Workout generation tests
β βββ test_diet_engine.py # Diet plan tests
βββ Dockerfile # Container definition
βββ requirements.txt # Python dependencies
βββ README.md # This file
- Developer pushes code to main or develop branch
- CloudBees Unify detects push and triggers ci.yml workflow
- Test Job starts:
- Code is checked out
- Python dependencies installed
- pytest runs all tests with coverage
- Test results published to CloudBees UI
- Test summary extracted (total/passed/failed)
- Evidence component called to publish audit trail
- Test Job completes - If successful, build job starts
- Build Job starts:
- Calls build-reusable.yml workflow
- Code checked out again
- Docker Hub credentials configured
- Kaniko builds Docker image
- Image pushed with two tags (commit SHA + latest)
- Build evidence published
- Pipeline completes - Both test and build evidence available in CloudBees
You can manually trigger the workflow from CloudBees Unify UI:
- Navigate to the repository in CloudBees Unify
- Go to Workflows
- Select "CI Workflow"
- Click "Run Workflow"
- Choose the branch to run against
lose_weight- 500 calorie deficitgain_muscle- 300 calorie surplusmaintain- Maintenance caloriesimprove_endurance- Slight surplus for training
balanced- Well-rounded nutritionvegetarian- No meatvegan- Plant-based onlyketo- Low-carb, high-fathigh_protein- Protein-focused
bodyweight- No equipment neededhome- Dumbbells and basic equipmentgym- Full gym access
# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=app --cov-report=html
# Run specific test file
pytest tests/test_api.py -v- app/main.py - FastAPI app initialization and endpoint definitions
- app/models.py - Pydantic models for request/response validation
- app/calculators.py - BMI, BMR, TDEE, calorie, macro calculations
- app/workout_engine.py - Workout plan generation logic
- app/diet_engine.py - Meal plan generation logic
This project is for demonstration purposes.