Based on the template: rust-web-app
This is the back-end service of the TV-Money app. It uses Rust (Axum, SeaQL), PostgreSQL, and Docker.
git clone https://github.com/NTTVy03/be-tv-money.git
cd be-tv-moneyInstall Rust by following the official guide:
π https://www.rust-lang.org/tools/install
Docker is required to run the PostgreSQL database.
π https://docs.docker.com/engine/install/
Auto-recompiles your code on changes.
cargo install cargo-watchRequired for secure connections. Use the appropriate command based on your OS:
- Fedora:
sudo dnf install openssl-devel - Ubuntu:
sudo apt install libssl-dev
docker run --rm --name pg -p 5432:5432 \
-e POSTGRES_PASSWORD=welcome \
postgres:17docker exec -it -u postgres pg psqlALTER DATABASE postgres SET log_statement = 'all';# Terminal 1: Run the server
cargo watch -q -c -w crates/services/web-server/src/ -w crates/libs/ -w .cargo/ \
-x "run -p web-server"
# Terminal 2: Run test client
cargo watch -q -c -w crates/services/web-server/examples/ \
-x "run -p web-server --example quick_dev"# Terminal 1: Run the server
cargo run -p web-server
# Terminal 2: Run test client
cargo run -p web-server --example quick_devcargo watch -q -c -x "test -- --nocapture"cargo watch -q -c -x "test -p lib-core test_create -- --nocapture"cargo test -- --nocapture
# Specific test
cargo test -p lib-core model::task::tests::test_create -- --nocaptureSome helper tools can be run separately:
cargo run -p gen-keyThis is a Rust-based project using Cargo Workspaces to manage multiple crates. The project is structured as follows:
.
βββ Cargo.lock # Lock file for dependencies.
βββ Cargo.toml # Workspace configuration and dependencies.
βββ crates # Contains the main application crates.
β βββ libs # Reusable libraries.
β β βββ lib-auth # Authentication utilities (passwords, tokens).
β β βββ lib-core # Core logic (models, context, config).
β β βββ lib-rpc-core # Core JSON-RPC utilities.
β β βββ lib-utils # General utilities (base64, time).
β β βββ lib-web # Web-related utilities (logging, middleware).
β βββ services # Application services (business logic).
β β βββ web-server # Main web server application (handles HTTP requests).
β βββ tools # Tools for various tasks.
β βββ gen-key # Key generation tool (likely for cryptographic keys).
βββ LICENSE-APACHE # Apache 2.0 license.
βββ LICENSE-MIT # MIT license.
βββ README.md # Project documentation.
βββ rustfmt.toml # Rust code formatting configuration.
βββ sql # SQL scripts for database setup and seeding.
β βββ dev_initial # Initial development SQL scripts.
β βββ 00-recreate-db.sql # Script to recreate the database.
β βββ 01-create-schema.sql # Script to create the database schema.
β βββ 02-dev-seed.sql # Script to seed the database with initial data.
βββ target # Build output directory (auto-generated by Cargo).
βββ web-folder # Front-end files (e.g., static HTML).
βββ index.html # Main HTML file.-
crates/libs/: Contains reusable libraries used across different services. Examples include authentication, core logic, and web utilities. -
crates/services/: Contains the core application services such as the web server that handles HTTP requests. -
crates/tools/: Contains standalone tools such asgen-keyfor key generation. -
sql/: Contains SQL scripts used for database initialization and seeding. -
web-folder/: This folder is likely used for front-end static files, including theindex.html.
Cargo.toml: Defines the workspace and shared dependencies for all the crates in the project.Cargo.lock: Lock file that ensures reproducible builds.rustfmt.toml: Configuration for formatting Rust code.LICENSE-APACHEandLICENSE-MIT: The Apache 2.0 and MIT licenses governing the project.README.md: Documentation explaining how to set up and run the project.
This structure allows for a modular, scalable project where libraries, services, and tools are well-separated and managed globally.