Skip to content

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

12 Commits

Folders and files

Repository files navigation

🌐 PeopleConnects - Advanced Social Media Platform

A beginner-friendly, fully-featured social media web application built with FastAPI (Python backend), MongoDB (database), and Bootstrap 5 + HTML (frontend).

πŸŽ‰ Version 2.0 - Complete Feature Set

✨ All Features Implemented

πŸ” Authentication & Security

  • βœ… User Registration with validation
  • βœ… Login with JWT tokens
  • βœ… Password hashing (bcrypt)
  • βœ… Secure cookie sessions
  • βœ… Error messages for wrong credentials

πŸ‘€ User Profiles

  • βœ… Profile pictures (upload & change)
  • βœ… Edit profile (username, email, password)
  • βœ… Unique username validation
  • βœ… Follower/following counts and lists
  • βœ… Profile picture display everywhere

πŸ“ Post System

  • βœ… Create text posts
  • βœ… Upload images with posts
  • βœ… Individual post pages (/posts/{post_id})
  • βœ… Like/unlike toggle button
  • βœ… Comment on posts
  • βœ… Author profile pictures

πŸ“° Feed System

  • βœ… Global feed (all posts)
  • βœ… Following filter (personalized)
  • βœ… Popular filter (most-liked)
  • βœ… Recent filter (last 24 hours)

πŸ‘₯ Follower System

  • βœ… Follow/unfollow users
  • βœ… Clickable follower lists
  • βœ… Clickable following lists
  • βœ… Profile pictures in lists

πŸ” Search Functionality

  • βœ… Search users by username
  • βœ… Search posts by content
  • βœ… Case-insensitive search
  • βœ… Results page with counts

πŸ›‘οΈ Admin Dashboard

  • βœ… Admin login (admin / admin123)
  • βœ… User statistics
  • βœ… Post statistics
  • βœ… Most liked posts
  • βœ… User management (delete)
  • βœ… Post management (delete)

🎨 Professional UI/UX

  • βœ… Bootstrap 5 framework
  • βœ… Bootstrap Icons (no emojis!)
  • βœ… Responsive mobile design
  • βœ… Clean color scheme
  • βœ… Smooth animations
  • βœ… Professional typography

⚑ Performance & Optimization

  • βœ… MongoDB indexes
  • βœ… Query pagination
  • βœ… Image optimization
  • βœ… Fast database queries
  • βœ… Efficient aggregations

πŸ“ Project Structure

peoplesconnect_1/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py          # FastAPI routes and application
β”‚   β”œβ”€β”€ database.py      # MongoDB connection and indexes
β”‚   β”œβ”€β”€ models.py        # Pydantic models for validation
β”‚   └── auth.py          # Authentication utilities (JWT, password hashing)
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ base.html        # Base template with navbar/footer
β”‚   β”œβ”€β”€ navbar.html      # Navigation bar component
β”‚   β”œβ”€β”€ footer.html      # Footer component
β”‚   β”œβ”€β”€ index.html       # Landing page
β”‚   β”œβ”€β”€ register.html    # User registration
β”‚   β”œβ”€β”€ login.html       # User login
β”‚   β”œβ”€β”€ feed.html        # Main feed with posts
β”‚   β”œβ”€β”€ post_detail.html # Individual post page
β”‚   β”œβ”€β”€ profile.html     # User profile page
β”‚   β”œβ”€β”€ admin_login.html # Admin login page
β”‚   └── admin_dashboard.html # Admin dashboard
β”œβ”€β”€ static/
β”‚   └── css/
β”‚       └── style.css    # Custom CSS styles
β”œβ”€β”€ requirements.txt     # Python dependencies
β”œβ”€β”€ .env.example         # Environment variables template
β”œβ”€β”€ .gitignore          # Git ignore rules
└── README.md           # This file

πŸ—ƒοΈ MongoDB Database Schemas

Users Collection

{
  "_id": ObjectId,
  "username": String (unique, indexed),
  "email": String (unique, indexed),
  "password": String (hashed),
  "profile_pic": String,      // NEW: URL to profile picture
  "followers": [String],      // Array of usernames
  "following": [String],      // Array of usernames
  "created_at": DateTime
}

Posts Collection

{
  "_id": ObjectId,
  "author": String (indexed),
  "content": String (max 500 chars),
  "image": String,            // NEW: URL to post image
  "timestamp": DateTime (indexed, descending),
  "likes": [String],          // Array of usernames
  "comments": [
    {
      "username": String,
      "text": String (max 200 chars),
      "timestamp": DateTime
    }
  ]
}

Database Indexes (Auto-created on startup)

# Users collection
db.users.create_index("username", unique=True)
db.users.create_index("email", unique=True)

# Posts collection
db.posts.create_index([("timestamp", -1)])  # Sort by newest
db.posts.create_index("author")             # Filter by author

πŸš€ Installation & Setup

Prerequisites

  • Python 3.8+
  • MongoDB (running on localhost:27017)

Quick Start (Windows)

  1. Test your setup:

    python test_setup.py
  2. Start the application:

    • Double-click start.bat, OR
    • Run manually:
      cd backend
      python -m uvicorn backend.main:app --reload --port 8000
  3. Open browser: http://localhost:8000

Manual Setup

Step 1: Install Dependencies

pip install -r requirements.txt

Step 2: Start MongoDB

Make sure MongoDB is running:

# Windows (if MongoDB is installed as service)
net start MongoDB

# Linux/Mac
sudo systemctl start mongod
# or
mongod --dbpath /path/to/data/directory

Step 3: Verify Setup

python test_setup.py

This will check all dependencies, directories, and MongoDB connection.

Step 4: Run the Application

cd backend
python -m uvicorn main:app --reload

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

πŸ“š Additional Documentation

  • COMPLETE_GUIDE.md - Comprehensive feature documentation
  • DEPLOYMENT.md - Production deployment guide
  • FINAL_SUMMARY.md - Project completion summary
  • QUICKSTART.md - Quick setup guide

πŸ”‘ Admin Access

⚠️ Important: Change admin credentials in production by updating ADMIN_PASSWORD_HASH in backend/main.py


πŸ“š API Routes

Authentication

Method Route Description
GET / Home page
GET /register Registration page
POST /register Create new user
GET /login Login page
POST /login User login
GET /logout Logout user

Posts

Method Route Description
GET /feed View personalized feed
POST /posts/create Create new post (with optional image)
GET /posts/{post_id} View individual post
POST /posts/{post_id}/like Like/unlike post
POST /posts/{post_id}/comment Add comment

Profile & Followers

Method Route Description
GET /profile/{username} View user profile
POST /follow/{username} Follow user
POST /unfollow/{username} Unfollow user
POST /profile/upload-picture Upload/change profile picture

Admin

Method Route Description
GET /admin/login Admin login page
POST /admin/login Admin authentication
GET /admin/dashboard Admin dashboard
POST /admin/users/{user_id}/delete Delete user
POST /admin/posts/{post_id}/delete Delete post
GET /admin/logout Admin logout

🎯 Usage Examples

Creating a Post

  1. Login to your account
  2. Go to /feed
  3. Type your content (max 500 characters)
  4. Click "Post"

Following a User

  1. Visit their profile: /profile/{username}
  2. Click "Follow" button
  3. Their posts will appear in your feed

Admin Tasks

  1. Login at /admin/login
  2. View statistics on dashboard
  3. Manage users and posts
  4. Delete inappropriate content

⚑ Performance Optimizations

Database Optimizations

  1. Indexes: Added indexes on frequently queried fields

    • username and email for user lookups
    • timestamp for sorting posts
    • author for filtering posts
  2. Projection: Only fetch required fields

    # Example: Exclude password from user queries
    db.users.find({}, {"password": 0})
  3. Pagination: Limit results to prevent large data transfers

    # Limit to 50 posts
    db.posts.find().limit(50)
  4. Aggregation Pipeline: Efficient statistics queries

    # Get most liked posts
    db.posts.aggregate([
        {"$project": {"like_count": {"$size": "$likes"}}},
        {"$sort": {"like_count": -1}},
        {"$limit": 5}
    ])

πŸ› οΈ Technology Stack

Component Technology
Backend FastAPI (Python)
Database MongoDB (Motor async driver)
Frontend Bootstrap 5 + HTML + Jinja2
Authentication JWT (python-jose)
Password Hashing Bcrypt
Image Processing Pillow (PIL)
Server Uvicorn (ASGI)

πŸ“– Code Examples

Creating a New Route (Example)

# backend/main.py

@app.get("/custom-route")
async def custom_route(request: Request):
    username = get_current_user(request)
    if not username:
        return RedirectResponse("/login")
    
    # Your logic here
    return templates.TemplateResponse("custom.html", {
        "request": request,
        "username": username
    })

Adding a MongoDB Query (Example)

db = get_database()

# Find all posts by a user
posts = await db.posts.find({"author": username}).to_list(100)

# Update a post
await db.posts.update_one(
    {"_id": ObjectId(post_id)},
    {"$set": {"content": new_content}}
)

# Delete a post
await db.posts.delete_one({"_id": ObjectId(post_id)})

πŸ› Troubleshooting

MongoDB Connection Error

  • Ensure MongoDB is running: mongod --version
  • Check connection string in backend/database.py

Port Already in Use

# Change port when starting
uvicorn main:app --port 8001

Module Not Found

# Reinstall dependencies
pip install -r requirements.txt

πŸ“ License

This project is created for educational purposes. Feel free to modify and use it for learning.


πŸ‘¨β€πŸ’» Developer Notes

Running in Development

uvicorn main:app --reload --host 0.0.0.0 --port 8000

Testing Database Queries

# Use MongoDB Shell
mongosh
use peopleconnects
db.users.find()
db.posts.find().sort({timestamp: -1})

Resetting Database

// In MongoDB Shell
use peopleconnects
db.users.deleteMany({})
db.posts.deleteMany({})

πŸ“ž Support

For issues or questions:

  1. Check this README thoroughly
  2. Review the code comments in backend/ files
  3. Verify MongoDB is running and accessible
  4. Check FastAPI logs in terminal

Happy Coding! πŸš€

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages