A lightweight social media application built with FastAPI backend and Streamlit frontend, featuring user authentication, media uploads with ImageKit integration, and a real-time feed.
- User Authentication: Secure JWT-based authentication with FastAPI-Users
- Media Uploads: Support for images and videos with ImageKit CDN integration
- Social Feed: Real-time feed displaying posts from all users
- Image Transformation: Dynamic image transformations with caption overlays using ImageKit
- User Management: Register, login, password reset, and account verification
- Post Management: Create and delete your own posts
- Async Database: SQLite with async support (aiosqlite)
- FastAPI: Modern, fast web framework for building APIs
- FastAPI-Users: Ready-to-use authentication and user management
- SQLAlchemy: Async ORM with SQLite database
- Uvicorn: ASGI server for running FastAPI
- ImageKit: Cloud-based image and video storage/transformation service
- Python-dotenv: Environment variable management
- Streamlit: Fast way to build data apps and web interfaces
- Requests: HTTP library for API communication
- Python 3.14+
- ImageKit account (for media storage)
- UV package manager (recommended) or pip
- Clone the repository
git clone <repository-url>
cd fast-api-project- Create environment variables
Copy .env.example to .env and fill in your actual values:
cp .env.example .envEdit .env with your credentials:
# ImageKit Configuration
IMAGEKIT_PRIVATE_KEY=your_actual_private_key
IMAGEKIT_PUBLIC_KEY=your_actual_public_key
IMAGEKIT_URL=your_actual_url_endpoint
# Security
SECRET_KEY=your_secure_random_secret_key
# Database
DATABASE_URL=sqlite+aiosqlite:///./test.db
# API
API_URL=http://localhost:8000Note: .env is gitignored and will never be committed. .env.example is committed to show required variables.
- Install dependencies
Using UV:
uv syncOr using pip:
pip install -r requirements.txtuv run ./main.pyThe API will be available at http://localhost:8000
In a separate terminal:
uv run streamlit run frontend.pyThe web interface will be available at http://localhost:8501
fast-api-project/
├── app/
│ ├── app.py # Main FastAPI application and endpoints
│ ├── db.py # Database models and session management
│ ├── images.py # ImageKit configuration
│ ├── schemas.py # Pydantic schemas for validation
│ └── users.py # User authentication and management
├── frontend.py # Streamlit frontend application
├── main.py # FastAPI server entry point
├── pyproject.toml # Project dependencies and metadata
└── README.md # This file
POST /auth/register- Register a new userPOST /auth/jwt/login- Login and get JWT tokenPOST /auth/forgot-password- Request password resetPOST /auth/reset-password- Reset password with tokenPOST /auth/request-verify-token- Request email verification
GET /users/me- Get current user informationPATCH /users/me- Update current user
POST /upload- Upload a new image/video post with captionGET /feed- Get all posts in chronological orderDELETE /post/{post_id}- Delete a post (owner only)
id(UUID): Primary keyemail(String): User email (unique)hashed_password(String): Securely hashed passwordis_active(Boolean): Account statusis_superuser(Boolean): Admin privilegesis_verified(Boolean): Email verification status
id(UUID): Primary keyuser_id(UUID): Foreign key to Usercaption(Text): Post captionurl(String): ImageKit URLfile_type(String): "image" or "video"file_name(String): Original filenamecreated_at(DateTime): Timestamp
- Simple email/password authentication
- Combined login and registration interface
- Displays all posts in reverse chronological order
- Shows user email and post date
- Image transformations with caption overlays
- Delete button for own posts
- Uniform media display sizing
- File upload for images (PNG, JPG, JPEG) and videos (MP4, AVI, MOV, MKV, WEBM)
- Caption input field
- Real-time upload feedback
- JWT-based authentication with bearer tokens
- Password hashing with bcrypt
- Environment-based configuration (secrets in
.env, never committed) - Session state management in Streamlit
- Protected API endpoints requiring authentication
- Post ownership verification for delete operations
- Separation of
.env(secrets) and.env.example(public reference)
All sensitive configuration is managed through environment variables in .env:
| Variable | Purpose | Example |
|---|---|---|
IMAGEKIT_PRIVATE_KEY |
ImageKit API authentication | Get from ImageKit dashboard |
IMAGEKIT_PUBLIC_KEY |
ImageKit public identifier | Get from ImageKit dashboard |
IMAGEKIT_URL |
ImageKit URL endpoint | https://ik.imagekit.io/your_id |
SECRET_KEY |
JWT secret key | Generate: openssl rand -hex 32 |
DATABASE_URL |
Database connection string | sqlite+aiosqlite:///./test.db |
API_URL |
Backend API URL | http://localhost:8000 |
- Sign up at ImageKit.io
- Go to Settings → Developer Options
- Copy your Private Key, Public Key, and URL Endpoint
- Add them to your
.envfile
The application uses SQLite by default for development. The database file test.db will be created automatically on first run.
Both FastAPI and Streamlit support auto-reload during development:
- FastAPI:
reload=Trueis enabled in main.py - Streamlit: Auto-reloads on file changes by default