Skip to content

SR091928/python-backend

Repository files navigation

Python Backend

Python Flask License CI Render

Table of Contents

Python backend using Flask, pytest, Flasgger, and auto-generated OpenAPI spec.

Project Structure

  • src/app.py → Application entrypoint
  • src/app_routes.py → Central router (includes all controllers, no prefixes)
  • src/controllers/ → Request handlers
    • user_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 validators
  • test/ → Pytest tests (100% coverage for updated endpoints)
  • scripts/ → Automation scripts (API spec + collections)
  • docs/ → API spec + generated collections

Endpoints

  • GET /healthcheck

    • Returns:
      {
        "message": "Shankar Python Backend Application is Up and Running successfully"
      }
  • GET /users

    • Returns:
      []
  • POST /users/create

    • Returns:
      {
        "message": "User created successfully"
      }
  • PUT /users/update/{id}

    • Returns:
      {
        "message": "User {id} updated successfully"
      }
  • DELETE /users/delete/{id}

    • Returns:
      {
        "message": "User {id} deleted successfully"
      }

Development

Install dependencies

  pip install -r requirements-test.txt .

Run tests

Unit Test

  • Run All Tests
  pytest -v
  • Run Failed Tests
pytest --last-failed

Unit Test Coverage

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

Run Lint

  python -m flake8 src test

Run app

  python -m src/app.py

Update API Spec & Collections

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

Render Deployment

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.

🖼 Architecture

Currently we are having only two controllers as showm in the image below (Repository Architecture). In future, will have many more.

Architecture Diagram

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published