ConvertX is a production-style unit conversion web application built with FastAPI, Jinja2, HTMX, SQLAlchemy, and SQLite.
It is designed as a Python-first server-rendered application that provides fast, accurate unit conversions across multiple categories, while also supporting conversion history, favorites, settings, reusable conversion logic, and dynamic partial updates.
This project demonstrates how to build a clean, modular backend-driven web app with FastAPI + Jinja2 instead of relying on a heavy frontend framework.
-
15 conversion categories:
- Length
- Weight / Mass
- Temperature
- Area
- Volume
- Time
- Speed
- Data Storage
- Pressure
- Energy
- Power
- Angle
- Frequency
- Fuel Economy
- Digital Transfer Rate
-
Interactive converter workspace
- category selection
- value input
- from-unit and to-unit selection
- precision control
- swap support
- result rendering with partial updates
-
HTMX-powered dynamic UI
- updates result cards without full page reload
- refreshes unit selectors dynamically based on category
-
Persistent history
- stores successful conversions in SQLite
- enables recent conversion tracking
-
Favorites system
- save frequently used unit pairs
- quickly access commonly repeated conversions
-
Settings support
- configurable app behavior such as precision and history preferences
-
Modular conversion engine
- dedicated converter modules for each category
- clean registry-based converter resolution
- easy to extend with new categories and units
-
Server-rendered architecture
- FastAPI for routing and application logic
- Jinja2 templates for pages and partials
- SQLAlchemy ORM for persistence
-
Testing support
- Pytest-based testing for conversion logic and routes
- Python 3.12+
- FastAPI
- Pydantic v2
- SQLAlchemy 2.x
- SQLite
- Jinja2
- HTMX
- Tailwind CSS
- Pytest
ConvertX follows a layered backend architecture to keep the codebase modular, maintainable, and easy to extend.
FastAPI routers handle HTTP endpoints and request/response flow.
Examples:
- page routes
- converter routes
- favorites routes
- history routes
- settings routes
The service layer contains business logic such as:
- performing conversions
- recording history
- checking / toggling favorites
- reading and updating settings
Each conversion category is implemented in its own converter module.
This keeps the conversion logic isolated and reusable.
Database operations are handled through SQLAlchemy-backed models and persistence logic.
Jinja2 templates render:
- full pages
- reusable HTML partials
- HTMX responses for dynamic UI updates
| Category | Description |
|---|---|
| Length | Distance and size conversions |
| Weight / Mass | Metric and imperial mass conversions |
| Temperature | Celsius, Fahrenheit, Kelvin conversions |
| Area | Surface measurement conversions |
| Volume | Liquid and space volume conversions |
| Time | Time unit conversions |
| Speed | Velocity conversions |
| Data Storage | Bytes, KB, MB, GB, TB, etc. |
| Pressure | Pressure measurement conversions |
| Energy | Joules, calories, kWh, etc. |
| Power | Watts, kilowatts, horsepower, etc. |
| Angle | Degree and radian conversions |
| Frequency | Hz, kHz, MHz, GHz conversions |
| Fuel Economy | Mileage and fuel consumption conversions |
| Digital Transfer Rate | bps, Kbps, Mbps, Gbps, etc. |
ConvertX/
│
├── app/
│ ├── main.py
│ ├── config.py
│ ├── dependencies.py
│ │
│ ├── core/
│ │ ├── enums.py
│ │ ├── exceptions.py
│ │ └── utils.py
│ │
│ ├── converters/
│ │ ├── base.py
│ │ ├── registry.py
│ │ ├── length.py
│ │ ├── weight.py
│ │ ├── temperature.py
│ │ └── ...
│ │
│ ├── db/
│ │ ├── session.py
│ │ └── models/
│ │
│ ├── repositories/
│ ├── schemas/
│ ├── services/
│ │
│ ├── routers/
│ │ ├── converter.py
│ │ ├── favorites.py
│ │ ├── history.py
│ │ ├── pages.py
│ │ └── settings.py
│ │
│ ├── templates/
│ │ ├── base templates
│ │ ├── pages
│ │ └── partials
│ │
│ └── static/
│
├── tests/
├── requirements.txt
├── README.md
└── .gitignore
- The user enters a value, category, and unit pair in the converter form.
- The request is sent to a FastAPI route.
- The route validates the input and identifies the selected conversion category.
- The
ConversionServicecalls the correct converter via the converter registry. - The conversion result is generated.
- If history is enabled, the conversion is stored in the database.
- Favorite status is checked for the selected unit pair.
- A Jinja2 partial (such as a result card) is rendered and returned.
- HTMX updates only the relevant part of the page without a full reload.
ConvertX is more than a basic calculator project. It demonstrates practical backend engineering skills and clean software design, including:
- building APIs and web routes with FastAPI
- structuring a Python project with routers, services, repositories, and domain modules
- implementing reusable business logic for multiple conversion domains
- rendering server-side templates with Jinja2
- using HTMX for interactive partial page updates
- persisting application data with SQLAlchemy and SQLite
- managing settings, history, and favorites in a maintainable way
- designing a project that can later scale to PostgreSQL or deployment environments
git clone https://github.com/<your-username>/convertx-smart-unit-converter.git
cd convertx-smart-unit-converterpython -m venv .venv
.venv\Scripts\Activate.ps1python -m venv .venv
.venv\Scripts\activate.batpython -m venv .venv
source .venv/bin/activatepip install -r requirements.txtuvicorn app.main:app --reloadhttp://127.0.0.1:8000
Run the test suite with:
pytest -qFor verbose output:
pytest -vBy default, ConvertX uses SQLite for local development.
The project is structured so it can be migrated to PostgreSQL later with minimal architectural changes if the database URL and driver are updated appropriately.
Example PostgreSQL connection string:
CONVERTX_DATABASE_URL=postgresql+psycopg://user:password@localhost/convertxInstall PostgreSQL driver if needed:
pip install "psycopg[binary]"ConvertX can be used for:
- metric ↔ imperial conversions
- engineering and scientific unit conversions
- data storage and transfer-rate calculations
- fuel economy comparison
- everyday measurement conversion workflows
- learning and experimenting with structured conversion logic
Possible future enhancements include:
- user authentication and account-based preferences
- exportable conversion history
- REST API endpoints for external programmatic usage
- Dockerized deployment setup
- PostgreSQL production configuration
- search and fuzzy matching for units
- usage analytics dashboard
- advanced presets and saved conversion profiles
- internationalization / multi-language support
This repository is a Python-first FastAPI application.
The main local development command is:
uvicorn app.main:app --reloadThis project is not intended to be run as a standalone Vite/TanStack frontend app.
If older experimental frontend files exist from a previous setup, they are not part of the final ConvertX architecture and should not be treated as the main runtime for this project.
ConvertX — Smart Unit Converter
Built a production-style unit conversion web application using FastAPI, Jinja2, HTMX, SQLAlchemy, and SQLite. Implemented a modular conversion engine supporting 15 unit categories, dynamic partial rendering, persistent history and favorites, configurable settings, and a layered backend architecture with routers, services, repositories, and reusable converter modules.
This project is licensed under the MIT License.





