Skip to content
webtypPublic

About

The application kit: one config turns WebTyp pieces (server, auth, permissions, session, menu) into a ready app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

166 Commits

Folders and files

Repository files navigation

appkit

The application kit: the app hands it what it chose (database, ids, broker, transports) and the list of its modules; it builds the app — modules in order, sign-in, operations, browser session — and picks no concrete itself.

Why This Exists

Without appkit, each app writes its module wiring, its login wiring (users, roles, first administrator, rate limit) and its browser session, and lists every module twice — once for the server, once for the menu. With appkit, the app declares App (what it is, its modules once), Backend (how each module is built, the transports), Server (what only the native server decides) and Browser (each module's screens); the main of each binary is one call.

Without With
config/server.go, config/auth.go, config/client.go App + Backend + Server + Browser
Every module listed for the server and again for the menu App.Modules, once, in build order
Login wiring written by hand App.SignIn: []auth.Mode{trustedip.Mode{Devices: staffmanager.Definition}} — each mode is a value; appkit builds it and never names it
Adapters written by hand between modules the module that provides exports a plain type; the app joins them with FindBuiltModule

Before You Start

  • Only the app imports appkit. Modules and access never do. appkit imports no database driver, HTTP server, transport, id generator or broker: the app passes them in.
  • Why three packages: appkit (only App and shared errors), appkit/backend (Backend, Server, Build) and appkit/browser (Browser, Run, NewSession). The import graph decides what enters each binary — no browser/!browser build tag needed.
  • Modules are built, migrated and shown in App.Modules order; whoever provides to another goes first. The first screen is the one opened first.
  • A listed module without its backend.Module (or browser.Module) is an error at start that names it; so is a part whose module is not listed.

Step-by-Step Guide

  1. What the app is — config/app.go (no tag):
var App = appkit.App{
	Name: "Acme", TenantID: "acme", Timezone: "America/Santiago",
	Countries: country.Catalog{ /* the default country and which go first */ },
	SignIn:    []auth.Mode{passkey.Mode{Origin: "https://app.example.com"}}, // without modes nobody enters and every guarded operation is denied
	Modules:   []model.ModuleDefinition{catalog.Definition, devices.Definition, staff.Definition},
	Log:       log.Println, // required (ErrNoLog)
}
  1. The backend — config/services/backend.go (server and Worker):
var Backend = backend.Backend{
	Events: &inprocess.Broker{}, API: rpc.JSON{}, Agents: mcp.Tools{Allowed: MCPTools()},
	Modules: []backend.Module{
		{Name: catalog.Definition.Name, Build: func(d backend.Deps) (model.ModuleNaming, error) {
			return catalog.New(d.DB, catalog.Deps{IDs: d.IDs, Publisher: d.Events, TenantID: d.TenantID})
		}},
		{Name: staff.Definition.Name, Build: buildStaff}, // asks device_manager for its devices with backend.FindBuiltModule
	},
}
  1. The native server — config/services/server.go (!wasm; a Worker adds config/services/edge.go):
var Server = backend.Server{Database: postgres.Open, NewIDs: func() (model.IDGenerator, error) { return unixid.NewUnixID() }}
  1. The browser — config/screens/browser.go:
var Browser = browser.Browser{
	Caller: rpc.NewCaller(""), NewIDs: func() (model.IDGenerator, error) { return unixid.NewUnixID() },
	Modules: []browser.Module{{Name: catalog.Definition.Name, Screens: catalogui.Screens}}, // Screens(d view.BrowserDeps)
}
  1. The mains (generated by webtyp.com/server):
// web/browser/main.go
func main() { browser.Run(config.App, screens.Browser, layoutapp.New(devtools.Menu())) }

// web/server/main.go — the HTTP server is created between Build and Mount because httpd.Config needs the three values Build returns
built, err := backend.Build(config.App, services.Backend, services.Server, dsn, services.Schema)
srv := httpd.New(httpd.Config{ /* … */ Authn: built.Authn, Authorize: built.Authorize, Policy: built.Policy})
err = built.Mount(srv.Router(), devtools.Server(services.Schema)...)

Log and Timezone are required (ErrNoLog, ErrNoTimezone). Build also logs, one line each, the columns the models no longer have but that hold data; it never drops them.

Default grants and external calls

What any signed-in person may do with a module is backend.Module.DefaultGrants, ensured at boot on rbac.RoleAuthenticated with the rbac that appkit builds itself. When entities declare ExternalCalls, Build creates the durable queue (webtyp.com/externalcalls), fills Deps.Queue, sets crud.SetDefaultQueue and starts the periodic executor. They need the queued_call table: the generated config/services/migrations.go always migrates it (webtyp.com/externalcalls/migrate), so the app writes nothing.

Importing history

backend.BuildModules(config.App, services.Backend, services.Server, tx) builds the modules on a transaction (the sign-in is not built): an import finds them with FindBuiltModule and every write rolls back with it.

Documentation Map

File What
docs/ARCHITECTURE.md Design and decisions
docs/TESTS.md Test suite inventory
app.go App (its SignIn lists auth.Mode values)
backend/backend.go Backend, Module, Server, API, Agents, Deps, FindBuiltModule
backend/build.go Build, Built.Mount, BuildModules
backend/signin.go / browser/signin.go The sign-in by trusted IP, server and screens
browser/browser.go Browser, Module, Run, NewSession
backend/external_calls.go NewCallQueue, NewCallRunner, StartCallExecutor
render_ssr.go App.RenderHTML: the loading card before the wasm downloads

About

The application kit: one config turns WebTyp pieces (server, auth, permissions, session, menu) into a ready app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages