A RESTful API built with FastAPI for creating, managing, and interacting with social media posts
InstaAPI is a robust backend service for a social media application, providing secure and efficient endpoints for user management, post operations, and social interactions. The API implements full authentication, comprehensive CRUD operations, data validation, and detailed API documentation.
-
User Management
- Registration with secure password hashing
- Authentication using JWT tokens
- User profile retrieval
-
Post Operations
- Create, read, update, and delete posts
- Pagination and search functionality
- Ownership validation for secured operations
-
Social Interactions
- Vote/like system for posts
- Post metrics (vote count)
- Backend: Python with FastAPI
- Database: PostgreSQL
- ORM: SQLAlchemy
- Migration: Alembic
- Authentication: JWT using python-jose
- Containerization: Docker and Docker Compose
- Documentation: Auto-generated with Swagger UI and ReDoc
- Python 3.9+
- Docker and Docker Compose
- PostgreSQL
-
Clone the repository:
git clone https://github.com/yourusername/InstaAPI.git cd InstaAPI -
Set up environment variables: Create a
.envfile in the project root with the following variables:DATABASE_HOSTNAME=postgres DATABASE_PORT=5432 DATABASE_NAME=InstaAPI DATABASE_USERNAME=yourusername DATABASE_PASSWORD=yourpassword SECRET_KEY=yoursecretkey ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=60 -
Run with Docker Compose (recommended):
# For development docker compose -f docker-compose-dev.yaml up -d # For production docker compose -f docker-compose-prod.yaml up -d -
Or set up a local development environment:
python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt uvicorn app.main:app --reload -
Run database migrations:
alembic upgrade head
Once the server is running, access the interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
# Create a new migration
alembic revision --autogenerate -m "description"
# Apply migrations
alembic upgrade head
# Rollback migration
alembic downgrade -1
pytest
ruff check --fix
ruff format
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.