Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Instagram-Flask

A full-featured Instagram-like backend REST API built with Python Flask framework, featuring real-time chat, stories, posts, and comprehensive social media functionality.

๐Ÿš€ Features

๐Ÿ” Authentication & User Management

  • User Registration & Login: Email/phone-based authentication with JWT tokens
  • Profile Management: Update profile pictures, personal information, and settings
  • Password Management: Forgot password with OTP verification, password reset
  • Account Security: JWT token management with blocklist support
  • User Validation: Email, phone, and username validation

๐Ÿ“ฑ Posts & Content

  • Post Creation: Upload multiple images with captions and location
  • Hashtag Support: Automatic hashtag parsing and trending
  • Post Interactions: Like, unlike, save, and unsave posts
  • Image Processing: Automatic image compression and optimization
  • Post Management: Edit, delete, and retrieve user posts

๐Ÿ’ฌ Social Features

  • Follow System: Follow/unfollow users with activity tracking
  • Feed Generation: Personalized feed based on following relationships
  • Explore Page: Discover new content from non-followed users
  • Activity Tracking: Comprehensive activity logging for social interactions

๐Ÿ“– Stories

  • Story Creation: Upload and share 24-hour stories
  • Story Views: Track who viewed your stories
  • Story Discovery: View stories from followed users
  • Story Management: Automatic expiration after 24 hours

๐Ÿ’ญ Comments & Interactions

  • Comment System: Add comments to posts with pagination
  • Reply Comments: Nested comment replies
  • Comment Likes: Like/unlike comments and replies
  • Comment Management: Edit and delete comments

๐Ÿ’ฌ Real-time Chat

  • Direct Messaging: Private conversations between users
  • Chat Rooms: Create and manage chat sessions
  • Real-time Updates: WebSocket-based instant messaging
  • Message History: Persistent chat storage and retrieval

๐Ÿ”” Notifications & Activities

  • Activity Feed: Track all social interactions
  • Push Notifications: Firebase integration for mobile notifications
  • Real-time Updates: Live notification delivery

๐Ÿ—„๏ธ Database & Performance

  • PostgreSQL Database: Robust relational database with SQLAlchemy ORM
  • Database Migrations: Alembic-based schema management
  • Background Tasks: Celery integration for async operations
  • Image Optimization: Automatic image compression and processing

๐Ÿ”ง Technical Features

  • RESTful API: Comprehensive API documentation with Swagger/OpenAPI
  • JWT Authentication: Secure token-based authentication
  • File Upload: Secure file handling with validation
  • Pagination: Efficient data retrieval with pagination support
  • Error Handling: Comprehensive error handling and validation
  • API Documentation: Auto-generated Swagger UI documentation

๐Ÿ› ๏ธ Technology Stack

  • Backend Framework: Flask 3.0.0
  • Database: PostgreSQL with SQLAlchemy ORM
  • Authentication: JWT with Flask-JWT-Extended
  • Real-time: Flask-SocketIO for WebSocket support
  • Background Tasks: Celery for async operations
  • File Processing: Pillow for image manipulation
  • API Documentation: Flask-Smorest with OpenAPI/Swagger
  • Push Notifications: Firebase Admin SDK
  • Database Migrations: Alembic
  • Image Storage: Local file system with compression

๐Ÿ“‹ Prerequisites

Before running this application, make sure you have:

  • Python 3.8+ installed
  • PostgreSQL database server running
  • Redis server (for Celery background tasks)
  • Firebase Admin SDK credentials file (firebase-adminsdk.json)

๐Ÿš€ Installation

1. Clone the Repository

git clone <repository-url>
cd instagram-flask-main

2. Create Virtual Environment

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Environment Configuration

Create a .env file in the root directory with the following variables:

# Flask Configuration
FLASK_APP=app
FLASK_DEBUG=True

# Database Configuration
DATABASE_URL=postgresql://username:password@localhost:5432/instagram_db

# JWT Configuration
JWT_SECRET_KEY=your-secret-key-here
JWT_ACCESS_TOKEN_EXPIRES=15m
JWT_REFRESH_TOKEN_EXPIRES=30d

# API Configuration
API_TITLE=Instagram Flask API
API_VERSION=1.0.0
OPENAPI_VERSION=3.0.2
OPENAPI_URL_PREFIX=/

# Celery Configuration
CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/0

# Firebase Configuration
FIREBASE_CREDENTIALS_PATH=firebase-adminsdk.json

5. Database Setup

# Create PostgreSQL database
createdb instagram_db

# Run database migrations
flask db upgrade

6. Firebase Setup

  • Download your Firebase Admin SDK service account key
  • Rename it to firebase-adminsdk.json
  • Place it in the root directory

๐Ÿƒโ€โ™‚๏ธ Running the Application

1. Start Redis Server

redis-server

2. Start Celery Worker (in a new terminal)

