Skip to content

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.

Notifications You must be signed in to change notification settings

SuhelKhanCA/Python-API-Development

Repository files navigation

FastAPI Social App

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.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/fastapi-social-app.git
    cd fastapi-social-app
  2. Create and activate a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows use `.venv\Scripts\activate`
  3. Install the dependencies:

    pip install -r requirements.txt
  4. Set up the environment variables:

    Create a .env file 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

Running the Application

Using Docker

  1. Build and run the Docker containers:

    docker compose -f docker-compose-dev.yml up --build
  2. Access the application:

    The application will be running at http://localhost:8000.

Without Docker

  1. Run the FastAPI application:

    uvicorn app.main:app --reload
  2. Access the application:

    The application will be running at http://localhost:8000.

API Endpoints

Authentication

  • POST /login/: User login.

Users

  • POST /users/: Create a new user.
  • GET /users/{id}: Get user details by ID.

Posts

  • 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.

Votes

  • POST /vote/: Vote on a post.

Environment Variables

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.

Database Migrations

The project uses Alembic for database migrations.

  1. Generate a new migration:

    alembic revision --autogenerate -m "Migration message"
  2. Apply the migrations:

    alembic upgrade head

Project Structure

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

Snapshot

Swagger UI Docs

ReDocs

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes.

License

This project is licensed under the MIT License.

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published