Skip to content

rust-game-samples/redleaf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

41 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌿 RedLeaf CMS

A lightweight, blazing-fast CMS built with Rust β€” WordPress parity without the bloat.

πŸ‡―πŸ‡΅ Japanese documentation: README_ja.md

πŸš€ About

RedLeaf is a modern CMS powered by Rust.
It combines the stability of systems programming with the flexibility of web publishing.

  • ⚑ Fast β€” compiled Rust backend, in-memory page cache, minimal runtime overhead
  • πŸͺΆ Lightweight β€” single binary + SQLite, zero external runtime dependencies
  • πŸ”’ Secure β€” Argon2id password hashing, JWT auth, role-based capabilities
  • 🌐 Headless Ready β€” full REST API included
  • 🐳 Docker Ready β€” multi-stage build, production-grade image
  • 🧩 WordPress Compatible β€” WXR import/export, familiar admin UX

πŸ”§ Tech Stack

Layer Technology
Language Rust (stable, 2021 edition)
Web Framework Axum 0.8
Database SQLite via SQLx 0.8
Templates Askama 0.14 (compiled at build time)
Auth JWT (jsonwebtoken) + Argon2id
Search SQLite FTS5 (full-text search)
Image Processing image 0.25 (resize + WebP)
XML Parsing quick-xml 0.37 (WXR import)
Cache In-memory page cache (Tower middleware)

βš™οΈ Quick Start

Development

git clone https://github.com/yourname/redleaf.git
cd redleaf
cp .env.example .env   # set JWT_SECRET before production use
cargo run

Open http://localhost:3000
First run: visit http://localhost:3000/setup to create the admin account.

Docker

docker build -t redleaf .
docker run -p 3000:3000 \
  -v redleaf-data:/app/data \
  -v redleaf-uploads:/app/static/uploads \
  -e JWT_SECRET=$(openssl rand -hex 32) \
  redleaf

Environment Variables

Variable Default Description
DATABASE_URL sqlite:redleaf.db SQLite file path
HOST 127.0.0.1 Bind address
PORT 3000 Listen port
JWT_SECRET (required in production) Token signing secret

πŸ—‚οΈ Directory Structure

redleaf/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs              # Entry point β€” server startup
β”‚   β”œβ”€β”€ lib.rs               # App builder β€” router + middleware wiring
β”‚   β”œβ”€β”€ auth.rs              # JWT generation & validation
β”‚   β”œβ”€β”€ cache.rs             # In-memory page cache (Tower middleware)
β”‚   β”œβ”€β”€ db.rs                # SQLite connection pool
β”‚   β”œβ”€β”€ errors.rs            # Unified AppError type
β”‚   β”œβ”€β”€ filters.rs           # Askama template filters
β”‚   β”œβ”€β”€ hooks.rs             # Action/filter hook registry (WordPress-style)
β”‚   β”œβ”€β”€ image_processing.rs  # Image resize + WebP variant generation
β”‚   β”œβ”€β”€ middleware.rs        # Auth middleware + capability checks
β”‚   β”œβ”€β”€ shortcodes.rs        # Shortcode registry ([gallery], [caption], …)
β”‚   β”œβ”€β”€ util.rs              # slugify / render / Pagination / FTS helpers
β”‚   β”œβ”€β”€ wxr.rs               # WordPress WXR XML parser
β”‚   β”œβ”€β”€ assets.rs            # Script/style enqueue registry
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ activity_log.rs  # Admin activity log
β”‚   β”‚   β”œβ”€β”€ category.rs      # Categories
β”‚   β”‚   β”œβ”€β”€ comment.rs       # Comments (threaded)
β”‚   β”‚   β”œβ”€β”€ media.rs         # Media library + image variants
β”‚   β”‚   β”œβ”€β”€ nav_menu.rs      # Custom navigation menus
β”‚   β”‚   β”œβ”€β”€ page.rs          # Static pages
β”‚   β”‚   β”œβ”€β”€ post.rs          # Posts (CRUD, FTS, revisions, scheduling)
β”‚   β”‚   β”œβ”€β”€ post_meta.rs     # Custom fields (KV store per post)
β”‚   β”‚   β”œβ”€β”€ post_revision.rs # Post revision history
β”‚   β”‚   β”œβ”€β”€ setting.rs       # Site settings KV store
β”‚   β”‚   β”œβ”€β”€ tag.rs           # Tags
β”‚   β”‚   β”œβ”€β”€ user.rs          # Users (roles, profiles)
β”‚   β”‚   └── widget.rs        # Widget areas + widgets
β”‚   └── routes/
β”‚       β”œβ”€β”€ mod.rs           # Public pages (home, search, setup, sitemap, …)
β”‚       β”œβ”€β”€ admin.rs         # Admin panel (all CRUD + import/export)
β”‚       β”œβ”€β”€ api.rs           # REST API (/api/posts)
β”‚       β”œβ”€β”€ auth.rs          # Auth API (/auth/login, /auth/register)
β”‚       β”œβ”€β”€ feed.rs          # RSS 2.0 & Atom feeds
β”‚       β”œβ”€β”€ posts.rs         # Public post pages
β”‚       └── taxonomy.rs      # Category & tag archive pages
β”œβ”€β”€ templates/
β”‚   β”œβ”€β”€ admin/               # Admin panel (dashboard, posts, media, …)
β”‚   β”œβ”€β”€ themes/default/      # Default public theme (single, archive, …)
β”‚   β”œβ”€β”€ base.html            # Public base layout
β”‚   β”œβ”€β”€ index.html           # Homepage
β”‚   β”œβ”€β”€ search.html          # Search results
β”‚   └── setup.html           # First-run setup wizard
β”œβ”€β”€ migrations/              # 15 SQLx migrations (embedded in binary)
β”œβ”€β”€ static/
β”‚   └── uploads/             # User-uploaded media files
β”œβ”€β”€ tests/                   # Integration tests
β”œβ”€β”€ ai_docs/                 # Project documentation & Claude Code skills
β”œβ”€β”€ build.rs                 # Captures RUST_VERSION at compile time
└── Dockerfile

🌐 Endpoints

Public

Method Path Description
GET / Homepage
GET /posts Post archive (paginated)
GET /posts/{slug} Single post
GET /categories/{slug} Category archive
GET /tags/{slug} Tag archive
GET /author/{username} Author archive
GET /pages/{slug} Static page
GET /search?q=… Full-text search
GET /feed RSS 2.0 feed
GET /feed/atom Atom feed
GET /sitemap.xml XML sitemap
GET /robots.txt robots.txt (editable in admin)
GET /health Health check ({"status":"ok"})

Auth

Method Path Description
POST /auth/login Login β†’ JWT
POST /auth/register Register β†’ JWT

Admin (session required)

Area Paths
Dashboard GET /admin (+ quick draft POST)
Posts /admin/posts CRUD + bulk actions, toggle, revisions
Pages /admin/pages CRUD
Categories /admin/categories CRUD + bulk delete
Tags /admin/tags + bulk delete
Media /admin/media upload/delete (auto-generates variants)
Comments /admin/comments approve/reject/spam
Users /admin/users + role management
Menus /admin/menus CRUD + drag-and-drop items
Widgets /admin/widgets CRUD + reorder
Settings /admin/settings + robots.txt
Activity Log GET /admin/activity-logs
Import GET/POST /admin/import (WXR)
Export GET /admin/export β†’ JSON / WXR / SQLite backup

REST API

Method Path Description
GET /api/posts Post list (JSON)
GET /api/posts/{id} Single post (JSON)
POST /api/posts Create post (auth)
PUT /api/posts/{id} Update post (auth)
DELETE /api/posts/{id} Delete post (auth)
GET /api/users/{id}/posts Posts by user

πŸ“Š Implementation Status

Feature Status
Post CRUD + Markdown rendering βœ…
Category & tag management βœ…
Media upload & library βœ…
Image resize + WebP variants + <img srcset> βœ…
JWT authentication + role-based capabilities βœ…
REST API βœ…
FTS5 full-text search βœ…
Site settings βœ…
Docker / health check βœ…
Web installer (setup wizard) βœ…
Static pages (Pages) βœ…
Featured images + OGP βœ…
Custom fields (Post Meta) βœ…
Scheduled posts βœ…
Post revisions βœ…
Sticky posts βœ…
Template system (themes) βœ…
Hook system (actions / filters) βœ…
Shortcode API ([gallery], [caption], [audio]) βœ…
Custom navigation menus βœ…
Breadcrumbs + JSON-LD βœ…
Widget areas βœ…
User roles & profiles βœ…
Author archive pages βœ…
Comment system (threaded) βœ…
Comment moderation βœ…
RSS 2.0 / Atom feeds βœ…
XML sitemap βœ…
SEO meta + Open Graph + Twitter Card βœ…
Structured data (JSON-LD Article) βœ…
Bulk actions (posts / categories / tags) βœ…
Activity log βœ…
Dashboard (stats / quick draft / site health) βœ…
In-memory page cache + ETag / Last-Modified βœ…
WordPress WXR import (+ dedup / slug rename) βœ…
JSON export / WXR export / SQLite backup βœ…

πŸ€– Claude Code Skills

Custom commands for AI-assisted development:

/wp-implement [task or phase]

Implements a task from ai_docs/wordpress-parity-tasks.md, runs cargo build, and marks the checkbox.

/wp-implement フェーズ 8
/wp-implement RSS feed
/wp-implement          ← list all pending tasks

/wp-add-task [description]

Appends a new task to the roadmap file.

πŸ§ͺ Testing

cargo test

Integration tests in tests/: auth_test.rs Β· admin_posts_test.rs Β· public_posts_test.rs Β· api_test.rs Β· taxonomy_test.rs

🚒 Deployment

VPS (systemd)

cargo build --release
# copy binary + static/ to /opt/redleaf
# configure /etc/systemd/system/redleaf.service with JWT_SECRET env var
# put Nginx in front for TLS + static file serving

Fly.io (recommended for SQLite)

fly launch --no-deploy
fly volumes create redleaf_data --size 1
fly volumes create redleaf_uploads --size 5
fly secrets set JWT_SECRET="$(openssl rand -hex 32)"
fly deploy
# visit https://your-app.fly.dev/setup

Backup

Download a live SQLite snapshot anytime from Admin β†’ Export β†’ Download DB.

πŸͺ„ Philosophy

"RedLeaf β€” grows naturally, powered by Rust."

Every page is a leaf. Every site is a tree. And Rust is the root that keeps it strong.

πŸ“œ License

MIT

Releases

Packages

Contributors

Languages