Social Media API is a powerful RESTful API for managing user profiles, posts, likes, comments, and subscriptions on a social media platform. This API allows the integration of core social platform features such as registration, logout, creating and editing posts, likes, comments, blocking users, and more.
- JWT Authentication ππ β secure access via tokens.
- Role-Based Access Control (RBAC) π₯π‘οΈβοΈ β detailed access control for resources.
- Filtration & Search πππ¬ β search users by username and filter posts by hashtags.
- Profile Management π§βπ»πβ¨ β view and edit profiles, set privacy preferences.
- Post Management πβοΈπΈ β create, edit, view posts, like and comment.
- Subscriptions & Blocking π«ππ€ β follow, unfollow, and block users.
- Celery for Background Tasks β³βοΈπ§ β process background tasks to optimize API performance.
- Redis π§ β‘π¨ β caching and task queue management using Redis in Celery.
- Flower πΈπΊπΌ β monitor Celery tasks through the Flower web interface.
ππ» Clone the repository to your local machine.
git clone https://github.com/your-username/social-media-api.git
cd social-media-apiπ±π» Set up a virtual environment for dependency management:
python -m venv venv
source venv/bin/activate # For Linux/Mac
venv\Scripts\activate # For Windowsπ₯π¦ Install all required dependencies from the requirements.txt file:
pip install -r requirements.txtππ Create and configure the .env file for environment settings:
# Django
DJANGO_SECRET_KEY=<django-insecure-6_e1bm0dh#zcn2m9@@*_z@9r-*m0h2i+)&oxh!^9m3bt3w2=ha>
DJANGO_SETTINGS_MODULE=<config.settings.dev>
# DB
POSTGRES_PASSWORD=<password>
POSTGRES_USER=<user>
POSTGRES_DB=<the_best_db>
POSTGRES_HOST=<localhost>
POSTGRES_PORT=<5432>
PGDATA=</var/lib/postgresql/data>
# Celery settings
CELERY_BROKER_URL = "redis://localhost:6379/0"
CELERY_RESULT_BACKEND = "redis://localhost:6379/0"
CELERY_TIMEZONE = "Europe/Kyiv"
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = 30 * 60ππ Start the development server to run the API.
python manage.py runserverVisit http://127.0.0.1:8000 to test the API.
π³π§ Run the application using Docker Compose to spin up all services in containers.
docker-compose up --buildππ‘ Define all necessary services (PostgreSQL, Redis, Celery, etc.) in the docker-compose.yaml.
FROM python:3.10.8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/services:
social_media_api:
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
env_file:
- .env
web:
build: .
command: >
sh -c "python manage.py wait_for_db &&
python manage.py migrate &&
python manage.py runserver 0.0.0.0:8000"
volumes:
- ./:/code
- media:/code/media
ports:
- "8000:8000"
env_file:
- .env
depends_on:
- social_media_api
redis:
image: "redis:alpine"
celery:
build:
context: .
dockerfile: Dockerfile
command: "celery -A social_media_api worker -l info"
depends_on:
- web
- redis
- social_media_api
restart: on-failure
env_file:
- .env
celery-beat:
build:
context: .
dockerfile: Dockerfile
command: >
sh -c "python manage.py wait_for_db &&
celery -A social_media_api beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler"
depends_on:
- web
- redis
- social_media_api
restart: on-failure
env_file:
- .env
flower:
build:
context: .
dockerfile: Dockerfile
ports:
- "5555:5555"
command: "celery -A social_media_api flower --address=0.0.0.0"
depends_on:
- celery
env_file:
- .env
volumes:
media:π Swagger UI: http://127.0.0.1:8000/api/v1/schema/swagger/

POST /api/user/: Create a new user.POST /api/user/token/: Get access token (JWT).POST /api/user/token/refresh/: Refresh the access token.POST /api/user/token/verify/: Verify the access token.GET /api/user/me/: View your own profile.
GET /api/posts/: List all posts.POST /api/posts/: Create a new post.GET /api/posts/<id>/: View details of a specific post.POST /api/posts/<id>/like/: Like a post.POST /api/posts/<id>/comment/: Comment on a post.
GET /api/profile/: View and edit your profile details.GET /api/profile/<username>/: View another user's profile.
- JWT Authentication: Secure token-based authentication for API access.
- Logout: Token invalidation for logging out users.
- View Profile: Access your own or other users' profiles.
- Edit Profile: Modify your personal information.
- Profile Privacy: Set your account as public or private.
- Create Posts: Users can create posts with text and images.
- View Posts: Posts are publicly viewable, with private access control for editing.
- Like & Comment: Engage with posts by liking or commenting.
- Follow/Unfollow: Manage who you follow/unfollow.
- Block Users: Block other users and prevent them from interacting with you.
- Add Likes: Like posts to express approval.
- Remove Likes: Remove your like from a post.
- Write Comments: Leave comments on posts to engage in conversations.
- Celery: Manage background tasks (e.g., notifications, media processing).
- Redis: Cache data and manage task queues with Redis for efficiency.
- Flower: Use Flower for monitoring background task progress.

