ShopZone is a API for an e-commerce platform designed to provide users with the ability to manage products, create accounts, and perform authenticated operations. This API supports product CRUD operations, role-based access control (RBAC), JWT-based authentication, and caching for performance optimization.
With ShopZone, users can:
- Register, log in, and manage their own product listings.
- Filter products and securely interact with store data.
- Benefit from the integration of third-party services such as currency conversion.
Built with Django, Django REST Framework, and PostgreSQL, the platform leverages Redis for caching and supports JWT for secure access. It is designed with performance optimization in mind, ensuring fast and efficient interactions.
-
User Registration & Authentication:
- Users can sign up using email, username, and password.
- Secure authentication using JWT with login and logout functionality.
-
Product Management:
- Full support for CRUD (Create, Read, Update, Delete) operations on products.
- Each product includes attributes such as name, description, price, quantity, category, and store ID.
- Only authenticated users can create, update, and delete products.
-
Role-Based Access Control (RBAC):
- Two user roles: Admin and User.
- Admins can manage all products and users, while regular users can only manage their own products.
-
Database Management:
- Uses PostgreSQL for storing user and product data.
- Includes database migrations to set up and modify schemas as needed.
-
Performance Optimization:
- Caching is implemented for frequently accessed product data using Redis to ensure high-performance API responses.
-
Third-Party Integration:
- Integration with a currency conversion API to convert product prices to different currencies, offering flexibility to users globally.
-
Testing:
- Includes unit and integration tests for user registration, authentication, and product management using PyTest to ensure code reliability and maintainability.
- Django: Backend web framework to power the API.
- Django REST Framework: Provides tools to build a RESTful API with authentication and authorization features.
- PostgreSQL: A relational database system for managing and storing data.
- Redis: An in-memory data structure store, used here for caching frequently accessed product data.
- JWT: JSON Web Tokens for secure, stateless user authentication.
- Python 3.6+
- PostgreSQL
- Redis
- pip (Python package installer)
-
Clone the Repository:
git clone https://github.com/Mannuel25/shopzone.git cd shopzone
-
Create a Virtual Environment:
python -m venv venv
-
Activate the Virtual Environment:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
-
Install Dependencies:
pip install -r requirements.txt
-
Configure the Database: Update the
DATABASES
settings inshopzone/settings.py
to match your PostgreSQL configuration. -
Make Migrations
python manage.py makemigrations
-
Apply Migrations
python manage.py migrate
-
Create a Superuser (Optional)
python manage.py createsuperuser
-
Run the Development Server
python manage.py runserver
-
Clone the Repository:
git clone https://github.com/Mannuel25/ShopZone.git cd ShopZone
-
Ensure Docker is installed
Ensure Docker and Docker Compose are installed and running on your machine. You can check this with the following commands:
docker --version docker-compose --version
-
Build and Start the Docker Containers
Use Docker Compose to build the containers and start the services:
docker-compose up --build
-
Make Migrations
Once the containers are up, make the migrations to set up the database schema:
docker-compose exec web python manage.py makemigrations
-
Run Migrations
Once the containers are up, apply the migrations to set up the database schema:
docker-compose exec web python manage.py migrate
-
Create a Superuser (Optional)
If you want to create a superuser, run:
docker-compose exec web python manage.py createsuperuser
-
Access the Application
After successfully running the Docker containers, the application will be available at:
http://localhost:8000
-
Stop the Docker Containers
When you're done, stop the containers using:
docker-compose down
Explore the API using the Postman collection here for testing and interacting with the API endpoints.
Alternatively, you can interact with the documentation available at /swagger/
or /redoc/
endpoints when running the server.
- Currency Conversion: Products can be priced in different currencies by integrating with the ExchangeRate API. This allows customers to view product prices in their preferred currency, providing flexibility for global transactions. You can refer to the supported currencies list to see the available currencies for filtering.
Run the tests to ensure the system is functioning as expected:
pytest
Errors are returned in the following format:
{
"message": "Error message",
"status_code": 400
}
This project is licensed under an MIT LICENSE.