Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Directory Structure

lat new generates an application in this layout.

acme/
├── Cargo.toml
├── README.md
├── .gitignore
├── config/
│   ├── default.toml     # committed defaults
│   └── local.toml       # git-ignored; the database URL
├── plugins/
│   └── plugins.toml     # the installed plugins
├── plugins-manifest/    # generated by `lat plugin sync`
├── src/
│   ├── main.rs
│   └── migrations/      # the application's module and its migrations
└── storage/             # runtime data; git-ignored
PathHolds
Cargo.tomlThe application crate and the workspace its plugins join.
config/The layered configuration. See Application and Server.
plugins/Installed plugin crates and the list that names them. See Installing Plugins.
plugins-manifest/The generated crate that links the listed plugins. Never edited by hand.
src/main.rsThe entry point.
src/migrations/The application’s module and its migrations. See Migrations.
storage/Files the application keeps while it runs. backend.storage moves it.

Read main.rs

[dependencies]
lateritecmf = { version = "0.12", features = ["postgres"] }
laterite-core = "0.12"
plugins-manifest = { path = "plugins-manifest" }
use lateritecmf::prelude::*;

mod migrations;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    Bootstrap::new("config")
        // Every plugin under plugins/, as listed in plugins/plugins.toml.
        .modules(plugins_manifest::all())
        .module(migrations::AppModule)
        // .extend(|router, ctx| router.merge(my_api(ctx.db())))
        .run()
        .await
}
CallDescription
Bootstrap::new("config")The configuration directory, relative to the working directory.
.modules(..)The installed plugins.
.module(..)The application’s own module.
.extend(..)Merges the application’s own routes onto the admin router.

Read the module

src/migrations/mod.rs defines the application’s module:

use lateritecmf::prelude::*;

migration_set! {
    module_id: "acme",
}

pub struct AppModule;

impl Module for AppModule {
    fn id(&self) -> ModuleId {
        ModuleId::new(MODULE_ID)
    }
    fn migrations(&self) -> MigrationSet {
        migrations()
    }
}

lat make:migration <description> adds a file to the directory and lists it in the migration_set! block. The methods a module may add are in Writing a Plugin.

Read the configuration

# config/default.toml
[app]
name = "Acme Blog"
env_prefix = "LAT"
# url = "https://acme.example"

[server]
listen = "127.0.0.1:8080"

[backend]
timezone = "UTC"
secure_cookie = false
# path = "/admin"
# config/local.toml
[database]
url = "postgres://localhost/acme"

Every key is in Configuration.