Skip to content

Repository files navigation

Blog Platform API

A FastAPI-based blog platform API with JWT authentication, Alembic migrations, and PostgreSQL support (API will fallback to sqlite db if postgresql configuration is missing)
Package management is handled with Poetry.

Database fallback: By default, the API uses PostgreSQL (via DATABASE_URL).
If no configuration is found, it will seamlessly switch to a local SQLite file (blog_platform_api.db) 
so you can run the project immediately without extra setup.

📦 Requirements

  • Python 3.12+
  • Poetry (dependency management)
  • PostgreSQL (or compatible database)

🚀 Getting Started

1️⃣ Clone the repository

git clone https://github.com/yourusername/blog-platform-api.git
cd blog-platform-api

2️⃣ Install dependencies

  • If you dont have poetry installed on your system
pip install poetry
poetry --version
  • Without dev tools (production-like)
poetry install

If poetry install doesn't work, try:

poetry install --no-root

-With dev tools (ruff for formatting)

poetry install --with dev

3️⃣ Setup environment variables

  • Create .env file in the project root
  • Edit .env with your own values.

Example .env:

DATABASE_URL=postgresql://username:password@localhost:5432/blog_db
SECRET_KEY=your-secret-key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRES_MINUTES=60

4️⃣ Run database migrations

Alembic is used for database migrations.

  • Generate a migration after making model changes:
poetry run alembic revision --autogenerate -m "description of changes"
  • Apply migrations:
poetry run alembic upgrade head
  • Downgrade migration (optional):
poetry run alembic downgrade -1

5️⃣ Start the development server

poetry run uvicorn app.main:app --reload
  • The API will be available at:
http://127.0.0.1:8000
  • Swagger Docs
http://127.0.0.1:8000/docs

🛠 Project Structure

.
├── alembic/               # Database migration scripts
├── config/                # Config, security, auth
├── models/                # SQLAlchemy models
├── routes/                # Routes and endpoints
├── schemas/               # Pydantic schemas
├── main.py                # FastAPI entry point
├── utils/                 # hashing and dependencies
├── alembic.ini            # Alembic configuration
├── pyproject.toml         # Poetry dependencies
├── poetry.lock            # Locked dependency versions
├── .env.example           # Environment variable template
├── README.md              # This file
└── .gitignore             # Ignored files

About

FastAPI-powered blog platform API with JWT auth, role-based access, PostgreSQL/SQLite support, and Alembic migrations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages