Project: Simple product-tracking demo using FastAPI (backend) and a React frontend.
Deployments:
-
Backend https://fastapi-inventory-management-system.onrender.com
-
Frontend https://fastapi-inventory-management-system-1.onrender.com/
Note: Free PostgreSQL resets monthly on Render.
If backend is inactive, ping the app or recreate DB before testing.
Project snapshots:
Purpose: Demonstrates a small CRUD API backed by SQLAlchemy and a create-react-app frontend that talks to the API.
Prerequisites:
- Python 3.10+ (project uses a local venv at
myFastAPienv). - Node.js and npm (for the frontend).
Quick Start (Backend)
- Create and activate the virtual environment (optional if
myFastAPienvalready exists):
python3 -m venv myFastAPienv
source myFastAPienv/bin/activate
- Install Python dependencies (FastAPI, Uvicorn, SQLAlchemy, DB driver):
pip install fastapi uvicorn sqlalchemy psycopg2
- Run the backend development server:
uvicorn main:app --reload
- Open the FastAPI interactive docs at:
http://127.0.0.1:8000/docs
Notes:
- The backend code is in
main.py. It defines CRUD endpoints forProductobjects and uses SQLAlchemy models defined underdatabase_models.pytogether with session helpers indatabase.py. - On first run the code will create tables and initialize a few sample products if the database is empty.
Quick Start (Frontend)
- Change to the frontend directory and install packages:
cd frontend
npm install
- Start the frontend (create-react-app):
npm start
- The frontend expects the backend at
http://localhost:8000(seefrontend/package.json->proxy). The React app runs by default athttp://localhost:3000.
Repository Structure
main.py: FastAPI application with routes and DB initialization.database.py: SQLAlchemy session / engine helpers.database_models.py: SQLAlchemy ORM models andBasemetadata.models.py: Pydantic models used by FastAPI request/response validation.frontend/: React app (create-react-app).setup.txt: Quick setup notes and useful commands.myFastAPienv/: Optional local Python virtual environment (not checked in normally).
API Endpoints (summary from main.py)
GET /— health check returns a welcome string.GET /products— list all products.GET /products/{id}— get product by id.POST /products— add a new product (accepts the PydanticProductmodel payload).PUT /products/{id}— update an existing product.DELETE /products/{id}— delete a product by id.
Use the interactive docs at http://127.0.0.1:8000/docs to explore and test these endpoints.
Database
- The project uses SQLAlchemy. The default DB connection is configured in
database.py— by default that file may use SQLite or another engine depending on your configuration. If you're using PostgreSQL, installpsycopg2and set the correct connection URL indatabase.py. - On first run, tables are created automatically via
database_models.Base.metadata.create_all(bind=engine).
Developer Notes
- The project includes a helper
get_db()(dependency injection) to provide a DBSessionto route handlers and ensure sessions are closed automatically. - Sample data is inserted automatically if the products table is empty (see
init_db()inmain.py).