celery -A app.celery worker --loglevel=info

3. Start the Flask Application

flask run

4. Start Socket.IO Server (in a new terminal)

python -c "from app import create_app; from socket_utils import mysocket; app = create_app(); mysocket.run(app, debug=True)"

๐Ÿ“š API Endpoints

Authentication

  • POST /signup - User registration
  • POST /login - User login
  • POST /logout - User logout
  • POST /refresh - Refresh JWT token
  • POST /forgot-password - Request password reset
  • POST /verify-otp - Verify OTP for password reset
  • POST /reset-password - Reset password with OTP

User Management

  • GET /profile - Get user profile
  • PUT /profile - Update user profile
  • PUT /profile-pic - Update profile picture
  • POST /change-password - Change password
  • GET /username-check/<username> - Check username availability

Posts

  • POST /posts - Create a new post
  • GET /posts - Get user posts
  • GET /post/<post_id> - Get specific post
  • DELETE /post/<post_id> - Delete post
  • POST /post/<post_id>/like - Like a post
  • DELETE /post/<post_id>/like - Unlike a post
  • POST /post/<post_id>/save - Save a post
  • DELETE /post/<post_id>/save - Unsave a post

Stories

  • POST /stories - Create a new story
  • GET /stories - Get feed stories
  • GET /my-stories - Get user's stories
  • GET /user-stories/<user_id> - Get specific user's stories
  • POST /story/<story_id>/view - Mark story as viewed

Comments

  • POST /post_comment/<post_id> - Add comment to post
  • GET /post_comment/<post_id> - Get post comments
  • PUT /comment/<comment_id> - Edit comment
  • DELETE /comment/<comment_id> - Delete comment
  • POST /comment/<comment_id>/like - Like a comment
  • DELETE /comment/<comment_id>/like - Unlike a comment

Reply Comments

  • POST /reply_comment/<comment_id> - Reply to a comment
  • GET /reply_comment/<comment_id> - Get comment replies
  • PUT /replies/<reply_id> - Edit reply
  • DELETE /replies/<reply_id> - Delete reply
  • POST /reply/<reply_id>/like - Like a reply
  • DELETE /reply/<reply_id>/like - Unlike a reply

Followers

  • POST /follow/<user_id> - Follow a user
  • DELETE /unfollow/<user_id> - Unfollow a user
  • GET /follow/<user_id> - Get user's following list

Feeds

  • GET /feed - Get personalized feed
  • GET /explore - Get explore page content
  • GET /search - Search users and hashtags
  • GET /activity - Get user activity feed

Chat

  • GET /viewchats - Get user's chat rooms
  • POST /newchat/<user_id> - Create new chat room
  • GET /chat/<room_id> - Get chat messages
  • POST /chat/<room_id> - Send message

๐Ÿ”ง Configuration Options

Database Configuration

  • PostgreSQL: Configure connection string in .env
  • Migrations: Use flask db commands for schema management

JWT Configuration

  • Token Expiry: Configure access and refresh token lifetimes
  • Secret Key: Set secure JWT secret key

File Upload Configuration

  • Supported Formats: Images (JPEG, PNG, GIF)
  • File Size Limits: Configurable upload limits
  • Storage Path: Local file system with compression

Celery Configuration

  • Broker: Redis for task queue
  • Workers: Configure number of worker processes
  • Task Timeouts: Set appropriate task timeouts

๐Ÿงช Testing

Run Tests

# Install test dependencies
pip install pytest pytest-flask

# Run tests
pytest

API Testing

  • Use the built-in Swagger UI at /swagger-ui for API testing
  • Import the OpenAPI specification into tools like Postman

๐Ÿ“ฆ Deployment

Production Setup

  1. Environment Variables: Set production environment variables
  2. Database: Use production PostgreSQL instance
  3. Redis: Configure production Redis server
  4. Web Server: Use Gunicorn with proper WSGI configuration
  5. Static Files: Configure proper static file serving
  6. Security: Enable HTTPS and security headers

Docker Deployment

# Build Docker image
docker build -t instagram-flask .

# Run with Docker Compose
docker-compose up -d

๐Ÿค Contributing

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

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

If you encounter any issues or have questions:

  1. Check the API documentation at /swagger-ui
  2. Review the error logs
  3. Check database connectivity
  4. Verify environment configuration
  5. Open an issue on GitHub

๐Ÿ”ฎ Future Enhancements

  • Video Support: Add video upload and processing
  • Live Streaming: Real-time video streaming capabilities
  • Advanced Analytics: User engagement and content analytics
  • Machine Learning: Content recommendation algorithms
  • Microservices: Break down into microservice architecture
  • GraphQL: Add GraphQL API support
  • Mobile SDK: Native mobile application SDKs

Note: This is a comprehensive Instagram-like backend API. Make sure to configure all required services (PostgreSQL, Redis, Firebase) before running the application.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages