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.stew | Main page of a route. Defines a Page(w, data) function. | stew.page.go |
| @layout.stew | Layout wrapping the pages of a folder. Defines a Layout(w, data, slot) function. | stew.layout.go |
| Xxx.stew | Component (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.go | Automatically generated HTTP router at the project root. | stew generate |
| stew.page.go | Compiled output of a @page.stew file. | stew compile |
| stew.layout.go | Compiled output of a @layout.stew file. | stew compile |
| stew.middleware.go | Route middleware (optional, manually written). | Manual |
| server.go | Custom 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.