Skip to content

UmanSheikh/backend-IS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Influencer Marketing Platform - Backend API

A comprehensive Django REST Framework backend for an influencer marketing platform that connects brands with influencers for campaign collaborations.

πŸ“‹ Overview

This backend system powers an influencer marketing platform where:

  • Brands can create campaigns, manage budgets, and collaborate with influencers
  • Influencers can browse campaigns, place bids, and deliver content
  • Both parties can communicate through an integrated messaging system
  • Payments are processed securely through Stripe integration
  • Real-time notifications keep users informed of campaign updates

✨ Features

User Management

  • Dual account types: Brand and Influencer
  • JWT-based authentication with access and refresh tokens
  • Email verification with OTP
  • Profile management with profile pictures and bio
  • Instagram username integration

Campaign Management

  • Create, update, and delete campaigns
  • Campaign status tracking (Open, Pending Payment, In Progress, Completed, Closed)
  • Campaign images and detailed descriptions
  • Budget management
  • Date-based campaign scheduling

Bidding System

  • Influencers can bid on open campaigns
  • Brands can accept or decline bids
  • Bid status tracking (Pending, Accepted, Declined)
  • Delivery status management (Pending, Delivered, Approved)

Payment Processing

  • Stripe integration for secure payments
  • Checkout session creation
  • Payment status tracking (Pending, Completed, Failed)
  • Payment success and cancellation handling

Analytics

  • Track campaign performance metrics
  • Engagement rate monitoring
  • Reach and impressions tracking
  • Clicks and conversions reporting

Messaging System

  • Direct messaging between users
  • Recent conversations view
  • Contact list management
  • Unread message indicators
  • Automatic notifications for new messages

Notifications

  • Real-time notification system
  • Multiple notification types
  • Read/unread status tracking
  • Automatic notifications for key events

πŸ›  Technology Stack

  • Framework: Django 5.1.2
  • API: Django REST Framework 3.15.2
  • Authentication: JWT (djangorestframework-simplejwt 5.5.0)
  • Database: SQLite3 (development)
  • Payment Processing: Stripe
  • Image Handling: Pillow 11.1.0
  • CORS: django-cors-headers 4.7.0
  • Real-time Features: Channels 4.2.2, Redis 6.2.0, Daphne 4.2.0

πŸ“¦ Installation

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)
  • Virtual environment (recommended)

Setup Steps

  1. Clone the repository

    git clone https://github.com/UmanSheikh/backend-IS.git
    cd backend-IS
  2. Create and activate virtual environment

    python -m venv venv
    
    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Run migrations

    python manage.py migrate
  5. Create superuser (optional)

    python manage.py createsuperuser
  6. Run the development server

    python manage.py runserver

The API will be available at http://localhost:8000/

βš™οΈ Configuration

Environment Variables

Key settings in backend/settings.py that you may want to configure:

  • SECRET_KEY: Django secret key (change in production)
  • DEBUG: Set to False in production
  • ALLOWED_HOSTS: Add your domain in production
  • DATABASES: Configure production database
  • STRIPE_API_KEY: Your Stripe API key
  • FRONTEND_URL: Frontend application URL (default: http://localhost:3000)

CORS Configuration

The API is configured to accept requests from:

  • http://localhost:3000 (default frontend)

Add additional origins in CORS_ALLOWED_ORIGINS in settings.py

JWT Configuration

  • Access token lifetime: 60 minutes
  • Refresh token lifetime: 1 day

πŸ”— API Endpoints

Authentication

  • POST /apis/register-user/ - Register a new user
  • POST /apis/login/ - User login
  • GET /apis/user-profile/ - Get authenticated user profile

User Management

  • GET /apis/users/ - List all users
  • GET /apis/user/<uuid:id>/ - Get user details
  • PUT /apis/update-user/<str:email>/ - Update user
  • DELETE /apis/delete-user/<str:email>/ - Delete user

Campaign Management

  • GET /apis/campaign/ - List open campaigns (for influencers)
  • GET /apis/campaigns/ - List all campaigns (for authenticated users)
  • POST /apis/create-campaign/ - Create a new campaign
  • GET /apis/campaigns/<uuid:id>/ - Get campaign details
  • PUT /apis/update-campaign/<uuid:id>/ - Update campaign
  • DELETE /apis/delete-campaign/<uuid:id>/ - Delete campaign
  • GET /apis/completed-campaigns/ - List completed campaigns

Bid Management

  • GET /apis/bids/ - List bids
  • POST /apis/bids/create/ - Create a new bid
  • GET /apis/bids/list/<uuid:campaign_id>/ - List bids for a campaign
  • PUT /apis/bids/update/<uuid:id>/ - Update bid status
  • POST /apis/bids/deliver/<uuid:id>/ - Mark bid as delivered

Payment Processing

  • POST /apis/create-checkout-session/ - Create Stripe checkout session
  • GET /apis/pay/success/ - Payment success callback
  • GET /apis/pay/cancel/ - Payment cancellation callback

Analytics

  • GET /apis/analytics/ - List analytics
  • POST /apis/create-analytics/ - Create analytics record
  • PUT /apis/update-analytics/<uuid:id>/ - Update analytics
  • DELETE /apis/delete-analytics/<uuid:id>/ - Delete analytics

Messaging

  • GET /apis/messages/contacts/ - Get contact list
  • GET /apis/messages/recent/ - Get recent conversations
  • GET /apis/messages/ - List messages
  • POST /apis/messages/ - Send a new message

Notifications

  • GET /apis/notifications/ - List notifications
  • POST /apis/create-notification/ - Create notification
  • PUT /apis/update-notification/<uuid:id>/ - Update notification
  • DELETE /apis/delete-notification/<uuid:id>/ - Delete notification

Dashboard

  • GET /apis/brand-data/ - Get brand dashboard data

Instagram Integration

  • POST /apis/fetch-instagram-data/ - Fetch Instagram profile data

πŸ“ Project Structure

backend-IS/
β”œβ”€β”€ apis/                      # Main API application
β”‚   β”œβ”€β”€ migrations/           # Database migrations
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ admin.py             # Admin panel configuration
β”‚   β”œβ”€β”€ apps.py              # App configuration
β”‚   β”œβ”€β”€ models.py            # Database models
β”‚   β”œβ”€β”€ serializers.py       # DRF serializers
β”‚   β”œβ”€β”€ tests.py             # Test cases
β”‚   β”œβ”€β”€ urls.py              # API URL routing
β”‚   └── views.py             # API views
β”œβ”€β”€ backend/                  # Project settings
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ asgi.py              # ASGI configuration
β”‚   β”œβ”€β”€ settings.py          # Django settings
β”‚   β”œβ”€β”€ urls.py              # Main URL configuration
β”‚   β”œβ”€β”€ views.py             # Base views
β”‚   └── wsgi.py              # WSGI configuration
β”œβ”€β”€ media/                    # User-uploaded media files
β”‚   β”œβ”€β”€ profile_pics/        # Profile pictures
β”‚   └── campaign_images/     # Campaign images
β”œβ”€β”€ db.sqlite3               # SQLite database (development)
β”œβ”€β”€ manage.py                # Django management script
β”œβ”€β”€ requirements.txt         # Python dependencies
└── README.md               # This file

πŸ—ƒ Database Models

IS_Users

Custom user model extending Django's AbstractUser with:

  • UUID primary key
  • Email and username (unique)
  • Account type (Brand/Influencer)
  • Instagram username
  • Profile picture and bio
  • OTP verification system

Campaign

  • Title, description, and budget
  • Start and end dates
  • Status tracking
  • Image upload
  • Foreign key to Brand (IS_Users)

Bid

  • Campaign and Influencer references
  • Bid amount
  • Status (Pending, Accepted, Declined)
  • Payment status
  • Delivery status

Payment

  • One-to-one relationship with Bid
  • Amount and payment date
  • Status tracking

Analytics

  • Campaign and Influencer references
  • Engagement metrics (rate, reach, impressions)
  • Click and conversion tracking

Message

  • Sender and recipient (IS_Users)
  • Message content
  • Read status
  • Timestamp

Notification

  • User reference
  • Message content
  • Notification type
  • Read status

πŸ” Authentication

The API uses JWT (JSON Web Tokens) for authentication. Include the token in the Authorization header:

Authorization: Bearer <access_token>

Getting Tokens

  1. Register a new user at /apis/register-user/
  2. Login at /apis/login/ to receive access and refresh tokens
  3. Use the access token for authenticated requests
  4. Refresh the token using the refresh token when it expires

πŸ’³ Payment Integration

The platform uses Stripe for payment processing:

  1. Brand accepts an influencer's bid
  2. Campaign status changes to "Pending Payment"
  3. Brand initiates payment through /apis/create-checkout-session/
  4. User completes payment on Stripe checkout page
  5. Success callback updates payment status
  6. Campaign status updates to "In Progress"

πŸš€ Usage Examples

Register a New User

curl -X POST http://localhost:8000/apis/register-user/ \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "username": "username",
    "first_name": "John",
    "last_name": "Doe",
    "password": "secure_password",
    "phone_number": "+1234567890",
    "account_type": "brand"
  }'

Login

curl -X POST http://localhost:8000/apis/login/ \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "secure_password"
  }'

Create a Campaign (Authenticated)

curl -X POST http://localhost:8000/apis/create-campaign/ \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access_token>" \
  -d '{
    "title": "Summer Product Launch",
    "description": "Promote our new summer collection",
    "budget": "5000.00",
    "start_date": "2024-06-01",
    "end_date": "2024-08-31"
  }'

Place a Bid (Authenticated)

curl -X POST http://localhost:8000/apis/bids/create/ \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access_token>" \
  -d '{
    "campaign": "<campaign_uuid>",
    "amount": "1500.00"
  }'

πŸ§ͺ Testing

Run the test suite:

python manage.py test

Run tests for a specific app:

python manage.py test apis

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ Development Notes

Security Considerations

  • Change SECRET_KEY in production
  • Set DEBUG = False in production
  • Use environment variables for sensitive data
  • Update ALLOWED_HOSTS for production deployment
  • Use a production-grade database (PostgreSQL, MySQL)
  • Implement rate limiting for API endpoints
  • Review and update CORS settings

Production Deployment

  1. Set up a production database
  2. Configure static files serving
  3. Set up media files storage (e.g., AWS S3)
  4. Configure Redis for Channels
  5. Use a production ASGI server (e.g., Daphne, uvicorn)
  6. Set up SSL/TLS certificates
  7. Configure environment variables
  8. Set up logging and monitoring

πŸ‘₯ Authors

Uman Sheikh, Hamza Shafique

πŸ“ž Support

For support, please open an issue or contact the development team.

πŸ”„ Version History

  • v1.0.0 - Initial release with core functionality

Note: This is a development setup. Please ensure proper security measures and configurations before deploying to production.

About

This is a part of our FYP Project

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages