Getting started/Project Structure
Project Structure
Modular monolith layout, vertical slices, module boundaries, and code generators.
On this page
Fletch organizes applications as a modular monolith with vertical slices under modules/. There is no internal/ tree, no cmd/<name>/ nesting, and no tools/buildassets/ directory. Top-level directories map directly to application responsibilities, and fletch check enforces boundaries between modules at build time.
Directory layout
myapp/
main.go # entry point: bootstrap.App().Main(context.Background())
bootstrap/
app.go # config, database, subsystems, and app.Mount(...)
assets.go # embedded asset manifest
storage.go # storage.Store setup
config/
config.go # typed Config struct, Load, OpenDB, Migrate
app.yaml # base settings (plus database.yaml, mail.yaml, storage.yaml)
environments/
production.yaml # prod overrides (auto_migrate: false)
modules/
home/ # created by fletch new
billing/ # created by fletch make module billing
module.go # implements fletch.Module
routes.go # HTTP and LiveView routes
handlers.go # typed handlers and input structs
service.go # the module's public API
store.go # Nock queries, private to the module
schema/
schema.go # table definitions
schema_gen.go # generated by fletch gen
views/ # module-local .crest views and generated *_crest.go
policy.go # authorization policy types
events.go # module event types and subscribers
jobs.go # Quiver job registration
module_test.go # module tests
ui/
layouts/ # shared page shells (app.crest)
components/ # reusable Crest UI primitives
partials/ # shared app fragments (nav, header, flash)
emails/ # Crest email templates (created by fletch make email)
mailer/ # application email helpers (added when sending mail)
commands/ # custom CLI commands (fletch make command adds more)
resources/ # source stylesheets and scripts
database/
migrations/ # timestamped SQL migrations and snapshot.json
seeders/ # database seeders (fletch make seeder adds more)
public/ # static files served verbatim
storage/ # local SQLite database and local file storage
tests/ # cross-module integration tests
.fletch/ # local build cache, scaffold metadata, compiled tools
What fletch new creates vs. fletch make
fletch new generates the running skeleton: main.go, bootstrap/, config/, commands/, modules/home/, ui/layouts/, ui/components/, ui/partials/, database/migrations/, database/seeders/, resources/, public/, storage/, tests/, and .fletch/.
fletch make module writes the full slice shown above, including store.go, schema/, policy.go, events.go, and jobs.go, and adds the module to app.Mount(...) in bootstrap/app.go. Email pieces (ui/emails/, mailer/) appear only when you add them.
The fletch.Module interface
Every domain slice under modules/<name>/ exposes a constructor returning a fletch.Module:
type Module interface {
Name() string
Register(a *fletch.App) error
}
Register modules in bootstrap/app.go with app.Mount:
if err := app.Mount(
home.New(db, "myapp"),
billing.New(db, mailer),
); err != nil {
return nil, fmt.Errorf("mount modules: %w", err)
}
app.Mount(mods ...Module) error validates each module before calling Register. It returns an error if a module reports an empty Name() or if two mounted modules share the same name.
Keeping dependencies explicit in each module’s constructor (billing.New(db, mailer)) avoids package-level globals and makes modules straightforward to construct in tests.
Module schemas: schema.go vs. schema/
Nock discovers table definitions in two layouts inside any module:
- A single file at
modules/<name>/schema.goexportingvar Tables = []*schema.TableDef{...}. - A sub-package at
modules/<name>/schema/(for examplemodules/billing/schema/schema.go) exportingTables.
Both fletch db generate and fletch gen scan both layouts, but a module may use only one: declaring tables in both schema.go and schema/schema.go is an error. fletch make module uses the sub-package, so generated Row, New, Patch, and Col[T] symbols live in their own package namespace (schema.Invoices, schema.InvoicesRow) instead of crowding the module’s handler package. A small module can keep its tables in a single modules/<name>/schema.go instead, and fletch gen then writes modules/<name>/schema_gen.go alongside it.
Moving tables into modules/<name>/schema/ does not make them public to other modules. Diagnostic W0511 still blocks any other module from importing modules/<name>/schema or querying its tables directly. Cross-module reads and writes go through the owning module’s exported Go service API or through events.
Module boundary checks
fletch check inspects imports, module registration, schemas, and generated artifacts. Run it locally and in CI to keep vertical slices isolated:
| Code | Check | What triggers it |
|---|---|---|
W0510 |
Cross-module internal import | Code in modules/a imports an internal sub-package belonging to modules/b |
W0511 |
Cross-module table/schema access | Code in modules/a imports modules/b/schema or references a table owned by modules/b |
W0512 |
Unmounted module | A directory exists under modules/ that is never passed to app.Mount(...) |
W0513 |
Schema drift | Go schema.TableDef definitions differ from database/migrations/snapshot.json (run fletch db generate) |
W0514 |
Stale OpenAPI spec | Routes or input/output types changed without regenerating the OpenAPI document (run fletch gen) |
W0515 |
Invalid schema | A schema.TableDef fails validation (for example duplicate column names, broken foreign keys, or invalid defaults) |
The ui/ directory
Shared presentation code lives in ui/ instead of being duplicated across modules:
| Directory | Purpose |
|---|---|
ui/layouts/ |
Outer HTML document shells such as app.crest with <slot:head>, <slot:scripts>, and <slot />. |
ui/components/ |
Reusable Crest UI primitives (buttons, inputs, modals, tables) with no domain coupling. |
ui/partials/ |
Shared application fragments such as top navigation, sidebars, headers, and flash message banners. |
ui/emails/ |
Crest email templates and email layouts rendered via mail.RenderHTML(ctx, c). |
Module-specific pages stay inside modules/<name>/views/.
Code generators (fletch make)
All generators support --json for machine-readable output and --force to overwrite existing files.
| Command | Creates |
|---|---|
fletch make module <name> |
Vertical slice under modules/<name>/ (module.go, routes.go, handlers.go, service.go, store.go, schema/schema.go, views/, jobs.go, events.go, policy.go, module_test.go), mounted in bootstrap/app.go |
fletch make handler <module> <name> |
Typed HTTP handler and input struct inside modules/<module>/ |
fletch make live <module> <name> |
LiveView component, mount/event handlers, and .crest template inside modules/<module>/ |
fletch make job <module> <name> |
Quiver job args struct and worker handler in modules/<module>/ |
fletch make command <name> |
Custom application CLI command in commands/ |
fletch make policy <module> <name> |
A policy type in modules/<module>/policy.go |
fletch make migration <name> |
Manual timestamped SQL migration in database/migrations/ |
fletch make seeder <name> |
Database seeder in database/seeders/ |
fletch make email <name> |
Crest email template ui/emails/<name>.{go,crest} (plus ui/emails/layout.{go,crest} if missing) |
Offline documentation
Every Fletch release ships matching Markdown documentation accessible directly from the CLI without network access:
fletch docs list
fletch docs show modules
fletch docs search "W0511"
When run inside a project, fletch docs reads the documentation bundled with your pinned github.com/fletchhq/fletch module version first. Outside a Fletch project, it falls back to the copy embedded in the fletch CLI binary.