Skip to content

Latest commit

 

History

History
123 lines (102 loc) · 6.68 KB

README.md

File metadata and controls

123 lines (102 loc) · 6.68 KB

Production-ready seed & template for Rust Backend & Long Runner Applications

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:

  1. Additional Runtimes:
    • Tokio
    • Reactive programming with the reactive-mutiny crate for event-driven / reactive & stream-based programming
  2. 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
    • Resilient Programming enabled by keen-retry
  3. 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 with rlottie (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
  4. 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
  5. 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
  6. Testing:
    • Built-in example for Big-O analysis with big-o-test crate
    • Built-in example for Criterion bench

Running the default version

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
  1. Init the submodule for the web-stats app: git submodule update --init --remote
  2. 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 ..
  3. Build the web-egui app (you should have Trunk previously setup): cd web-egui/; ~/.cargo/bin/trunk build --release; cd .. (make sure you have trunk & webasm build tools installed. If not, cargo install trunk & rustup target add wasm32-unknown-unknown)
  4. Build the Rust app (release, optimized for the local processor): RUSTFLAGS="-C target-cpu=native" cargo build --release
  5. 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
  6. 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 any chat ids that you'd like to send push notifications to.

How to use it

  • 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 for src/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 in bench/
  • Inspect & adjust the src/frontend module & submodules
  • Share back (through a PR) any improvements you do to the template

Why

This template brings up a basis for

Screenshots

Angular

rust+angular+material 1.png rust+angular+material 2.png (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)

EGui (web + mobile)

egui-web.png (the same code is shared between the native and web versions of the egui interface)

Stats Web UI

rust+angular+internal_stats.png

Terminal UI

terminal-ui.png

EGui (native)

egui-fractal-clock-example.png egui-lottie-animations.jpg (the same code is shared between the native and web versions of the egui interface)

Telegram (chat UI)

telegram-bot.png

Command-Line options example

command-line-examples.png

Config .ron example

config-example.png

Notes on Angular upgrades for web-app