Inventory Management API
I built this project as a backend learning project for managing inventory items through a Flask REST API. It started as a small single-file CRUD application and gradually became a deployed service with MySQL, authentication, protected routes, and role-based authorization.
The current release is v1.4.0. The live API is hosted on Render and uses a MySQL database hosted on alwaysdata.
How the Project Evolved
I developed the project in stages so that each change solved a clear problem in the previous version.
v0.1.0: A single-file Flask CRUD API using in-memory storage.v0.2.0: A layered structure separating routes, business logic, and storage.v0.3.0: MySQL integration for persistent data.v1.0.0: JWT authentication and protected inventory routes.v1.1.0: Deployment configuration and improved documentation.v1.2.0: Admin and staff roles with different permissions.v1.3.0: Docker support and CORS configuration.v1.4.0: Docker Compose support and container startup health checks.
Building the Inventory API
The main inventory features are create, read, update, and delete operations. Items can be retrieved individually or as a collection, and updates support changing only the fields that need to change.
I added a rule that an item can only be deleted when its quantity is zero. This keeps the API from removing an item while the system still considers it part of the available inventory.
The API validates values such as item names and quantities before sending them to the database. Invalid input returns an appropriate error response instead of being allowed to reach the storage layer.
Separating the Backend into Layers
The first version placed the application logic in one file. That was useful for getting the basic API working, but it became harder to maintain as database access and authentication were added.
I separated the application into a routes layer, a service layer, and a storage layer. Routes handle HTTP requests and responses, services contain the main rules of the application, and storage handles MySQL operations. Authentication has its own module for signup, login, JWT creation, and route protection.
This structure makes it easier to change one part of the application without placing all of the logic in the route handlers.
Authentication and Password Security
I added signup and login so that inventory routes would not be openly accessible. When a user signs up, the password is hashed with bcrypt before it is stored. The original password is never stored in the database.
After a successful login, the server creates a JWT. The client sends that token in the Authorization: Bearer header when calling a protected route. The API checks the token before allowing the request to continue.
The current implementation does not yet add an expiration time to JWT tokens. I documented this as a limitation so it is clear what should be improved in a future version.
Adding Role-Based Permissions
Authentication answers who is making a request, but it does not by itself decide what that user is allowed to do. I therefore added two roles: admin and staff.
New users receive the staff role by default. Both roles can view and update inventory, while only administrators can create or delete items. The API returns 401 Unauthorized when the token is missing or invalid and 403 Forbidden when the user is authenticated but does not have permission for the operation.
Database and Configuration Decisions
I moved from in-memory storage to MySQL because inventory data should remain available after the application restarts. The database schema is kept in schema.sql, which can be run against a local or hosted MySQL database.
Database credentials and secret keys are loaded through environment variables rather than being written into the source code. The.env.example file documents the required settings without containing real credentials.
Docker and Deployment
I added a Dockerfile so the API can run in a consistent environment with Gunicorn. Docker Compose provides a local setup with separate API and MySQL services, while the API uses DB_HOST=mysql to connect to the database service.
For deployment, I configured Flask to run with Gunicorn and moved the sensitive settings into Render's environment configuration. The deployed service uses the Render-provided port and connects to the hosted MySQL database using the same environment-based configuration.
The live API is hosted on Render's free tier, so its first request after a period of inactivity may take some time while the service starts.
What I Learned
This project helped me understand how a backend application grows from a simple working prototype into a more complete service. I practiced separating responsibilities, storing data in a real database, protecting routes, handling permissions, validating input, and preparing an application for deployment.
Technology Stack
Python 3.12, Flask, MySQL, mysql-connector-python, bcrypt, PyJWT, Docker, Docker Compose, Gunicorn, Render, Git, and GitHub.