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.
- Python 3.12+
- Poetry (dependency management)
- PostgreSQL (or compatible database)
git clone https://github.com/yourusername/blog-platform-api.git
cd blog-platform-api- 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
- 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
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
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
.
├── 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