A modern, full-stack social media application featuring a FastAPI-powered backend with asynchronous database support and a streamlined Streamlit frontend.
- 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.
- Framework: FastAPI (Asynchronous)
- Database: PostgreSQL (using
asyncpgandSQLAlchemy) - Authentication: FastAPI-Users with JWT tokens.
- Storage/CDN: ImageKit.io for media hosting and transformations.
- Package Manager:
uvfor lightning-fast dependency management.
- Framework: Streamlit
- Communication: RESTful API calls to the FastAPI backend.
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) - Python 3.14+
- PostgreSQL database
- ImageKit.io account
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/"Using uv:
uv syncuv run uvicorn main:app --reloadThe backend will be available at http://localhost:8000. You can access the interactive API docs at http://localhost:8000/docs.
uv run streamlit run frontend.pyThe frontend will typically open at http://localhost:8501.
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).
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.
- Form Data:
DELETE /posts/delete/{post_id}: Delete a post.- Auth Required: Yes (must be the owner).
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.
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.pyNote: Ensure the backend server is running before executing tests.
This project is licensed under the terms included in the repository.