Skip to content

rastar12/simple-insta

Repository files navigation

Simple Social (InstaBackend)

A modern, full-stack social media application featuring a FastAPI-powered backend with asynchronous database support and a streamlined Streamlit frontend.

🚀 Features

  • User Authentication: Robust JWT-based authentication using fastapi-users.
  • Media Management: Seamless image and video uploads powered by ImageKit.io.
  • Real-time Feed: A global feed showing posts from all users, ordered by creation date.
  • Caption Overlays: Automatic text-on-image caption overlays for uploaded media.
  • Post Ownership: Users can delete their own posts directly from the feed.
  • Modern Tech Stack: Built with Python 3.14+, FastAPI, SQLAlchemy, and Streamlit.

🛠️ Architecture & Tech Stack

Backend

  • Framework: FastAPI (Asynchronous)
  • Database: PostgreSQL (using asyncpg and SQLAlchemy)
  • Authentication: FastAPI-Users with JWT tokens.
  • Storage/CDN: ImageKit.io for media hosting and transformations.
  • Package Manager: uv for lightning-fast dependency management.

Frontend

  • Framework: Streamlit
  • Communication: RESTful API calls to the FastAPI backend.

📂 Project Structure

simpleSocial/ ├── app/ │ ├── db.py # Database models (User, Post) and session management │ ├── images.py # ImageKit.io configuration │ ├── main.py # Main FastAPI app configuration and router registration │ ├── schemas.py # Pydantic models for data validation │ ├── users.py # FastAPI-Users setup (UserManager, Auth Backend) │ └── routers/ │ └── posts.py # Post-related API endpoints (upload, feed, delete) ├── main.py # Entry point for the backend (Uvicorn) ├── frontend.py # Streamlit frontend application ├── pyproject.toml # Project dependencies and metadata └── .env # Environment variables (required) 

⚙️ Setup & Installation

1. Prerequisites

2. Environment Configuration

Create a .env file in the root directory and populate it with your credentials:

DATABASE_URL="postgresql+asyncpg://user:password@host/dbname?ssl=require" SECRET_KEY="your-secret-key-for-jwt" IMAGE_KIT_PRIVATE_KEY="your-imagekit-private-key" IMAGE_KIT_PUBLIC_KEY="your-imagekit-public-key" IMAGE_KIT_URL="https://ik.imagekit.io/your-endpoint-id/"

3. Install Dependencies

Using uv:

uv sync

🏃 Running the Application

Start the Backend

uv run uvicorn main:app --reload

The backend will be available at http://localhost:8000. You can access the interactive API docs at http://localhost:8000/docs.

Start the Frontend

uv run streamlit run frontend.py

The frontend will typically open at http://localhost:8501.


📡 API Endpoints

Authentication

  • POST /auth/register: Create a new user account.
  • POST /auth/jwt/login: Authenticate and receive a JWT token.
  • GET /users/me: Retrieve current user details (Requires Auth).

Posts

  • GET /posts/feed: Get all posts with user details and ownership status.
  • POST /posts/upload: Upload an image/video.
    • Form Data: file (UploadFile), caption (string).
    • Auth Required: Yes.
  • DELETE /posts/delete/{post_id}: Delete a post.
    • Auth Required: Yes (must be the owner).

🎨 Media Transformations

The application leverages ImageKit.io for real-time transformations:

  • Images: Automatically resized and displayed with a semi-transparent caption overlay at the bottom.
  • Videos: Resized and padded with a blurred background for a consistent aspect ratio in the feed.

🧪 Testing

The repository includes basic test scripts to verify backend functionality:

  • test_register.py: A simple standalone script to test the user registration endpoint (/auth/register).

To run the registration test:

python test_register.py

Note: Ensure the backend server is running before executing tests.


📜 License

This project is licensed under the terms included in the repository.

About

A simple Instagram app for sharing photos using fastapi

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages