Skip to content

Girik1105/EntreHive_BackEnd

 
 

Repository files navigation

EntreHive Backend

Django REST API powering the EntreHive social platform for students, professors, and investors.

Live Demo Django DRF Python

Links

Table of Contents

Overview

EntreHive Backend is a comprehensive Django REST API that powers the EntreHive platform. It provides a robust, scalable backend with role-based access control, real-time notifications, messaging system, and social networking features tailored for the entrepreneurial ecosystem.

Features

Authentication & Authorization

  • JWT-based authentication with refresh tokens
  • Email verification system
  • Password reset functionality
  • Role-based access control (Student, Professor, Investor)
  • Permission-based API endpoints

User Management

  • User profiles with customizable information
  • Profile pictures and banners
  • University affiliation
  • Bio and social links
  • Follow/unfollow system
  • Public/private profile settings

Social Features

  • Post creation with rich content
  • Image uploads for posts and projects
  • Comment and reply system
  • Like functionality
  • Post sharing
  • Hashtag support
  • Visibility controls (public/university-only)

Project Management

  • Create and manage entrepreneurial projects
  • Project types: Startup, Research, Social Impact, Tech Innovation
  • Team management and invitations
  • Project status tracking
  • Rich project profiles with banners
  • Project discovery and search
  • Categories and tagging system

Messaging System

  • Direct Conversations: 1-on-1 messaging
  • Group Conversations: Team-based messaging for projects
  • Project View Requests: Permission-based access system
  • Message read receipts
  • Unread message tracking
  • Permission management for messaging

Notifications

  • Real-time notification system
  • Notification types:
    • Likes and comments
    • New followers
    • Project invitations
    • Messages
    • Project view requests
  • Read/unread status
  • Bulk operations

Search & Discovery

  • Global search across users, posts, and projects
  • Advanced filtering
  • Hashtag search
  • Category-based project search
  • University-based filtering

Tech Stack

Core Framework

  • Django 5.2.6 - Web framework
  • Django REST Framework 3.16.1 - API framework
  • Python 3.10+ - Programming language

Authentication

  • djangorestframework-simplejwt 5.5.1 - JWT authentication
  • dj-rest-auth 7.0.1 - REST auth endpoints
  • django-allauth 65.11.2 - Authentication system

Database

  • PostgreSQL - Production database (via psycopg 3.2.10)
  • SQLite - Development database

Additional Libraries

  • django-cors-headers 4.8.0 - CORS handling
  • django-filter 25.1 - Advanced filtering
  • Pillow 11.3.0 - Image processing
  • python-dotenv 1.1.1 - Environment variable management

Getting Started

Prerequisites

  • Python 3.10 or higher
  • PostgreSQL (for production) or SQLite (for development)
  • pip package manager
  • Virtual environment (recommended)

Installation

  1. Clone the repository

    git clone https://github.com/Aadit-Chadda/EntreHive_backend.git
    cd EntreHive_backend
  2. Create a virtual environment

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

    pip install -r requirements.txt
  4. Set up environment variables

    Create a .env file in the root directory:

    # Django Settings
    SECRET_KEY=your-secret-key-here
    DEBUG=True
    ALLOWED_HOSTS=localhost,127.0.0.1
    
    # CORS Settings
    CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
    
    # Database (PostgreSQL for production)
    # DATABASE_URL=postgresql://user:password@localhost:5432/entrehive
    
    # Email Configuration
    EMAIL_HOST=smtp.gmail.com
    EMAIL_PORT=587
    EMAIL_USE_TLS=True
    EMAIL_HOST_USER=[email protected]
    EMAIL_HOST_PASSWORD=your-app-password
    DEFAULT_FROM_EMAIL=[email protected]
    
    # Frontend URL
    FRONTEND_URL=http://localhost:3000
  5. Run database migrations

    python manage.py makemigrations
    python manage.py migrate
  6. Create a superuser (optional)

    python manage.py createsuperuser
  7. Run the development server

    python manage.py runserver
  8. Access the API

    Navigate to http://localhost:8000/api/

Running Tests

