1. Pre-Requisites Top ▲
For this project to run you will require the following:
- Rust & Cargo installed (https://www.rust-lang.org/tools/install)
- pnpm installed (https://pnpm.io/installation)
- SQLite3 installed (https://sqlite.org/download.html)
- [optional] make installed (https://www.gnu.org/software/make/)
2. Installation Top ▲
This project is built with Cargo, pnpm, and SQLx-cli.
If make was installed, these steps can be skipped with: Skip ▼
make setupTo set-up the repository install the rust dependencies with:
cargo install
cargo binstall cargo-watch
cargo binstall sqlx-cliNext install the pnpm dependencies with:
pnpm installFinally, you will need to create and migrate the db with:
sqlx db create
sqlx migrate runOr using the bash script:
./migrations.shNow you should be ready to build and run the project.
3. Build Top ▲
The build process is quite simple.
First run:
make tailwindor
npx @tailwindcss/cli -i ./ui/styles/tailwind.css -o ./ui/assets/main.cssThis is required to set-up the css styling for the project.
Following that run:
make server-watchor
RUST_LOG=info cargo watch -x runThis will start the Rust server. Once built, you can access the app at http://localhost:3000 or your configured port.
4. Setup Top ▲
Following this you will need to set up a shortcut for your search bar. Given you have not changed the port, the steps for some common browsers are as follows:
- Go to chrome://settings/search.
- Click "Manage search engines and site search".
- Click "Add" next to "Site search".
- Fill the url to be
http://localhost:8035/api/get?keyword=%s - Fill out the rest of the details and save.
- Go to about:preferences#search.
- Click "Search Shortcut".
- Click "Add".
- Fill the url to be
http://localhost:8035/api/get?keyword=%s - Fill out the rest of the details and save.
- Go to edge://settings/searchEngines?search=address.
- Click "Add" next to "Site search".
- Fill the url to be
http://localhost:8035/api/get?keyword=%s - Fill out the rest of the details and save.
- Go to brave://settings/search.
- Click "Manage search engines and site search".
- Click "Add" next to "Site search".
- Fill the url to be
http://localhost:8035/api/get?keyword=%s - Fill out the rest of the details and save.
- Go to vivaldi://settings/search.
- Click "Search Engines".
- Click "Add" next to "Site search".
- Fill the url to be
http://localhost:8035/api/get?keyword=%s - Fill out the rest of the details and save.
5. Architecture Top ▲
This project is a Rust HTMX monolith application.
HTMX is a lightweight HTML templating structure that allows you to swap elements in the DOM through function returns.
For the templating system, we are using Tera, which uses Jinga-inspired templates.
With Tera, we have chosen to use the tera-hot-reload crate. This allows for quick and easy development of the ui.
Roughly a page template can be described like below:
#[derive(TeraTemplate, Serialize)]
#[template(path = "template.html")]
pub struct Template {
pub title: String
}
pub fn getTemplate(tera: Tera) {
let context = Template { title: "template" }
return Html(self.render(tera));
}Where an example template.html can be:
{% extends "base.html" %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
<main class="ml-14 pl-5 flex-1 p-4 dark:bg-neutral-800" style="justify-items: center;" >
<div id="load-error" class="dark:text-white"></div>
{% include "components/search/search.html" %}
<div id="results" \>
</main>
{% endblock %}With api calls, we then set the results div as the target for the output of a function.
More examples of this can be seen in:
The interaction between our server and our database is sqlx.
In an ideal world, I would use sqlean, spellfix1 extension, or elastic-rs to allow fuzzy searching within the database.
But for simplicity's sake, we are currently using a SQLite database without any extensions.
This means that our searches will require pulling the entire shortcut database and searching/sorting within the Rust layer. This in practice is not as bad as you think due to Rust's fast nature.
Finally, we use tailwind for our component styling.
6. Config Top ▲
All the config is kept within the .env file.
The default is:
DATABASE_FILENAME=shortcut.db
DATABASE_URL=sqlite://${DATABASE_FILENAME}?mode=rwc
PORT=3000
UI_URL=http://localhost:${PORT}7. FAQ's Top ▲
Feel free to create any issues at: https://github.com/AlexTrebs/shortcut/issues
