Skip to content

HellBook is a small FastAPI-based demo REST API built to showcase authentication, CRUD operations for posts and comments, file uploads, and background task processing in a clean, modular application structure.

Notifications You must be signed in to change notification settings

hello-sahasraka/HellBook-FastAPI-Social-Media-Application

Repository files navigation

🔥 HellBook (FastAPI)

A small but complete FastAPI project featuring:

  • 🔐 JWT authentication
  • 📝 Posts with 🗨 comments and ❤️ likes
  • 📤 File uploads (B2 helper included)
  • 📨 Background tasks (email & image generation)
  • 🧪 Basic tests and structured logging

📂 Quick Links

  • 🚀 App entry / lifecycle

    • app/main.pylifespan and exported app
  • 🧭 Routers

    • Posts — app/routers/routes_posts.pyrouter
    • Users — app/routers/routes_users.pyrouter
    • Uploads — app/routers/routes_upload.pyrouter
  • 🔐 Security

    • app/security.pyget_current_user, create_access_token, create_confirmation_token, authenticate_user, get_subject_for_token_type
  • 🗄 Database

    • app/database.pydatabase instance & table schemas
  • 🛠 Background tasks / mail / image

    • app/tasks.pysend_simple_email, generate_and_add_to_post
  • ☁️ B2 Cloud helper

    • app/libs/b2/__init__.pyb2_upload_file
  • 🧾 Logging

    • app/logging_conf.pyconfigure_logging
  • Tests

    • app/test/

📦 Requirements

  • Python 3.10+

  • Dependencies from:

    • requirements.txt
    • (optional dev tools) requirements-dev.txt

🚀 How to Run

# 1) Create & activate a virtual environment (recommended)
python -m venv venv
# Linux/Mac:
source venv/bin/activate
# Windows:
venv\Scripts\activate

# 2) Install dependencies
pip install -r requirements.txt
# (optional for linting/tests/dev tools)
pip install -r requirements-dev.txt

# 3) Create a .env file in the project root (see template below)

# 4) Launch the API (auto-reload in dev)
uvicorn app.main:app --reload

🧾 Example .env Template (Safe Placeholders)

# ───── Environment Mode ───────────────────────────────────────────────
ENV_STATE=dev

# ───── Dev Database ──────────────────────────────────────────────────
DEV_DATABASE_URL=sqlite+aiosqlite:///./dev.db

# ───── Mailgun (for emails) ──────────────────────────────────────────
DEV_MAILGUN_API_KEY=YOUR_MAILGUN_API_KEY_HERE
DEV_MAILGUN_DOMAIN=YOUR_MAILGUN_DOMAIN_HERE

# ───── Sentry (optional monitoring) ──────────────────────────────────
DEV_SENTRY_DNS=YOUR_SENTRY_DSN_HERE

# ───── Backblaze B2 Storage (for uploads) ────────────────────────────
B2_KEY_ID=YOUR_B2_KEY_ID
B2_APPLICATION_KEY=YOUR_B2_APPLICATION_KEY
B2_BUCKET_NAME=YOUR_B2_BUCKET_NAME

# ───── External API (e.g., DeepAI for images) ────────────────────────
DEEPAI_API_KEY=YOUR_DEEPAI_API_KEY

# ───── Test Database ─────────────────────────────────────────────────
TEST_DATABASE_URL=sqlite+aiosqlite:///./test.db

# ───── Production Database (example) ─────────────────────────────────
PROD_DATABASE_URL=postgresql+asyncpg://USER:PASSWORD@HOST/DB_NAME

# ───── JWT Secret (Dev) ─────────────────────────────────────────────
DEV_SECRET_KEY=CHANGE_ME_TO_A_RANDOM_LONG_SECRET

🧪 Running Tests (optional)

# Assuming pytest is in requirements-dev.txt
pytest -q

🔒 Security Notes

  • Keep real secrets out of README.md and version control.
  • Rotate API keys periodically.
  • Use HTTPS and proper CORS settings in production.
  • Prefer a production-grade server (e.g., gunicorn with uvicorn.workers.UvicornWorker) behind a reverse proxy.

📦 Deployment Tips

  • Configure ENV_STATE=prod and point to PROD_DATABASE_URL.
  • Set real secrets via environment variables (or a secret manager).
  • Use a process manager (e.g., systemd, Supervisor) or containers (Docker).

🤝 Contributing

  1. Open an issue describing the change
  2. Submit a PR with a clear title/description
  3. Include tests or example calls if applicable

About

HellBook is a small FastAPI-based demo REST API built to showcase authentication, CRUD operations for posts and comments, file uploads, and background task processing in a clean, modular application structure.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published