# Run all tests
python manage.py test

# Run specific app tests
python manage.py test accounts
python manage.py test posts
python manage.py test projects

Project Structure

entrehive_backend/
├── accounts/                    # User management app
│   ├── models.py               # UserProfile, Follow models
│   ├── views.py                # User endpoints
│   ├── serializers.py          # User serializers
│   └── urls.py                 # User routes
├── posts/                       # Social posts app
│   ├── models.py               # Post, Comment, Like models
│   ├── views.py                # Post endpoints
│   ├── serializers.py          # Post serializers
│   └── urls.py                 # Post routes
├── projects/                    # Project management app
│   ├── models.py               # Project, ProjectInvitation models
│   ├── views.py                # Project endpoints
│   ├── serializers.py          # Project serializers
│   └── urls.py                 # Project routes
├── messaging/                   # Messaging system app
│   ├── models.py               # Conversation, Message, GroupConversation models
│   ├── views.py                # Messaging endpoints
│   ├── serializers.py          # Messaging serializers
│   └── urls.py                 # Messaging routes
├── notifications/               # Notification system app
│   ├── models.py               # Notification model
│   ├── views.py                # Notification endpoints
│   ├── serializers.py          # Notification serializers
│   └── urls.py                 # Notification routes
├── feed/                        # Feed algorithm app
│   ├── views.py                # Feed endpoints
│   └── utils.py                # Feed scoring logic
├── universities/                # University data app
│   ├── models.py               # University model
│   └── admin.py                # Admin interface
├── contact/                     # Contact form app
│   ├── models.py               # ContactSubmission model
│   └── views.py                # Contact endpoints
├── entrehive_backend/          # Project settings
│   ├── settings.py             # Django settings
│   ├── urls.py                 # Main URL configuration
│   └── wsgi.py                 # WSGI configuration
├── media/                       # User-uploaded files
├── static/                      # Static files
├── manage.py                    # Django management script
├── requirements.txt             # Python dependencies
├── .env                         # Environment variables (create this)
└── README.md                    # This file

Django Apps

accounts

User authentication, profiles, and social features

  • User profile management
  • Email verification
  • Follow/unfollow system
  • Profile customization
  • User search

posts

Social networking features

  • Post creation and management
  • Comments and replies
  • Like system
  • Post sharing
  • Hashtag support
  • Feed integration

projects

Entrepreneurial project management

  • Project CRUD operations
  • Team management
  • Project invitations
  • Project search and discovery
  • Categories and tags
  • Status tracking

messaging

Communication system

  • Direct messaging (1-on-1)
  • Group conversations (team chats)
  • Project view requests
  • Message permissions
  • Read receipts
  • Unread counts

notifications

Real-time notification system

  • Multiple notification types
  • Read/unread tracking
  • Bulk operations
  • User preferences

feed

Curated content feed

  • Engagement-based scoring
  • User preferences
  • University-based filtering
  • Personalized recommendations

universities

University data management

  • University information
  • Student affiliation
  • University-based filtering

contact

Contact form handling

  • Contact submissions
  • Admin management

Environment Variables

Create a .env file with the following variables:

# Django Core
SECRET_KEY=your-django-secret-key
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1

# Database (PostgreSQL for production)
DATABASE_URL=postgresql://username:password@localhost:5432/entrehive
# Or use SQLite for development (default)

# CORS Configuration
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000

# Email Configuration
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USE_TLS=True
EMAIL_HOST_USER=[email protected]
EMAIL_HOST_PASSWORD=your-app-password
DEFAULT_FROM_EMAIL=[email protected]

# Frontend URL
FRONTEND_URL=http://localhost:3000

# Optional: AWS S3 Configuration for media files
# AWS_ACCESS_KEY_ID=your-access-key
# AWS_SECRET_ACCESS_KEY=your-secret-key
# AWS_STORAGE_BUCKET_NAME=your-bucket-name
# AWS_S3_REGION_NAME=us-east-1

Database Models

accounts.UserProfile

Extended user profile with additional information

