This is a full-stack web application for managing user subscriptions. It consists of a Django REST framework backend and a React frontend. This README provides a guide for setting up and running the project locally.
-
User Authentication: Secure login and session management.
-
Subscription Plans: Manage and view various subscription tiers.
-
Subscription Lifecycle: Handle subscription creation, activation, and renewal.
-
Payment Proof Upload: Users can upload proof of payment for manual verification.
-
Admin Panel: A Django admin interface for administrators to manage users, plans, and verify payments.
- Backend Setup
- Prerequisites
- Setup Instructions
- API Endpoints
- Testing
- Project Structure
- Dependencies
- Error Handling
- Development
- Frontend Setup
- Python 3.11 or higher
- PostgreSQL
- pip (Python package manager)
- Node.js 14+ & npm
-
Clone the repository
git clone https://github.com/PrajwalChaudhary25/subscription.git cd backend -
Create a virtual environment
# Windows python -m venv myenv myenv\Scripts\activate # Linux/MacOS python3 -m venv myenv source myenv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Database Setup
- Install PostgreSQL if you haven't already
- Create a new database named
my_subscription_db - Update the database configuration in
backend/settings.pyif needed:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'my_subscription_db', 'USER': 'admin', 'PASSWORD': 'password', 'HOST': 'localhost', 'PORT': '5432', } }
-
Apply migrations
python manage.py migrate
-
Create a superuser
python manage.py createsuperuser
-
Run the development server
python manage.py runserver
The server will start at http://127.0.0.1:8000/
POST /api/token/- Obtain authentication token
GET /api/user/- Get current user details
GET /api/plans/- List all subscription plansGET /api/plans/<id>/- Get specific plan details
GET /api/users/<user_id>/subscriptions/- Get user's subscriptionsPOST /api/purchase/- Purchase a subscription planPOST /api/renew/- Renew existing subscription
To run the tests:
python manage.py testbackend/
├── manage.py
├── backend/
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── media/
│ └── payment_proofs/ # Payment proof uploads
└── subscriptions/
├── __init__.py
├── admin.py # Admin interface configuration
├── apps.py # App configuration
├── models.py # Database models
├── serializers.py # API serializers
├── tests.py # Unit tests
├── urls.py # API routing
├── views.py # API views
├── api/
│ ├── serializers.py
│ └── views.py
└── migrations/ # Database migrations
- Django
- Django REST Framework
- django-cors-headers
- psycopg2-binary
- python-dateutil
The API uses standard HTTP response codes:
- 200: Success
- 400: Bad request
- 401: Unauthorized
- 404: Not found
- 500: Server error
- Make sure to activate your virtual environment before starting development
- Use
python manage.py makemigrationswhen modifying models - Apply migrations with
python manage.py migrate - The development server will reload automatically when code changes
The frontend is a react application
- Navigate to the forntend directory
cd ../frontend- Install Dependencies
Use
npmto install all the necessary packages defined inpackage.json.
npm install- Start the React Development Server
npm startThe frontend will be available at http://localhost:3000/.