- Project Structure
- Endpoints
- Development
- Update API Spec & Collections
- Render Deployment
- Architecture
Python backend using Flask, pytest, Flasgger, and auto-generated OpenAPI spec.
src/app.py
→ Application entrypointsrc/app_routes.py
→ Central router (includes all controllers, no prefixes)src/controllers/
→ Request handlersuser_controller.py
(CRUD endpoints:/users
,/users/create
,/users/update/{id}
,/users/delete/{id}
)health_controller.py
(/healthcheck
)
src/services/
→ Business logic (user_service.py
)src/validators/
→ Input validatorstest/
→ Pytest tests (100% coverage for updated endpoints)scripts/
→ Automation scripts (API spec + collections)docs/
→ API spec + generated collections
-
GET
/healthcheck
- Returns:
{ "message": "Shankar Python Backend Application is Up and Running successfully" }
- Returns:
-
GET
/users
- Returns:
[]
- Returns:
-
POST
/users/create
- Returns:
{ "message": "User created successfully" }
- Returns:
-
PUT
/users/update/{id}
- Returns:
{ "message": "User {id} updated successfully" }
- Returns:
-
DELETE
/users/delete/{id}
- Returns:
{ "message": "User {id} deleted successfully" }
- Returns:
pip install -r requirements-test.txt .
- Run All Tests
pytest -v
- Run Failed Tests
pytest --last-failed
These commands create coverage reports in HTML showing covered/uncovered lines.
Coverage will also be displayed in the terminal.
- For All Files:
pytest --cov=src --cov-report=term-missing --cov-report=html --cov-report=annotate:coverage/annotate
- For Individual File:
pytest --cov=`File-Path` --cov-report=term-missing --cov-report=html:coverage/html --cov-report=annotate:coverage/annotate
python -m flake8 src test
python -m src/app.py
Whenever you add or modify an endpoint, regenerate spec & collections:
python scripts/generate_apispec.py
python scripts/update_collections.py
This updates:
docs/api_spec.yaml
docs/postman_collection.json
docs/python-backend.bru
This application is deployed on Render with the following environments:
Environment | URL | APP_ENV |
---|---|---|
Production | https://python-backend-prod.onrender.com | production |
Engineering | https://python-backend-eng.onrender.com | eng |
Each service runs the same codebase with different
APP_ENV
values.
Currently we are having only two controllers as showm in the image below (Repository Architecture). In future, will have many more.