This project implements a complete RESTful API for a Mechanic Shop with advanced features including:
- Built a production-style Flask API with authentication, authorization, caching, rate limiting, and OpenAPI docs.
- Implemented 27 documented endpoints across Customers, Mechanics, Service Tickets, and Inventory resources.
- Wrote 71 automated tests covering positive and negative flows, auth guards, and business rules.
- Added CI/CD automation and deployment configuration for cloud hosting.
- Application Factory pattern for environment-specific app creation and testability.
- Blueprint-based route modules for clear domain separation.
- SQLAlchemy models for relational entities and many-to-many junction tables.
- Marshmallow validation/serialization to enforce request and response contracts.
- Token-based auth decorator to secure protected routes.
Add screenshots and demo GIFs under docs/media/ to make this project faster to evaluate for recruiters.


- β Rate Limiting - Protection against API abuse
- β Token Authentication - JWT-based customer authentication
- β Caching - Improved performance for frequently accessed data
- β Pagination - Efficient data retrieval for large datasets
- β Advanced Queries - Complex database operations
- β Inventory Management - New resource with many-to-many relationships
- JWT token-based authentication using
python-jose - Password hashing with
bcrypt - Protected routes requiring valid tokens
- Customer login system
- Authorization checks (users can only modify their own data)
- Default rate limits: 200 requests/day, 50 requests/hour
- Customer creation endpoint: 5 requests/minute
- Implemented using
Flask-Limiter
- GET customers endpoint cached for 60 seconds
- Implemented using
Flask-Caching - Improves performance for frequently accessed data
- GET customers endpoint supports pagination
- Query parameters:
pageandper_page - Returns comprehensive pagination metadata
- Edit Ticket Mechanics: Add and remove multiple mechanics in one request
- Mechanics Ranking: Get mechanics ordered by tickets worked on
- Complex SQL queries with aggregations
- Full CRUD operations for inventory parts
- Many-to-many relationship with service tickets
- Track parts used in each service
- Swagger/OpenAPI Documentation: Interactive API documentation with Flasgger
- All 27 endpoints documented with request/response schemas
- JWT authentication support in Swagger UI
- Accessible at
/api-docs/
- Comprehensive Unit Tests: 71 tests covering all endpoints
- Positive and negative test cases
- Separate test database configuration
- Tests for authentication, authorization, validation, and business logic
- Coverage for all CRUD operations and advanced features
pip install -r requirements.txtpython update_database.pypython populate_database.pypython run.pyThe API will be available at http://localhost:5000
- API_DOCUMENTATION.md - Complete API reference with all endpoints
- TESTING_GUIDE.md - Testing instructions
- PROJECT_SUMMARY.md - Project overview
- DEPLOYMENT.md - Production deployment guide with CI/CD setup (NEW)
This API includes interactive Swagger documentation powered by Flasgger:
- Swagger UI:
http://localhost:5000/api-docs/(local) orhttps://your-app-url/api-docs/(production) - OpenAPI Spec:
http://localhost:5000/apispec.json
The Swagger UI provides:
- β Interactive API documentation for all 27 endpoints
- β Try-it-out functionality to test endpoints directly
- β Request/response examples with proper schemas
- β JWT Bearer token authentication support (click "Authorize" button)
- β Organized by tags: Customers, Mechanics, Service Tickets, Inventory
To use protected endpoints in Swagger:
- Login via
POST /customers/loginendpoint - Copy the returned token
- Click the "Authorize" button at the top right
- Enter:
Bearer <your-token-here> - Click "Authorize" and then "Close"
- All protected endpoints will now include the token automatically
This project includes comprehensive unit tests covering all endpoints:
# Activate virtual environment first
venv\Scripts\activate # Windows
source venv/bin/activate # Linux/Mac
# Run all tests
python -m unittest discover tests -v
# Run specific test file
python -m unittest tests.test_customers -v
# Run specific test
python -m unittest tests.test_customers.TestCustomerBlueprint.test_login_success -v- 71 total tests covering all 27 API endpoints
- Positive tests: Verify successful operations
- Negative tests: Verify error handling and validation
- Test database: Uses separate
mechanic_shop_testdatabase
-
Customers (22 tests):
- Authentication (login, tokens)
- Authorization (protected routes)
- Rate limiting validation
- Pagination functionality
- Email validation
- CRUD operations
-
Mechanics (13 tests):
- CRUD operations
- Email uniqueness validation
- Advanced queries (ranking by tickets)
- Data type validation
-
Service Tickets (19 tests):
- CRUD operations
- Mechanic assignment/removal (many-to-many)
- Inventory part management
- Bulk editing mechanics
- Foreign key constraint validation
-
Inventory (17 tests):
- CRUD operations
- Price validation (type checking)
- Partial updates
- Edge cases (zero/negative prices)
# Create test database
python create_test_database.pyThis creates a separate mechanic_shop_test database to avoid interfering with development data.
- Each test is independent (setUp/tearDown handle cleanup)
- Junction tables cleared before main tables (proper foreign key handling)
- Both success and failure scenarios tested
- Token authentication tested thoroughly
- Database constraints validated
- Import the collection:
Mechanic_Shop_Advanced_API.postman_collection.json - Test all endpoints in the following order:
- Create a customer
- Login to get a token
- Test protected routes with the token
- Test pagination, caching, and rate limiting
- Explore inventory and advanced queries
After running populate_database.py:
- Email: john@example.com | Password: password123
- Email: jane@example.com | Password: password123
- Email: bob@example.com | Password: password123
- customers - Customer information (includes password field)
- mechanics - Mechanic information
- service_tickets - Service ticket records
- inventory - Inventory parts (NEW)
- service_mechanic - Junction table (tickets β mechanics)
- service_inventory - Junction table (tickets β inventory) (NEW)
- Customer β Service Tickets (One-to-Many)
- Service Ticket β Mechanics (Many-to-Many)
- Service Ticket β Inventory (Many-to-Many) (NEW)
POST /customers/- Create account (rate limited)POST /customers/login- Login and get tokenGET /customers/my-tickets- Get my tickets (requires token)
GET /customers/?page=1&per_page=10- Paginated list (cached)PUT /customers/<id>- Update (requires token)DELETE /customers/<id>- Delete (requires token)
GET /mechanics/by-tickets- Ranked by tickets worked (advanced query)
PUT /service-tickets/<id>/edit- Add/remove mechanics (advanced query)PUT /service-tickets/<id>/add-part/<part_id>- Add inventory part
POST /inventory/- Create partGET /inventory/- List all partsPUT /inventory/<id>- Update partDELETE /inventory/<id>- Delete part
- Flask 3.1.2 - Web framework
- Flask-SQLAlchemy 3.1.1 - ORM
- Flask-Limiter 3.5.0 - Rate limiting
- Flask-Caching 2.1.0 - Caching
- Marshmallow 4.2.1 - Serialization/validation
- python-jose 3.3.0 - JWT tokens
- bcrypt 4.1.2 - Password hashing
- Flasgger 0.9.7.1 - Swagger/OpenAPI documentation (NEW)
- unittest - Python built-in testing framework (NEW)
- MySQL Connector - Database driver
Mechanic Shop/
βββ app/
β βββ __init__.py # App factory with rate limiting, caching & Swagger
β βββ models.py # Database models (includes Inventory)
β βββ utils.py # Token auth utilities
β βββ blueprints/
β βββ customer/ # Customer routes (auth, pagination, Swagger docs)
β βββ mechanic/ # Mechanic routes (advanced queries, Swagger docs)
β βββ service_ticket/ # Service ticket routes (Swagger docs)
β βββ inventory/ # Inventory routes (Swagger docs)
βββ tests/ # Unit tests (NEW)
β βββ __init__.py # Test package initialization
β βββ test_customers.py # Customer endpoint tests (22 tests)
β βββ test_mechanics.py # Mechanic endpoint tests (13 tests)
β βββ test_service_tickets.py # Service ticket tests (19 tests)
β βββ test_inventory.py # Inventory endpoint tests (17 tests)
β βββ README.md # Testing documentation
βββ requirements.txt # Updated with Flasgger
βββ create_test_database.py # Test database setup script (NEW)
βββ update_database.py # Database update script
βββ populate_database.py # Sample data script
βββ API_DOCUMENTATION.md # Complete API docs
βββ Mechanic_Shop_Advanced_API.postman_collection.json
- β Rate limiting on customer creation route
- β Default rate limits applied to all routes
- β Caching on GET customers route
- β
encode_token()function - β
login_schemafor validation - β
POST
/customers/loginroute - β
@token_requireddecorator - β
GET
/customers/my-ticketswith token - β Protected update/delete routes
- β
PUT
/service-tickets/<id>/editfor add/remove mechanics - β
GET
/mechanics/by-ticketsfor ranking - β Pagination on GET customers
- β Inventory model with id, name, price
- β Many-to-many relationship with service tickets
- β Inventory blueprint with CRUD routes
- β Add part to ticket route
- β Swagger/OpenAPI documentation for all 27 endpoints
- β 71 comprehensive unit tests (positive and negative)
- β Separate test database configuration
- β Complete API documentation
- β Production configuration with environment variables
- β PostgreSQL support for Render deployment
- β Gunicorn production server
- β GitHub Actions CI/CD pipeline
- β Automated testing on push
- β Automated deployment to Render
- β Dynamic Swagger configuration (http/https)
This project is deployment-ready with full CI/CD pipeline support!
- Database: Create PostgreSQL database on Render
- Web Service: Deploy from your GitHub repository
- Environment Variables: Set
DATABASE_URI,SECRET_KEY,FLASK_ENV=production,BASE_URL - CI/CD: Add GitHub secrets (
RENDER_API_KEY,SERVICE_ID) - Done: Auto-deploy on every push to main!
See DEPLOYMENT.md for complete step-by-step deployment guide.
- β Build Job: Python syntax validation
- β Test Job: Runs all 71 unit tests with MySQL service
- β Deploy Job: Auto-deploys to Render on successful tests
- β Workflow: Triggered on push/PR to main branch
- Configuration Management: Separate dev/test/production configs
- Environment Variables: Secure credential management with
.env - Database Support: MySQL (development) + PostgreSQL (production)
- Production Server: Gunicorn WSGI server
- Auto-scaling: Ready for Render's scaling features
- HTTPS: Automatic SSL/TLS in production
Secret Key Management:
- Development: Set in
.envfile (not committed) - Production: Set in Render environment variables
- Generate secure key:
python -c "import secrets; print(secrets.token_hex(32))"
Database Credentials:
- Never commit database passwords to version control
- Use
.envfor local development (in.gitignore) - Use Render environment variables for production
Beyond the project requirements, this project includes:
- Comprehensive error handling
- Authorization checks
- Detailed API documentation
- Sample data population script
- Complete Postman collection
- Automatic token storage in Postman
This is an educational project for learning advanced API development techniques.
Educational use only.
Project completed by: Yousaf Zeb
Date: February 15, 2026
Course: Advanced API Development