This project is a social media application built using FastAPI, PostgreSQL, and Docker. It includes features such as user authentication, post creation, voting on posts, and more.
-
Clone the repository:
git clone https://github.com/yourusername/fastapi-social-app.git cd fastapi-social-app -
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Set up the environment variables:
Create a
.envfile in the root directory and add the following variables:HOST='localhost' DATABASE='social_app' USER='postgres' PASSWORD='root' SECRET_KEY='your_secret_key' ALGORITHM='HS256' ACCESS_TOKEN_EXPIRE_MINUTES=60
-
Build and run the Docker containers:
docker compose -f docker-compose-dev.yml up --build
-
Access the application:
The application will be running at
http://localhost:8000.
-
Run the FastAPI application:
uvicorn app.main:app --reload
-
Access the application:
The application will be running at
http://localhost:8000.
- POST /login/: User login.
- POST /users/: Create a new user.
- GET /users/{id}: Get user details by ID.
- GET /posts/: Get all posts.
- GET /posts/{id}: Get a post by ID.
- POST /posts/: Create a new post.
- PUT /posts/{id}: Update a post by ID.
- DELETE /posts/{id}: Delete a post by ID.
- POST /vote/: Vote on a post.
The application uses the following environment variables:
HOST: Database host.DATABASE: Database name.USER: Database user.PASSWORD: Database password.SECRET_KEY: Secret key for JWT.ALGORITHM: Algorithm for JWT.ACCESS_TOKEN_EXPIRE_MINUTES: Access token expiration time in minutes.
The project uses Alembic for database migrations.
-
Generate a new migration:
alembic revision --autogenerate -m "Migration message" -
Apply the migrations:
alembic upgrade head
fastapi-social-app/
├── alembic/
│ ├── versions/
│ ├── env.py
│ └── README
├── app/
│ ├── __init__.py
│ ├── main.py
│ ├── models.py
│ ├── schemas.py
│ ├── database.py
│ ├── oauth2.py
│ ├── utils.py
│ └── routers/
│ ├── __init__.py
│ ├── post.py
│ ├── user.py
│ ├── auth.py
│ └── vote.py
├── .env
├── .gitignore
├── Dockerfile
├── docker-compose-dev.yml
├── docker-compose-prod.yml
├── requirements.txt
└── README.md
- You can check in the http://localhost:8000/docs

- You can check in the http://localhost:8000/redoc

Contributions are welcome! Please open an issue or submit a pull request for any changes.
This project is licensed under the MIT License.