DEV Community

Cover image for I Built a Free Open-Source Blog Platform with Flask and TiDB
sam3maker
sam3maker

Posted on

I Built a Free Open-Source Blog Platform with Flask and TiDB

The Problem

I wanted a blog platform that was:

  • Free to host (no monthly bills)
  • Lightweight (not a 500MB WordPress install)
  • Open source (full control over my content)
  • Modern (Markdown editor, dark mode, i18n)

Everything I found was either too heavy, too expensive, or too restrictive. So I built OpenBlog.

What is OpenBlog?

OpenBlog is a fully open-source blogging platform built with Python/Flask and TiDB (MySQL-compatible serverless database). Deploy it on Hugging Face Spaces for free — zero cost, zero credit card.

Live Demo: sam3maker-openblog.hf.space
Source Code: github.com/sam3maker/openblog

Key Features

Dual Editor

Write in Markdown with live preview, or switch to Rich Text (Quill.js) — your choice.

# Hello World
This is **Markdown** with live preview.
Enter fullscreen mode Exit fullscreen mode

Community Features

  • Likes & Bookmarks
  • Nested comments with replies
  • Follow system & activity timeline
  • User profiles with avatars
  • User blocking

Admin Dashboard

  • Content moderation & report system
  • User management (activate/deactivate/ban by IP)
  • Site-wide configuration
  • Statistics & analytics
  • Audit logging

Multi-language (i18n)

7 languages out of the box: Chinese, English, Japanese, Korean, French, German, Spanish

Security

  • 2FA with TOTP & recovery codes
  • CSRF protection on all forms
  • HTML sanitization (nh3)
  • Rate limiting on auth & API
  • IP banning with auto-expiry
  • OAuth state signing (HMAC)
  • Account lockout after 5 failed logins
  • Security headers (CSP, HSTS, X-Content-Type-Options)

More Features

  • Dark/Light theme toggle
  • Full-text search
  • Image upload with auto-compression (PNG, JPEG, WEBP, GIF preserved)
  • Scheduled publishing with background scheduler
  • Article version history
  • Tag & category system
  • GitHub & Hugging Face OAuth login
  • CJK-friendly URL slugs
  • RSS feed & sitemap & robots.txt
  • SEO-ready meta tags
  • Responsive design (Bootstrap 5)

Tech Stack

Layer Technology
Backend Python 3.10+ / Flask / SQLAlchemy
Frontend HTML5 / CSS3 / JavaScript / Bootstrap 5
Database TiDB (MySQL-compatible, serverless)
Editor Marked.js + Quill.js
Hosting Hugging Face Spaces (Docker)
Cache FileSystemCache (cross-worker)
Auth Flask-Login + OAuth + 2FA

Deploy in 5 Minutes

Option 1: Hugging Face Spaces (Free, Recommended)

  1. Fork the repo on GitHub
  2. Go to Hugging Face Spaces → Create new Space → Select Docker
  3. Link your GitHub repo
  4. Add environment variables in Space Settings:
   MYSQL_HOST=your-tidb-host
   MYSQL_PORT=4000
   MYSQL_USER=your-username
   MYSQL_PASSWORD=your-password
   MYSQL_DATABASE=openblog
   SECRET_KEY=your-secret-key
   MYSQL_SSL_CA_CONTENT=<your SSL cert content>
Enter fullscreen mode Exit fullscreen mode
  1. Done! Your blog is live.

Option 2: Local Development

git clone https://github.com/sam3maker/openblog.git
cd openblog
cp .env.example .env
# Edit .env with your TiDB Cloud credentials
pip install -r requirements.txt
python run.py
Enter fullscreen mode Exit fullscreen mode

Visit http://localhost:5000 — the admin account is created automatically.

TiDB Cloud free tier gives you 5GB storage, 50M request units/month — more than enough for a blog.

Project Structure

openblog/
├── app/
│   ├── config.py           # Configuration
│   ├── models.py           # 13 database tables
│   ├── i18n/               # 7 languages
│   ├── routes/
│   │   ├── auth.py         # Auth, OAuth, 2FA
│   │   ├── blog.py         # Blog CRUD, RSS, scheduler
│   │   ├── community.py    # Likes, bookmarks, comments, follows
│   │   ├── admin.py        # Admin panel
│   │   ├── user.py         # Profiles, settings
│   │   └── api.py          # REST API
│   └── utils.py            # Helpers & utilities
├── templates/              # Jinja2 templates
├── static/                 # CSS, JS, uploads
└── run.py
Enter fullscreen mode Exit fullscreen mode

API Endpoints

Endpoint Method Description
/api/search?q= GET Global search
/api/tags GET Tag list
/api/categories GET Category list
/api/stats GET Site statistics
/api/upload POST Image upload
/feed GET RSS feed
/sitemap.xml GET Sitemap

Why TiDB?

Most blog platforms use SQLite or PostgreSQL. I chose TiDB because:

  • Serverless — no database server to manage
  • MySQL-compatible — uses standard SQLAlchemy
  • Free tier — generous limits for personal blogs
  • Scalable — grows with your traffic

What's Next?

  • Plugin system for community extensions
  • API documentation (Swagger/OpenAPI)
  • Docker Compose for one-command local dev
  • Database backup & export

Contributing

OpenBlog is open source under the MIT License. Issues and Pull Requests are welcome!

GitHub: github.com/sam3maker/openblog

If you find this project useful, please give it a ⭐ on GitHub — it helps a lot!

Top comments (0)