- user (OneToOne -> User)
- profile_picture (ImageField)
- banner_image (ImageField)
- bio (TextField)
- university (ForeignKey -> University)
- user_role (CharField: student/professor/investor)
- linkedin_url, github_url, website_url
- is_profile_public (Boolean)
- email_verified (Boolean)

posts.Post

Social media posts

- author (ForeignKey -> User)
- content (TextField)
- image_url (URLField)
- visibility (CharField: public/university)
- tagged_projects (ManyToMany -> Project)
- created_at, updated_at

projects.Project

Entrepreneurial projects

- owner (ForeignKey -> User)
- title, summary (CharField, TextField)
- project_type (CharField: startup/research/social_impact/tech_innovation)
- status (CharField: planning/active/completed/on_hold)
- team_members (ManyToMany -> User)
- banner_image, preview_image (ImageField)
- categories, tags, needs (JSONField)
- visibility (CharField)
- university (ForeignKey -> University)

messaging.Conversation

Direct 1-on-1 conversations

- participant_1, participant_2 (ForeignKey -> User)
- initiated_by (ForeignKey -> User)
- related_project (ForeignKey -> Project, optional)
- status (CharField: active/archived)
- created_at, updated_at, last_message_at

messaging.GroupConversation

Team-based group messaging

- project (ForeignKey -> Project)
- created_by (ForeignKey -> User)
- participants (ManyToMany -> User)
- created_at, updated_at, last_message_at

notifications.Notification

User notifications

- recipient (ForeignKey -> User)
- sender (ForeignKey -> User)
- notification_type (CharField)
- post, project, comment (ForeignKey, optional)
- message (TextField)
- is_read (Boolean)
- created_at

API Endpoints

Authentication

POST   /api/auth/registration/              # Register new user
POST   /api/auth/login/                      # Login
POST   /api/auth/logout/                     # Logout
POST   /api/auth/password/reset/             # Request password reset
POST   /api/auth/password/reset/confirm/     # Confirm password reset
POST   /api/auth/token/refresh/              # Refresh JWT token
GET    /api/accounts/verify-email/<key>/    # Verify email

User Profiles

GET    /api/accounts/profile/                # Get current user profile
PUT    /api/accounts/profile/                # Update profile
GET    /api/accounts/profile/<username>/     # Get user by username
POST   /api/accounts/follow/<username>/      # Follow user
DELETE /api/accounts/unfollow/<username>/    # Unfollow user
GET    /api/accounts/followers/              # Get followers
GET    /api/accounts/following/              # Get following
GET    /api/accounts/search/                 # Search users, posts, projects

Posts

GET    /api/posts/                           # List posts
POST   /api/posts/                           # Create post
GET    /api/posts/<id>/                      # Get post detail
PUT    /api/posts/<id>/                      # Update post
DELETE /api/posts/<id>/                      # Delete post
POST   /api/posts/<id>/like/                 # Toggle like
GET    /api/posts/<id>/likes/                # Get likes
POST   /api/posts/<id>/share/                # Share post
GET    /api/posts/feed/                      # Get curated feed
GET    /api/posts/my_posts/                  # Get user's posts
GET    /api/search/                          # Search posts

Comments

GET    /api/posts/<post_id>/comments/        # List comments
POST   /api/posts/<post_id>/comments/        # Create comment
PUT    /api/posts/<post_id>/comments/<id>/   # Update comment
DELETE /api/posts/<post_id>/comments/<id>/   # Delete comment

Projects

GET    /api/projects/                        # List projects
POST   /api/projects/                        # Create project
GET    /api/projects/<id>/                   # Get project detail
PUT    /api/projects/<id>/                   # Update project
DELETE /api/projects/<id>/                   # Delete project
GET    /api/projects/my_projects/            # Get user's projects
POST   /api/projects/<id>/add_team_member/   # Add team member
DELETE /api/projects/<id>/remove_team_member/ # Remove team member
GET    /api/projects/search/                 # Search projects

Messaging

