Guide / 07

Reserved Files

Stew uses strict naming conventions. Certain files and directories have particular meanings within the framework.

.stew Files

File Role Generates
@page.stewMain page of a route. Defines a Page(w, data) function.stew.page.go
@layout.stewLayout wrapping the pages of a folder. Defines a Layout(w, data, slot) function.stew.layout.go
Xxx.stewComponent (name starts with an uppercase letter). Defines Xxx(w, data, props, slot).Xxx.go
Critical Rule: The @ prefix denotes reserved Stew files (@page, @layout). Component files must start with an uppercase letter. All other lowercase .stew filenames will be ignored.

Reserved Go Files

File Role Produced by
stew_router_gen.goAutomatically generated HTTP router at the project root.stew generate
stew.page.goCompiled output of a @page.stew file.stew compile
stew.layout.goCompiled output of a @layout.stew file.stew compile
stew.middleware.goRoute middleware (optional, manually written).Manual
server.goCustom Go handlers (POST, DELETE, etc.) for a route.Manual

Reserved Directories

Directory Role
pages/Routing root. Mandatory.
static/Static assets served under /static/. Automatically created.
static/wasm/Generated .wasm binaries by stew compile + wasm_exec.js.
.stew/Internal file tracker cache. Gitignored. Purged by stew clean.
__name__/Folder between double underscores = dynamic URL parameter.

Middleware File stew.middleware.go

To add a middleware to a route, create a stew.middleware.go file in the route's folder with a Middleware function:

// pages/admin/stew.middleware.go
package admin

import "net/http"

func Middleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        if r.Header.Get("Authorization") == "" {
            http.Redirect(w, r, "/login", http.StatusFound)
            return
        }
        next.ServeHTTP(w, r)
    })
}

The router automatically detects this file and chains the middleware in stew_router_gen.go.