Project Status: β Version 1.0 (Complete) β
A robust RESTful API for parking service management, built with Django and Django REST Framework. The project is fully containerized with Docker and follows best development practices, including automated tests with high coverage, code linting, and formatting.
- Customer Management (
/api/v1/customers): Complete CRUD operations for customer registration - Vehicle Management (
/api/v1/vehicles): CRUD operations for vehicles, associating them with customers - Vehicle Types (
/api/v1/vehicles/type): Management of vehicle categories (e.g., Car, Motorcycle) - Parking Control:
- Parking Spots (
/api/v1/parking/spots): Management of parking spots - Parking Records (
/api/v1/parking/records): System for registering vehicle entry and exit, with automatic update of spot occupancy status
- Parking Spots (
- Authentication: JWT-based authentication system to protect API endpoints
- Optimized Admin: Customized administration interface with intelligent vehicle data auto-fill functionality to streamline workflow
- Swagger UI: Interactive API documentation at
/api/v1/docs/ - ReDoc: Alternative API documentation at
/api/v1/redoc/ - OpenAPI Schema: Available at
/api/v1/schema/
A common requirement in parking systems is the automatic filling of vehicle information (brand, model, color) from the license plate. However, there are no public, free, and legal APIs in Brazil for this purpose. Solutions based on web scraping of government portals were discarded as they are unstable, violate terms of service, and present risks related to LGPD (Brazil's General Data Protection Law).
As a pragmatic and professional solution, a POST endpoint (/api/v1/vehicles/get-by-plate/) was implemented that acts as a simulated data provider:
- When a new license plate is provided, the system uses the Faker library to generate fictional data for brand, model, and color
- This data is saved in the database
- In future queries for the same plate, the previously saved consistent data is returned
This approach demonstrates the ability to work around real-world limitations, ensuring a smooth user experience and allowing the system to function completely and independently, without depending on external services.
With the goal of following software design best practices, such as the Single Responsibility Principle (SRP), the business logic for vehicle querying and creation was extracted from the API layer (views.py) and isolated in a dedicated service layer (services.py). This refactoring made the code cleaner, more reusable, and much easier to test, demonstrating a commitment to long-term project maintainability.
The project was built with a focus on quality, maintainability, and modern development practices.
- Framework: Django 5.2, Django REST Framework 3.16
- Database: PostgreSQL 16
- Authentication:
djangorestframework-simplejwtfor JWT tokens
- Containerization: Docker, Docker Compose
- Dependency Management:
pipandpip-tools(pip-compile) - Testing:
pytest,pytest-django,pytest-cov(with 96% test coverage) - Code Quality:
Rufffor linting and formatting,pre-commitfor automated quality checks - API Documentation:
drf-spectacularfor automatic OpenAPI 3 schema generation - Admin Interface:
django-jazzminfor enhanced admin UI - Query Filtering:
django-rqlfor advanced query filtering
- Faker: For generating realistic test data
- WhiteNoise: For static file serving
- Gunicorn: Production WSGI server
- Docker (version 20.10 or higher)
- Docker Compose (version 2.0 or higher)
The project is fully containerized, so all you need is Docker and Docker Compose.
git clone https://github.com/CFBruna/parking_service.git
cd parking_serviceCreate a .env.docker file in the root directory with the following variables:
# Database
DATABASE_URL=postgresql://postgres:postgres@db:5432/parking_db
# Django
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=127.0.0.1,localhost
# Static Files
STATIC_ROOT=/usr/src/app/staticfilesNote: For development, you can use the default values. Adjust them as needed for production.
docker-compose up --buildThe --build flag is important the first time to build the Docker image.
In a new terminal, with containers running:
docker-compose exec web python manage.py migrateTo access the Django admin interface:
docker-compose exec web python manage.py createsuperuser- API Base URL:
http://127.0.0.1:8000/api/v1/ - Admin Interface:
http://127.0.0.1:8000/admin/ - API Documentation (Swagger):
http://127.0.0.1:8000/api/v1/docs/ - API Documentation (ReDoc):
http://127.0.0.1:8000/api/v1/redoc/
The automated test suite is fundamental to ensure the quality and stability of the project.
With containers running:
docker-compose exec web pytestTo see the coverage report in the terminal:
docker-compose exec web pytest --covTo generate a detailed HTML coverage report:
docker-compose exec web pytest --cov --cov-report=htmlOpen the htmlcov/index.html file in your browser to explore the report.
Current Test Coverage: 96% β
POST /api/v1/authentication/token/- Obtain JWT tokenPOST /api/v1/authentication/token/refresh/- Refresh JWT tokenPOST /api/v1/authentication/token/verify/- Verify JWT token
GET /api/v1/customers/- List all customersPOST /api/v1/customers/- Create a new customerGET /api/v1/customers/{id}/- Retrieve a customerPUT /api/v1/customers/{id}/- Update a customerPATCH /api/v1/customers/{id}/- Partially update a customerDELETE /api/v1/customers/{id}/- Delete a customer
GET /api/v1/vehicles/- List all vehiclesPOST /api/v1/vehicles/- Create a new vehicleGET /api/v1/vehicles/{id}/- Retrieve a vehiclePUT /api/v1/vehicles/{id}/- Update a vehiclePATCH /api/v1/vehicles/{id}/- Partially update a vehicleDELETE /api/v1/vehicles/{id}/- Delete a vehiclePOST /api/v1/vehicles/get-by-plate/- Get or create vehicle data by license plateGET /api/v1/vehicles/type/- List all vehicle typesPOST /api/v1/vehicles/type/- Create a new vehicle typeGET /api/v1/vehicles/type/{id}/- Retrieve a vehicle typePUT /api/v1/vehicles/type/{id}/- Update a vehicle typePATCH /api/v1/vehicles/type/{id}/- Partially update a vehicle typeDELETE /api/v1/vehicles/type/{id}/- Delete a vehicle type
GET /api/v1/parking/spots/- List all parking spotsPOST /api/v1/parking/spots/- Create a new parking spotGET /api/v1/parking/spots/{id}/- Retrieve a parking spotPUT /api/v1/parking/spots/{id}/- Update a parking spotPATCH /api/v1/parking/spots/{id}/- Partially update a parking spotDELETE /api/v1/parking/spots/{id}/- Delete a parking spotGET /api/v1/parking/records/- List all parking recordsPOST /api/v1/parking/records/- Create a new parking record (entry)GET /api/v1/parking/records/{id}/- Retrieve a parking recordPUT /api/v1/parking/records/{id}/- Update a parking recordPATCH /api/v1/parking/records/{id}/- Partially update a parking record (exit)DELETE /api/v1/parking/records/{id}/- Delete a parking record
The API supports RQL (Resource Query Language) for advanced filtering. For example:
GET /api/v1/vehicles/?filter=license_plate=like=ABC*
GET /api/v1/parking/records/?filter=entry_time=ge=2024-01-01T00:00:00ZSee the django-rql documentation for more details.
The API uses JWT (JSON Web Tokens) for authentication. To authenticate:
-
Obtain a token by making a POST request to
/api/v1/authentication/token/with your credentials:{ "username": "your_username", "password": "your_password" } -
Include the token in subsequent requests using the
Authorizationheader:Authorization: Bearer <your_token> -
Refresh your token using
/api/v1/authentication/token/refresh/when it expires.
parking_service/
βββ authentication/ # Authentication app
βββ customers/ # Customer management app
βββ vehicles/ # Vehicle management app
βββ parking/ # Parking management app
βββ parking_service/ # Main project settings
βββ static/ # Static files (images, JS)
βββ docker-compose.yml # Docker Compose configuration
βββ Dockerfile # Docker image definition
βββ requirements.txt # Python dependencies
βββ pytest.ini # Pytest configuration
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the terms specified in the LICENSE file.
- GitHub: @CFBruna
Made with β€οΈ using Django and Django REST Framework