GET    /api/messaging/conversations/         # List conversations
POST   /api/messaging/conversations/create/  # Create conversation
GET    /api/messaging/conversations/<id>/    # Get conversation detail
POST   /api/messaging/conversations/<id>/messages/create/ # Send message
GET    /api/messaging/group-conversations/   # List group conversations
POST   /api/messaging/group-conversations/create/ # Create group
GET    /api/messaging/group-conversations/<id>/ # Get group detail
POST   /api/messaging/group-conversations/<id>/messages/create/ # Send group message
GET    /api/messaging/project-view-requests/ # List view requests
POST   /api/messaging/project-view-requests/create/ # Create request
POST   /api/messaging/project-view-requests/<id>/respond/ # Respond to request

Notifications

GET    /api/notifications/                   # List notifications
GET    /api/notifications/<id>/              # Get notification detail
POST   /api/notifications/<id>/mark_as_read/ # Mark as read
POST   /api/notifications/mark_all_as_read/  # Mark all as read
GET    /api/notifications/unread_count/      # Get unread count

Feed

GET    /api/feed/                            # Get curated feed
GET    /api/feed/trending/                   # Get trending topics

Authentication

The API uses JWT (JSON Web Tokens) for authentication:

  1. Register: POST /api/auth/registration/
  2. Login: POST /api/auth/login/ - Returns access and refresh tokens
  3. Use Token: Include in headers: Authorization: Bearer <access_token>
  4. Refresh: POST /api/auth/token/refresh/ - Get new access token

Example Authentication Flow

# Register
POST /api/auth/registration/
{
  "username": "johndoe",
  "email": "[email protected]",
  "password1": "securepassword123",
  "password2": "securepassword123"
}

# Login
POST /api/auth/login/
{
  "username": "johndoe",
  "password": "securepassword123"
}

# Response
{
  "access": "eyJ0eXAiOiJKV1QiLCJhbGc...",
  "refresh": "eyJ0eXAiOiJKV1QiLCJhbGc...",
  "user": {...}
}

# Use token in subsequent requests
GET /api/accounts/profile/
Headers: Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGc...

Deployment

Production Checklist

  1. Environment Variables

    • Set DEBUG=False
    • Configure ALLOWED_HOSTS
    • Set strong SECRET_KEY
    • Configure production database
    • Set up email service
    • Configure AWS S3 for media files
  2. Database

    • Run migrations: python manage.py migrate
    • Create superuser: python manage.py createsuperuser
  3. Static Files

    python manage.py collectstatic
  4. Security

    • Enable HTTPS
    • Configure CORS properly
    • Set secure cookie settings
    • Enable CSRF protection
  5. Server

    • Use gunicorn or uwsgi
    • Set up nginx reverse proxy
    • Configure SSL certificates

Example Gunicorn Configuration

gunicorn entrehive_backend.wsgi:application \
  --bind 0.0.0.0:8000 \
  --workers 4 \
  --timeout 120

Contributing

We welcome contributions to EntreHive Backend!

Development Workflow

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/your-feature-name
  3. Make your changes
  4. Run tests
    python manage.py test
  5. Commit with clear messages
    git commit -m "Add feature: your feature description"
  6. Push to your fork
    git push origin feature/your-feature-name
  7. Create a Pull Request

Code Style

  • Follow PEP 8 guidelines
  • Use meaningful variable and function names
  • Add docstrings to classes and methods
  • Write unit tests for new features
  • Keep functions focused and modular

Database Migrations

Always create migrations when modifying models:

python manage.py makemigrations
python manage.py migrate

Admin Interface

Access the Django admin panel at /admin/:

# Create superuser
python manage.py createsuperuser

# Access admin panel
http://localhost:8000/admin/

Manage:

  • Users and profiles
  • Posts and comments
  • Projects and teams
  • Messages and conversations
  • Notifications
  • Contact submissions

License

This project is part of EntreHive platform.

Acknowledgments

  • Built with Django and Django REST Framework
  • Authentication powered by SimpleJWT
  • Image handling with Pillow
  • Database powered by PostgreSQL

Questions or Issues? Please open an issue in the GitHub repository.

Frontend Repository: EntreHive Frontend

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 94.1%
  • HTML 5.9%