A full-stack web application designed to track Body Mass Index (BMI) over time. Unlike simple static calculators, this project leverages FastAPI for a high-performance backend and SQLite for data persistence, allowing users to store and analyze their history log.
Key Technologies: Python, FastAPI, SQLite, HTML/Bootstrap.
- Persistent History Tracking:
- Utilizes a SQLite database to store user records permanently.
- Performs backend calculations to analyze weight trends and percentage changes compared to previous entries.
The application features:
- BMI Calculation: Users input their weight and height, and the app calculates their BMI and categorizes it.
- History: Users can view their BMI calculation history, including the percentage change in BMI from previous records.
- CORS-enabled: The app allows communication between the frontend and backend even when hosted on different origins, thanks to FastAPI’s CORS middleware.
- app.py: This is the FastAPI backend. It handles the POST request to calculate BMI and the GET request to retrieve the BMI history.
- index.html: This HTML file contains the frontend interface for the user to input their weight and height, see BMI calculations, and view the history.
- requirements.txt: Lists the Python dependencies required for the project.
-
BMI Calculation:
- The app calculates BMI using the formula:
[ \text{BMI} = \frac{\text{weight (kg)}}{\text{height (m)}^2} ] - It classifies BMI into categories (Underweight, Normal, Overweight, Obese).
- The app calculates BMI using the formula:
-
History Feature:
- Users can track their previous BMI calculations along with the percentage change between them.
- The app saves BMI history in an SQLite database.
-
Responsive Design:
- The app uses Bootstrap to make the frontend responsive and user-friendly across different devices.
- Clone the repository:
git clone https://github.com/A-Najjar/FastAPI-BMI-App.git cd bmi_calculator - Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`- Install dependencies:
pip install -r requirements.txt
- Run the FastAPI application:
uvicorn app:app --reload
you can add /docs to the url to get to the swaggar ui
-
Access the frontend:
- Open the
index.htmlfile in your browser, or serve it using a local HTTP server (e.g.,python -m http.server).
- Open the
-
Test the application:
- Enter your weight and height on the frontend.
- Click "Calculate BMI" to get your BMI result.
- Click "Load History" to view your previous BMI records.