Skip to content

NTTVy03/be-tv-money

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 TV-Money – Back-End

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.


πŸš€ Getting Started

1. Clone the Project

git clone https://github.com/NTTVy03/be-tv-money.git
cd be-tv-money

2. Install Rust

Install Rust by following the official guide:
πŸ‘‰ https://www.rust-lang.org/tools/install

3. Install Docker

Docker is required to run the PostgreSQL database.
πŸ‘‰ https://docs.docker.com/engine/install/

4. Install cargo-watch (optional but useful)

Auto-recompiles your code on changes.

cargo install cargo-watch

5. Install OpenSSL

Required for secure connections. Use the appropriate command based on your OS:

  • Fedora:
    sudo dnf install openssl-devel
  • Ubuntu:
    sudo apt install libssl-dev

πŸ—„οΈ Running the Project

βœ… Step 1: Start PostgreSQL via Docker

docker run --rm --name pg -p 5432:5432 \
  -e POSTGRES_PASSWORD=welcome \
  postgres:17

(Optional) Open psql terminal:

docker exec -it -u postgres pg psql

(Optional) Log all SQL queries

ALTER DATABASE postgres SET log_statement = 'all';

βœ… Step 2: Start Server & Test Client

Option 1: Development Mode with Auto-Reload (requires cargo-watch)

# 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"

Option 2: Manual Run (without cargo-watch)

# Terminal 1: Run the server
cargo run -p web-server

# Terminal 2: Run test client
cargo run -p web-server --example quick_dev

πŸ§ͺ Testing

Run All Tests (auto-reload)

cargo watch -q -c -x "test -- --nocapture"

Run Specific Test (by name)

cargo watch -q -c -x "test -p lib-core test_create -- --nocapture"

Run Tests Once (no auto-reload)

cargo test -- --nocapture

# Specific test
cargo test -p lib-core model::task::tests::test_create -- --nocapture

πŸ› οΈ Extra Tools

Some helper tools can be run separately:

cargo run -p gen-key

πŸ“ Project Structure

This 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.

πŸ“‚ Main Directories

  • 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 as gen-key for 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 the index.html.

πŸ“¦ Key Files

  • 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-APACHE and LICENSE-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.

About

Back-end for TV Money application :>

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors