A modern REST API application built with FastAPI.
- FastAPI framework for high performance
- Automatic API documentation (Swagger UI)
- Request/response validation with Pydantic
- CORS middleware enabled
- RESTful endpoints for CRUD operations
- Health check endpoint
Run the application using uvicorn:
uvicorn main:app --reloadOr run directly:
python main.pyThe API will be available at:
- UI: http://localhost:8000
- API base: http://localhost:8000/api
- Health: http://localhost:8000/api/health
- Interactive API Docs (Swagger): http://localhost:8000/docs
- Alternative API Docs (ReDoc): http://localhost:8000/redoc
This project includes a Dockerfile that builds a single container for the FastAPI backend (serving both the API and the HTML UI).
From the project root:
docker build -t python-app .The application expects a MySQL database. When running with plain Docker you must point it to an existing MySQL instance by setting environment variables:
docker run -d -p 8000:8000 ^
-e DB_HOST=your-mysql-host ^
-e DB_PORT=3306 ^
-e DB_USER=app_user ^
-e DB_PASSWORD=app_password ^
-e DB_NAME=app_db ^
--name python-app python-appThen open:
- UI: http://localhost:8000
- API base: http://localhost:8000/api
For local development, use docker-compose.yml (named Docker-Compose.yml in this project) to start both the FastAPI app and a MySQL database.
From the project root:
docker compose up --buildThis will:
- Start a MySQL 8 container with:
MYSQL_DATABASE=app_dbMYSQL_USER=app_userMYSQL_PASSWORD=app_password
- Build and start the
pyhton-appservice (FastAPI + UI) with matching environment variables:DB_HOST=mysqlDB_PORT=3306DB_USER=app_userDB_PASSWORD=app_passwordDB_NAME=app_db
- Ensure the app waits for MySQL to be healthy before starting (via
depends_on+ healthcheck).
- UI dashboard: http://localhost:8000
- API base: http://localhost:8000/api
- Health check: http://localhost:8000/api/health
- Swagger docs: http://localhost:8000/docs
GET /- API informationGET /health- Health check
GET /items- Get all itemsGET /items/{item_id}- Get item by IDPOST /items- Create new itemPUT /items/{item_id}- Update itemDELETE /items/{item_id}- Delete item
curl -X POST "http://localhost:8000/items" \
-H "Content-Type: application/json" \
-d '{"name": "Laptop", "description": "Gaming laptop", "price": 1299.99}'curl "http://localhost:8000/items"curl "http://localhost:8000/items/1"curl -X PUT "http://localhost:8000/items/1" \
-H "Content-Type: application/json" \
-d '{"name": "Updated Laptop", "description": "Updated description", "price": 1199.99}'curl -X DELETE "http://localhost:8000/items/1".
├── main.py # FastAPI entry point (re-exports backend.app)
├── backend/ # Backend package (API, DB models, config)
├── ui/ # HTML5/CSS/JS single-page UI
├── requirements.txt # Python dependencies
├── Dockerfile # Image for FastAPI app
├── Docker-Compose.yml # Docker Compose stack (MySQL + app)
├── README.md # Project documentation
└── .gitignore # Git ignore file
- Add database integration (SQLAlchemy, MongoDB, etc.)
- Add authentication and authorization
- Add request logging
- Add unit tests
- Add environment configuration
- Deploy to production (Docker, cloud services, etc.)