Skip to content

A full-fledged E-commerce API built on Django Rest Framework with stripe integration.

Notifications You must be signed in to change notification settings

chapainaashish/shopapi

Repository files navigation

Shopapi

An E-commerce APIs built using Django Rest Framework

Features

  • Basic e-commerce features
  • User profile and registration
  • JWT based authentication
  • Custom permissions set for necessary endpoints
  • Payment integration using Stripe
  • Customized Admin Panel
  • Redis caching
  • Tested API endpoints using pytest
  • Error tracking with Sentry
  • Performed performance test [local machine gunicorn web server]
  • Logged essential external service call
  • Documentation using DRF spectacular
  • Dockerized for local development and production

Technologies Used

Technology Purpose
Django Rest Framework APIs Building
Poetry Dependency Management
PostgreSQL Database
Celery Background Task
Redis Caching
Pytest API Testing
Locust Performance Testing
Djoser User Registration
Simple-JWT User Authentication
Stripe Payment
DRF spectacular Documentation
Error Tracking Sentry
Docker Containerization

How to set up?

Manual Set up

  1. Clone the project https://github.com/chapainaashish/shopapi

  2. Install poetry in your system curl -sSL https://install.python-poetry.org | python3 -

  3. Install the dependencies poetry install

  4. Enter into the virtual environment poetry shell

  5. Rename the .env_example to .env and update the environment variables accordingly

  6. Set DJANGO_SETTINGS_MODULE according to your need

    • For development: DJANGO_SETTINGS_MODULE = 'shopapi.settings.development'
    • For production : DJANGO_SETTINGS_MODULE = 'shopapi.settings.production'
      • Set database HOST USER PASSWORD PORT in .env file for production
  7. Install sentry-sdk pip install --upgrade 'sentry-sdk[django]'

  8. Install docker in your system https://docs.docker.com/desktop/

  9. Run redis using docker docker run -d -p 6379:6379 redis

  10. Start the celery worker celery -A shopapi worker --loglevel=info

  11. Install the stripe cli tool on your system https://stripe.com/docs/stripe-cli#install

  12. Configure the webhook stripe listen --forward-to localhost:8000/store/webhooks/stripe/

  13. Create the migration python manage.py migrate

  14. Create the superuser python manage.py createsuperuser

  15. Run the development server python manage.py runserver

  16. Head over to http://localhost:8000/admin on your browser

  17. Run the test using command pytest or pwt for continuous testing [Optional]

  18. Generate test coverage in html using pytest --cov --cov-report=html [Optional]

  19. Run celery flower to manage celery workers celery flower [Optional]

  20. Run the performance test using locust -f locustfiles/browse_product.py [Optional]

  21. Read the API documentation on http://127.0.0.1:8000/api/schema/swagger-ui/ [Optional]

Docker Set up

  1. Clone the project https://github.com/chapainaashish/shopapi

  2. Rename the .env_example to .env and update the environment variables accordingly

  3. Set DJANGO_SETTINGS_MODULE according to your need

    • For development: DJANGO_SETTINGS_MODULE = 'shopapi.settings.development'
    • For production : DJANGO_SETTINGS_MODULE = 'shopapi.settings.production'
      • Set database HOST USER PASSWORD PORT in .env file for production
  4. Install docker in your system https://docs.docker.com/desktop/

  5. Rename docker-compose-dev.yml to docker-compose.yml for development [Skip for production]

  6. Build docker image and run

$ docker-compose up
$ docker-compose exec web python manage.py createsuperuser
  1. Head over to http://localhost:8000/admin on your browser

ER Diagram

API Endpoints

Endpoints User
Anonymous Authenticated+Authorized Admin
collection
store/collection GET GET GET, POST
store/collection/pk GET GET GET, PUT, PATCH, DELETE
product
store/product GET GET GET, POST
store/product/pk GET GET GET, PUT, PATCH, DELETE
store/product/pk/reviews GET GET, POST GET, POST
store/product/pk/reviews/pk GET GET, PATCH, DELETE GET, PATCH, DELETE
cart
store/cart - GET, POST GET, POST
store/cart/pk - GET GET
store/cart/pk/items - GET, POST GET, POST
store/cart/pk/items/pk - GET, PATCH, DELETE GET, PATCH, DELETE
order
store/order - GET, POST GET, POST
store/order/pk - GET GET, PATCH, DELETE
store/order/pk/items - GET GET
store/order/pk/items/pk - GET GET, DELETE
payment
store/payment - GET GET
store/payment/pk - GET GET, PATCH, DELETE
stripe/payment/pk - POST POST
user
user/address - GET, POST GET, POST
user/address/pk - GET, PUT, PATCH, DELETE GET, PUT, PATCH, DELETE
user/profile - GET, POST GET, POST
user/profile/pk - GET, PATCH, DELETE GET, PATCH, DELETE

References

Releases

No releases published

Packages

No packages published

Languages