Here is the English translation of your project description:
This project is a real-time task management application (Todo List) built with Rust using the Axum web framework. It combines:
- A high-performance backend (REST API + SSE for live updates)
- A lightweight frontend (HTMX for interactivity without complex JavaScript)
- A PostgreSQL database for persistent storage
The application allows:
- ✅ Adding/deleting tasks with immediate updates for all connected users
- ✅ Displaying a dynamic list without page reloads (via SSE)
- ✅ Serving static assets (CSS) for a clean UI
-
Main Routes:
GET /→ Home page (home())GET /todos→ Retrieve all tasks (fetch_todos())POST /todos→ Create a task (create_todo())DELETE /todos/:id→ Delete a task (delete_todo())GET /stream→ SSE stream for real-time updates (handle_stream())GET /styles.css→ Static CSS (styles())
-
Data Management:
- SQLx for PostgreSQL queries
- Models (
Todo,TodoNew,TodoUpdate) to structure data
-
Real-Time Functionality:
BroadcastStream(Tokio) to notify clients of changes- Server-Sent Events (SSE) to push updates to the frontend
-
HTML Templates:
- Direct integration with Axum (e.g.,
templates::TodoNewTemplate) - Use of HTMX for AJAX requests (
hx-post,hx-delete)
- Direct integration with Axum (e.g.,
-
CSS: Static file served via
/styles.css
-
Shared State (
AppState):- Contains the database connection pool (
db) and the broadcast channel (tx)
- Contains the database connection pool (
-
Error Handling:
- Centralized via
ApiError(handling SQLx, Axum errors, etc.)
- Centralized via
-
Rust: Installed via rustup
-
PostgreSQL: Local or remote server (with a configured database)
-
Environment Variables: Create a
.envfile at the root:DATABASE_URL=postgres://user:password@localhost/db_name
-
Clone the repository (if applicable):
git clone <repo_url> cd <project_dir>
-
Install dependencies:
cargo build
-
Apply SQLx migrations:
sqlx migrate run
-
Start the server:
cargo run
- The server starts at
http://localhost:3000
- The server starts at
-
Access the application:
- Open
http://localhost:3000in a browser
- Open
-
Add a Task:
- The HTMX form sends a
POST /todosrequest - The task is saved in the database and broadcasted to all clients via SSE
- The HTMX form sends a
-
Delete a Task:
- Click on an
hx-deletebutton →DELETE /todos/:idrequest - Immediate UI update for all users
- Click on an
-
Real-Time Streaming:
- The
/streampage listens for SSE events and automatically updates the list
- The
- Logs: Check server logs (
cargo run) - SQLx Errors: Enable logging with
RUST_LOG=sqlx=info - SSE: Test with
curl http://localhost:3000/streamto see events
- Cloud: Use Docker + AWS/Google Cloud (with Rust + PostgreSQL image)
- Render/Heroku: Configure Rust buildpack and the database
A minimalist yet powerful project to explore Rust, Axum, and HTMX together! 🦀
For further insights and examples, you might find the following resources helpful:
- HTMX Todo List with Axum and Tailwind CSS
- Rust Axum Askama HTMX Todo App
- Build an App with Rust and HTMX
Feel free to explore these projects to deepen your understanding and enhance your application.