Running the Social Media Backend locally gives you a full development environment with hot-reload, interactive API docs, and direct access to your PostgreSQL database. This guide walks you through every step, from cloning the repository to verifying your first successful response.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pvnm4/Social-Media-Backend/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you begin, make sure you have the following installed and available on yourPATH:
- Python 3.14+ — required by
pyproject.toml(requires-python = ">=3.14") - PostgreSQL — a running local instance (any recent version)
uv(recommended) — fast Python package manager; or plainpipas a fallback
Setup steps
Clone the repository
Clone the project from GitHub and navigate into the application directory:The repository uses a nested directory structure — the actual application code and
pyproject.toml live inside the inner Social-Media-Backend/ folder. All subsequent commands must be run from this inner directory.Create a virtual environment and install dependencies
With This reads
uv (recommended):pyproject.toml and installs all declared dependencies — including FastAPI, SQLAlchemy, Alembic, Uvicorn, passlib, PyJWT, psycopg2, and pydantic-settings — into an isolated virtual environment automatically.The project’s canonical dependency list lives in
pyproject.toml. Dependencies include fastapi, sqlalchemy, alembic, uvicorn, psycopg2, pydantic[email], pydantic-settings, passlib[bcrypt], python-multipart, bcrypt, and pyjwt.Create a PostgreSQL database
Create a dedicated database for the application. Using the Or from within a You can use any database name you like — just make sure it matches the
createdb CLI:psql session:DATABASE_NAME value you set in the next step.Configure environment variables
The application reads all configuration from a Every key maps directly to a field in These same variables are used by both
.env file via pydantic-settings. Create .env in the project root (Social-Media-Backend/Social-Media-Backend/) with the following template:app/config.py:app/database.py (to build the SQLAlchemy connection URL) and alembic/env.py (to build the migration connection URL), so a single .env file covers the entire application.Run database migrations
Apply all Alembic migrations to bring your database schema up to the latest version:This runs all 7 migration files in order, creating the
posts, users, and votes tables with all their columns and constraints. See the DB Migrations page for a full breakdown of each migration.Verify the installation
Once the server is running, confirm everything is working with two quick checks: Health check endpoint — open your browser or run:http://localhost:8000/docs to open the Swagger UI. Every endpoint is listed here and can be called directly from the browser, including authenticated routes (use the Authorize button to supply a JWT token).
The
/redoc path at http://localhost:8000/redoc provides an alternative ReDoc-style documentation view of the same OpenAPI schema.Development tips
-
Hot reload — the
--reloadflag tells Uvicorn to watch your source files and restart the server automatically whenever you save a change. This is ideal for iterative development but should not be used in production. -
Testing endpoints with auth — the Swagger UI at
/docsincludes an Authorize button. After creating a user viaPOST /users/and logging in viaPOST /login, paste the returned JWT into the authorization dialog to test protected endpoints without a separate HTTP client. -
ReDoc — if you prefer a read-only, three-panel documentation layout, the
/redocpath renders the same OpenAPI spec in ReDoc format, which is particularly useful for sharing API documentation with consumers. -
Resetting the schema — during early development you may want to tear down and rebuild the schema. Use
alembic downgrade baseto drop all tables, thenalembic upgrade headto recreate them cleanly.