This repository presents a seed for creating backend Rust applications -- with preset libs, UIs, services & design patterns.
Most likely, you'll need only a subset of the features provided by this template:
- Additional Runtimes:
- Tokio
- Reactive programming with the
reactive-mutiny
crate for event-driven / reactive & stream-based programming
- Services:
- Web, through
Rocket
- Angular UI app -- demo featuring the backend services API exploration (more details bellow)
- Angular backend app -- exposing metrics, logs, statistics. The demo exposes Tokio data and you may add your own
- embedded static & pre-compressed files -- including all Angular apps -- for blazing fast speeds
- Telegram, through
Teloxide
- stateless & stateful bot examples (with navigation)
- application initiated message sending
- messaging framework inspired on InstantVAS' Microservice pattern
- reactive-messaging with async Streams & Reactive pipelines for socket servers & clients
- Textual protocols (like FIX)
- Binary protocols
- Hooks for your own Service
- async with
Tokio
- async with
- Resilient Programming enabled by
keen-retry
- Web, through
- UIs:
- Console -- logging through
slog
with stdout and file sink options - Terminal --
tui
+crossterm
; - GUI --
egui
- on the native computer's UI and also on Web Assembly, sharing the same code
-
lottie
animations withrlottie
(even on web?) - charts with
plotters
- Integrated & embedded Angular UI application
- Angular Universal, automatically pre-rendering parameter-less routes
- Google Material theming & components
- Example app to test the web services provided in
src/frontend/web/api
, with flexible components - Loading speeds of ~50ms, enabling it to be used as landing pages
- Dashboard (using
coreui-free-angular-admin-template
-- Angular), containing:- Runtime metrics & stats
- Console -- logging through
- Configs:
- Application-wide
config pattern
, tying all features together + customizable to include your business logic - Command Line parsing through
structopt
, merging with the application-wide configs - Persistent config file using
ron
-- easily serializing any Rust type + automated DOCs generation
- Application-wide
- Injection / Runtime Repository:
- Application-wide
runtime pattern
, sharing runtime data to tie all features together + customizable to include your business logic - May be used as an
Injection Repository
- Application-wide
- Testing:
- Built-in example for Big-O analysis with
big-o-test
crate - Built-in example for Criterion bench
- Built-in example for Big-O analysis with
Tested in this environment:
- Linux
- Rust 1.70
- Node 20.4.0 (18.9.0 & 18.10.0 are known to mess up with Angular Universal -- more details in the link at the end)
- Trunk v0.17.2
- Init the submodule for the
web-stats
app:git submodule update --init --remote
- Build the angular web apps (you should have
Angular
&Node
previously setup). Note that if any of those commands fail, building the app in Release mode won't be possible:cd web-app/; npm i; npm run prerender; cd ..
cd web-stats/; npm i; npm run build; cd ..
- Build the web-egui app (you should have
Trunk
previously setup):cd web-egui/; ~/.cargo/bin/trunk build --release; cd ..
(make sure you havetrunk
& webasm build tools installed. If not,cargo install trunk
&rustup target add wasm32-unknown-unknown
) - Build the Rust app (release, optimized for the local processor):
RUSTFLAGS="-C target-cpu=native" cargo build --release
- Inspect the command line options (with
--help
) to pick up which UI to run. Bellow, how to run the standard console / daemon mode:./target/release/kickass-app-template console daemon
- After the first run, the default config file is create in the same directory as the binary -- named
kickass_app_template.config.ron
. Follow the instructions there & set the Telegram token for your bot as well as anychat id
s that you'd like to send push notifications to.
- Click
Use this template
, at the top right of this GitHub page - Edit
build.rs
and remove the web apps you don't want, removing their directories as well - Edit
Cargo.toml
and clean it up from the dependencies you don't need + associated code, then, failing to compile - Remodel
src/config
&src/command_line
modules to your needs -- then go ahead and do it forsrc/runtime
as well - Add all modules for your business logic
- Elect parts of your code for Big O analysis tests and update
tests/big-o-tests.rs
-- then do the same for Criterion inbench/
- Inspect & adjust the
src/frontend
module & submodules - Share back (through a PR) any improvements you do to the template
This template brings up a basis for
(due to Angular-Universal pre-rendering, only 44ms are needed to show the content -- 13ms to load index.html + 31ms to render it. After being presented, Angular is loaded and after 664ms we have a fully working website)
(the same code is shared between the native and web versions of the egui interface)
(the same code is shared between the native and web versions of the egui interface)
- https://update.angular.io
- (remember to add Universal, like this
ng update @angular/core@14 @angular/cli@14 @nguniversal/express-engine@14
) - 2022-10-07: bug on 18.9 Node versions: https://pullanswer.com/questions/prerendering-fails-on-node-js-18-9-but-succeeds-on-node-18-8