#awto #protobuf #schema #macros


Compile microservices built with Awto

3 releases

0.1.2 Oct 21, 2021
0.1.1 Oct 18, 2021
0.1.0 Oct 17, 2021

#1404 in Database interfaces


1.5K SLoC


Awtomate your 🦀 microservices with awto


What is awto?

Awto treats your rust project as the source of truth for microservices, and generates database tables and protobufs based on your schema and service.

Database Generation

  • Database tables are generated from your Rust structs
  • Changes to your structs are detected and will modify the table schema accordingly

Protobuf Generation

  • Generate protobuf schemas from your models
  • Compile a protobuf server from your app's service


With awto, you create a Cargo workspace for each microservice. Under your workspace, you create two libs: schema and service


The schema lib's purpose is to define your microservice models which will be used to generate database tables.

// schema/src/lib.rs
use awto::prelude::*;

schema! {
    pub struct Product {
        pub id: Uuid,
        pub created_at: DateTime<FixedOffset>,
        pub updated_at: DateTime<FixedOffset>,
        pub name: String,
        #[awto(max_len = 120)]
        pub description: Option<String>,
        #[awto(default = 0)]
        pub price: i64,

See example schema in examples/ecom.


The service lib is where you write your business logic. This business logic can later be used to create a protobuf API (and in the future a graphql API).

// service/src/lib.rs


pub struct ProductService {
    pub conn: DatabaseConnection,

impl ProductService {
    pub async fn find_by_id(&self, request: ProductId) -> Result<Product, Status> {
        let product = product::Entity::find_by_id(request.id)
            .map_err(|err| Status::internal(err.to_string()))?
            .ok_or_else(|| Status::not_found("product not found"))?;


See example service in examples/ecom.

Cargo workspace

Your schema and service libs should be under a cargo workspace.

members = ["schema", "service"]

See example project in examples/ecom.

Awto CLI

Awto provides a cli for generating additional libraries with the awto compile <lib> command. Currently the available libraries are:

  • database - based on SeaORM, provides a database library for use in your service
  • protobuf - based on tonic, provides a protobuf server library


The cli can be installed with:

cargo install awto-cli

This will provide a binary called awto.

Check installation with awto --help.

Compile library

To compile a library, you can run:

awto compile <output>

The available outputs currently are:

  • database - syncs your database with your schema and generates a lib for performing operations with the database via SeaORM.
  • protobuf - generates a protobuf file and lib which can be used as a protobuf server & client via tonic.


Awto is still in alpha stages and is made mostly as an experiment at this point. If it gets some attention, serious effort will be put into it to make it a meaningful tool for the Rust community.


Whether you want to share ideas, bugs, suggestions, or other, your contributions to this project are welcomed 🤌


By contributing, you agree that your contributions will be licensed under this repository's MIT or Apache-2.0 License.


~683K SLoC