Uchat is a revolutionary full-stack chat app Built completely on Rust, while leveraging the capabilities of WASM
Demo video is available here
The design/
directory contains some design-related files:
If you are on Windows, using WSL is recommended to manage build dependencies and tooling.
If you haven't installed Rust yet, you can do so using rustup and then install cargo.
Compiling Rust for the browser also requires adding the wasm32
compilation target:
rustup target add wasm32-unknown-unknown
This project uses PostgreSQL for the database. Please follow the official instructions for how to install PostgreSQL on your system.
Trunk is a tool to build and bundle Rust WASM applications. Install with:
cargo install --locked trunk
# Apple M1 users also need to install this:
cargo install --locked wasm-bindgen-cli
Diesel is a Rust SQL query builder for working with the database.
Make sure you have installed PostgreSQL before proceeding.
Install Diesel with:
cargo install diesel_cli --no-default-features --features postgres
If you receive build or linker errors, make sure you install libpq
. This may
be packaged separately depending on your operating system and package manager
(libpq-dev
on Ubuntu/WSL, for example).
Create a .env
file in the workspace directory containing:
API_DATABASE_URL = postgres://DATABASE_USER:PASSWORD@localhost/uchatfinal
API_PRIVATE_KEY = API_PRIVATE_KEY_HERE
API_URL = "http://127.0.0.1:8070/"
API_BIND= "127.0.0.1:8070"
# development only
DATABASE_URL = postgres://DATABASE_USER:PASSWORD@localhost/uchatfinal
TEST_DATABASE_URL = postgres://DATABASE_USER:PASSWORD@localhost/uchatfinal_test
FRONTEND_URL = "http://127.0.0.1:8080"
Substitute these:
DATABASE_USER
: role created to access PostgreSQLPASSWORD
: your password to login to the database (omit:PASSWORD
if not using a password)
After the .env
is ready, run this command to create the database:
diesel setup
This project uses Tailwind CSS for utility classes.
To use Tailwind, you'll need to install
npm to use
the npx
command.
just is a command runner which can simplify running different development commands. Install with:
cargo install just
To build the documentation:
cargo doc -F docbuild
There is a minor bug in the published version of a transitive dependency.
Enabling the docbuild
feature is a temporary workaround until the dependency
gets updated.
Check the two different targets (frontend and backend):
cargo check -p frontend --target wasm32-unknown-unknown
cargo check --workspace --exclude frontend
Run clippy for the two different targets (frontend and backend):
cargo check -p frontend --target wasm32-unknown-unknown
cargo check --workspace --exclude frontend
This will check for the dependencies listed above and attempt to install the Rust dependencies. Dependencies which require manual install will provide a link to installation instructions.
cargo run -p project-init
To run a dev server for the frontend and open a new browser window:
trunk serve --open
To run the backend server:
cargo run -p uchat_server
To build the project for distribution:
trunk --config Trunk-release.toml build
cargo build --release --workspace --exclude frontend
Now run the following:
Frontend:
trunk serve --release --config Trunk-release.toml
Backend:
Switch to Uchat-app/target/release/ and run:
./api
To create database migrations, run:
diesel migration generate MIGRATION_NAME
The migrations will get created in data/migrations/timestamp_MIGRATION_NAME/
.
Add your SQL for applying the migration to up.sql
and the SQL for reverting
the migration to down.sql
.
After adding your migration code to up.sql
and down.sql
, apply the
migration with:
diesel migration run
To make sure you down.sql
works, run this command to revert and then reapply
the migration:
diesel migration redo
After creating a new migration, delete the testing database using:
psql -d postgres -c 'DROP DATABASE uchat_test;'