blog/backend/README.md
SquidSpirit d1f085b255
All checks were successful
Frontend CI / build (push) Successful in 1m37s
BLOG-145 Add pre-commit hooks (#147)
### Description

- READMEs are also updated!

### Package Changes

_No response_

### Screenshots

_No response_

### Reference

Resolves #145.

### Checklist

- [x] A milestone is set
- [x] The related issuse has been linked to this branch

Reviewed-on: #147
Co-authored-by: SquidSpirit <squid@squidspirit.com>
Co-committed-by: SquidSpirit <squid@squidspirit.com>
2025-10-15 13:11:25 +08:00

1.8 KiB

Backend

Development

Prerequisites

  • Rust - Latest stable version
  • sqlx-cli - Database migration tool
  • watchexec (Optional) - For hot reloading

Setup

  1. Install sqlx CLI:

    cargo install sqlx-cli
    
  2. Run database migrations:

    sqlx migrate run
    
  3. Prepare SQL schema:

    cargo sqlx prepare --workspace
    
  4. Run the server:

    RUST_LOG=debug cargo run
    

Development Commands

  • Run server: RUST_LOG=debug cargo run
  • Hot reload (optional): RUST_LOG=debug watchexec -e rs -r 'cargo run'
  • Database migration: sqlx migrate run
  • Schema preparation: cargo sqlx prepare --workspace
  • Build: cargo build
  • Test: cargo test

Project Structure

The backend follows Clean Architecture principles with a modular structure:

  • server/ - Main server application and configuration
  • feature/ - Feature modules organized by domain
    • auth/ - Authentication and authorization
    • post/ - Blog post management
    • label/ - Label/tag system
    • image/ - Image handling
    • common/ - Shared utilities and types
  • migrations/ - Database migration scripts

Each feature module follows the Clean Architecture pattern:

  • domain/ - Business logic and entities
  • application/ - Use cases and application services
  • adapter/ - Interface adapters (controllers, presenters)
  • framework/ - External frameworks (database, HTTP)

Technology Stack

  • Framework: Actix-web
  • Database: PostgreSQL with SQLx
  • Authentication: JWT-based
  • Serialization: Serde
  • Migration: SQLx migrations
  • Logging: env_logger with RUST_LOG