gowdk

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

README

GOWDK logo

GOWDK

CI Release Go

GOWDK is a compiler and runtime for shipping Go web apps. Write .gwdk files, get build-time pages, request-time backend behavior, opt-in SSR, and one-binary deploys while keeping application logic in Go.

GOWDK Compiler owns .gwdk parsing, analysis, route metadata, endpoint metadata, assets, generated adapter source, diagnostics, and LSP support. GOWDK Runtime owns serving, request context, actions, APIs, fragments, CSRF, contracts, SSR hooks, embedded assets, and one-binary wiring.

Live demo: gowdk.com Demo source: cssbruno/gowdk-page Simple login example: cssbruno/gowdk-simple-login

Status: pre-release. Public contracts can still change. Not production ready.

What It Looks Like

// pages/home.page.gwdk
package pages

import copy "github.com/acme/app/content"

use ui "components"

@page home
@route "/"

build {
  => copy.HomePageForBuild()
}

view {
  <main>
    <h1>{title}</h1>
    <p>{canonicalPath}</p>
    <ui.Counter />
  </main>
}

style {
  h1 { color: #0f766e; }
}
// content/home.go
package content

import (
	"strings"
)

type PageCopy struct {
	Title         string `json:"title"`
	Slug          string `json:"slug"`
	CanonicalPath string `json:"canonicalPath"`
}

func HomePageForBuild() PageCopy {
	title := "GOWDK ships apps"
	slug := strings.ToLower(strings.ReplaceAll(title, " ", "-"))

	return PageCopy{
		Title:         title,
		Slug:          slug,
		CanonicalPath: "/posts/" + slug,
	}
}
// components/counter.cmp.gwdk
package components

import ui "github.com/acme/app/ui"

@component Counter

state ui.CounterState = ui.NewCounterState()

client {
  computed Label string {
    return if Count == 0 { "Start" } else { string(Count) }
  }

  fn Increment() {
    Count++
  }

  fn Reset() {
    Count = 0
  }
}

view {
  <section .counter>
    <p class:active={Count > 0}>{Label}</p>
    <button g:on:click={Increment()}>Add</button>
    <button g:if={Count > 0} g:on:click={Reset()}>Reset</button>
  </section>
}

style {
  .counter { display: grid; gap: 0.75rem; }
  .active { color: #0f766e; }
}

Programming logic stays in Go. Today that means normal .go files imported or referenced from .gwdk, plus default go {} blocks for colocated static helpers. Saved default go {} blocks are type-checked with sibling Go files during validation. build {} can call an imported or inline no-argument Go function at build time, JSON-encode its returned object, and expose scalar fields to view {}. Request-time and addon-targeted go blocks are parsed and validated; generated apps can execute go ssr {} load handlers, page-level go client {} can opt into client-side Go by exporting //go:wasmexport GOWDKMount<PageID> for a generated WASM page loader, and configured addons that implement gowdk.GoBlockConsumer can validate go addon.<name> {} blocks and emit generated app Go files. Generated app source materializes default go {} and go ssr {} blocks as normal Go packages under gowdk_go/.

Pages can stay build-time while components own local reactive state; the compiler generates the island runtime for client {} handlers, computed values, bindings, class toggles, and conditional DOM.

API And Frontend In One File

Page files can declare backend endpoints beside the frontend they serve. Default go {} blocks can provide build-time copy and same-page API handlers when the handler uses the supported API signature.

// pages/dashboard.page.gwdk
package pages

@page dashboard
@route "/dashboard"

api Session GET "/api/session"

build {
  => DashboardCopyForBuild()
}

go {
import (
	"context"
	"net/http"
	"strings"

	"github.com/cssbruno/gowdk/runtime/response"
)

type DashboardCopy struct {
	Title   string `json:"title"`
	Summary string `json:"summary"`
}

func DashboardCopyForBuild() DashboardCopy {
	return DashboardCopy{
		Title:   "Dashboard",
		Summary: "This page and its API live in one GOWDK file.",
	}
}

func Session(_ context.Context, request *http.Request) (response.Response, error) {
	user := strings.TrimSpace(request.URL.Query().Get("user"))
	if user == "" {
		user = "guest"
	}

	return response.JSONValue(http.StatusOK, map[string]any{
		"authenticated": user != "guest",
		"user":          user,
		"source":        "pages/dashboard.page.gwdk",
	})
}
}

view {
  <main class="dashboard">
    <section class="panel">
      <h1>{title}</h1>
      <p>{summary}</p>

      <form method="get" action="/api/session">
        <label for="user">User</label>
        <input id="user" name="user" value="ada" />
        <button type="submit">Open API JSON</button>
      </form>

      <a href="/api/session?user=ada">Inspect session API</a>
    </section>
  </main>
}

style {
  .dashboard { min-height: 100vh; display: grid; place-items: center; }
  .panel { display: grid; gap: 1rem; max-width: 34rem; }
  form { display: flex; gap: 0.5rem; align-items: end; }
}

How It Works

  • Build-time by default: full pages compile to SPA output with route and asset manifests.
  • Request-time only where needed: @render ssr opts a page into supported load {}, guards, route params, redirects, and generated error pages.
  • Backend behavior without full SSR: actions, APIs, fragments, commands, and queries run per request without making every page request-rendered.
  • Direct CSS: style {} emits generated CSS assets. Component CSS, scoped CSS, processors, and Tailwind CLI integration are available in bounded slices.
  • Generated Go is adapter glue: generated code can decode supported typed inputs, validate supported form fields, wire CSRF, run guards, and apply optional rate limiting.
  • One-binary deploys: generated apps can embed frontend output and request-time handlers into a single Go binary.

Event-Driven Contracts

GOWDK can enable a typed contract runtime through the contracts addon:

UI event -> command/query -> backend handler -> backend event
UI <- result or presentation event
  • g:command binds forms to backend commands.
  • g:query binds elements to readonly backend queries.
  • Commands have one owner.
  • Domain and integration events are emitted after command success.
  • Presentation events notify UI but are not trusted input.
  • Jobs, event capture/replay, role filtering, graph/trace CLI, file outbox, local in-memory broker, Redis Streams, NATS, SSE, and WebSocket fanout support exist today.

See Contracts.

Install

git clone https://github.com/cssbruno/GoWDK.git
cd GoWDK
go build ./cmd/gowdk

Quickstart

Scaffolded App
./gowdk init --tests --template site ~/my-app
cd ~/my-app
/path/to/GoWDK/gowdk build
./bin/site

Open http://127.0.0.1:8080.

The scaffolded config builds hidden frontend output in .gowdk/output/site, generates .gowdk/site, and compiles bin/site. Use gowdk serve --dir .gowdk/output/site only for static inspection; it does not run backend handlers.

Ad Hoc Binary
/path/to/GoWDK/gowdk build --app dist/app --bin dist/my-app
./dist/my-app

This builds a Go binary that serves embedded frontend output alongside supported backend handlers, commands, queries, fragments, and SSR routes.

CLI Reference

gowdk init [dir]
gowdk check
gowdk build [--app <dir>] [--bin <file>]
gowdk dev
gowdk serve --dir <dir>
gowdk contracts | graph | trace | list
gowdk fmt | manifest | sitemap | routes | lsp

See CLI reference.

Current Status

Area Status
Pages, routes, layouts, and render modes Available
Build-time SPA output Available
Actions, APIs, and fragments Available
Commands, queries, and contracts addon Available
Direct style {} CSS assets Available
One-binary deploys Available
LSP server Available
SSR with load {}, guards, params, and errors Partial
Component behavior, client behavior, and scoped CSS Partial
WASM islands Partial
go {} metadata for inline Go authoring Available
Build-time default go block functions for build {} Partial
Client-side go client {} page mounts through Go WASM Partial
Request-time go ssr {} load execution Partial
Addon inline Go adapter file generation Partial
Hybrid request-time routes Partial
Split worker/cron contract wiring Planned
Durable outbox, broker, and realtime adapters Partial
Production operations guidance Available

See Requirements for the full status table and Roadmap for planned work.

Docs

Documentation

Index

Constants

View Source
const DefaultCSRFSecretEnv = "GOWDK_CSRF_SECRET"

Variables

This section is empty.

Functions

This section is empty.

Types

type Addon

type Addon interface {
	Name() string
	Features() []Feature
}

Addon is the minimal contract every optional GOWDK capability implements.

func NewAddon

func NewAddon(name string, features ...Feature) Addon

NewAddon creates a simple addon declaration for capability registration.

type AssetMode

type AssetMode string

AssetMode controls how frontend artifacts are shipped.

const (
	AssetExternal AssetMode = "external"
	Embed         AssetMode = "embed"
)

type BuildConfig

type BuildConfig struct {
	Output              string
	Mode                BuildMode
	Assets              AssetMode
	Head                HeadConfig
	CSRF                CSRFConfig
	AllowMissingBackend bool
	Stylesheets         []Stylesheet
	Targets             []BuildTargetConfig
}

BuildConfig controls output artifacts and frontend asset packaging.

func (BuildConfig) DebugAssets

func (config BuildConfig) DebugAssets() bool

DebugAssets reports whether generated frontend artifacts should include debugging metadata.

type BuildMode

type BuildMode string

BuildMode controls whether generated frontend artifacts include development metadata such as source maps. Development is the default when omitted.

const (
	Development BuildMode = "development"
	Production  BuildMode = "production"
)

type BuildTargetConfig

type BuildTargetConfig struct {
	Name          string
	Modules       []string
	Output        string
	App           string
	Binary        string
	WASM          string
	BackendApp    string
	BackendBinary string
}

BuildTargetConfig declares one configured build target. Modules selects the configured source modules compiled into Output, App, Binary, WASM, BackendApp, and BackendBinary.

type CSRFConfig added in v0.1.5

type CSRFConfig struct {
	Enabled    bool
	SecretEnv  string
	CookieName string
	FieldName  string
	HeaderName string
	Insecure   bool
}

CSRFConfig controls generated action CSRF token wiring.

func (CSRFConfig) SecretEnvName added in v0.1.5

func (config CSRFConfig) SecretEnvName() string

SecretEnvName returns the environment variable used by generated apps to read the CSRF signing secret.

type CSSAsset

type CSSAsset struct {
	Path     string
	Contents []byte
}

CSSAsset is a CSS file emitted by a compile-time CSS processor.

type CSSConfig

type CSSConfig struct {
	Include []string
	Exclude []string
	Default []string
	Output  CSSOutputConfig
}

CSSConfig controls discovered CSS inputs and page CSS output.

type CSSContext

type CSSContext struct {
	Sources   []CSSSource
	OutputDir string
	Build     BuildConfig
	CSS       CSSConfig
}

CSSContext is passed to compile-time CSS processors.

type CSSOutputConfig

type CSSOutputConfig struct {
	Dir        string
	HrefPrefix string
}

CSSOutputConfig controls generated page stylesheet locations.

type CSSProcessor

type CSSProcessor interface {
	Addon
	ProcessCSS(CSSContext) (CSSResult, error)
}

CSSProcessor is implemented by addons that emit CSS at build time.

type CSSResult

type CSSResult struct {
	Assets          []CSSAsset
	Stylesheets     []Stylesheet
	PageStylesheets map[string][]Stylesheet
}

CSSResult is returned by compile-time CSS processors.

type CSSSource

type CSSSource struct {
	Path       string
	Kind       string
	Name       string
	CSSClasses []string
}

CSSSource describes one discovered source file for compile-time CSS plugins.

type Config

type Config struct {
	AppName string
	Source  SourceConfig
	Modules []ModuleConfig
	Render  RenderConfig
	Build   BuildConfig
	CSS     CSSConfig
	Addons  []Addon
}

Config describes how a GOWDK application should be discovered, compiled, and packaged.

func (Config) HasFeature

func (config Config) HasFeature(feature Feature) bool

HasFeature reports whether a config enables a feature through an addon.

type Feature

type Feature string

Feature names the capabilities that addons make available to the compiler.

const (
	FeatureSPA       Feature = "spa"
	FeatureActions   Feature = "actions"
	FeaturePartial   Feature = "partial"
	FeatureSSR       Feature = "ssr"
	FeatureAPI       Feature = "api"
	FeatureEmbed     Feature = "embed"
	FeatureCSS       Feature = "css"
	FeatureRateLimit Feature = "ratelimit"
	FeatureContracts Feature = "contracts"
)

type FeatureSet

type FeatureSet map[Feature]bool

FeatureSet is a lookup table of enabled addon capabilities.

func EnabledFeatures

func EnabledFeatures(config Config) FeatureSet

EnabledFeatures returns the set of capabilities enabled by a config.

func (FeatureSet) Has

func (features FeatureSet) Has(feature Feature) bool

Has reports whether a feature is present in the set.

type GoBlockConsumer added in v0.1.5

type GoBlockConsumer interface {
	GoBlockTargets() []string
	ValidateGoBlock(target GoBlockTarget, context GoBlockContext) []GoBlockDiagnostic
	GeneratedGo(target GoBlockTarget, context GoBlockContext) ([]GoBlockFile, error)
}

GoBlockConsumer is an optional addon extension point for targeted go blocks such as go addon.contracts {}.

type GoBlockContext added in v0.1.5

type GoBlockContext struct {
	Render RenderMode
}

GoBlockContext describes the compiler lane that owns a go block target.

type GoBlockDiagnostic added in v0.1.5

type GoBlockDiagnostic struct {
	Code    string
	Message string
	Span    SourceSpan
}

GoBlockDiagnostic is an addon-produced diagnostic for a go block target.

type GoBlockFile added in v0.1.5

type GoBlockFile struct {
	Path    string
	Source  string
	Package string
}

GoBlockFile is a generated file emitted by an addon go block consumer. Path is relative to the generated app directory.

type GoBlockTarget added in v0.1.5

type GoBlockTarget struct {
	Target       string
	OwnerKind    string
	OwnerID      string
	OwnerPackage string
	SourcePath   string
	Body         string
	Span         SourceSpan
}

GoBlockTarget describes one parsed go block passed to an addon.

type HeadConfig added in v0.1.5

type HeadConfig struct {
	SiteName    string
	Favicon     string
	Image       string
	TwitterCard string
}

HeadConfig controls app-level document head tags emitted around page metadata.

type ModuleConfig

type ModuleConfig struct {
	Name   string
	Type   string
	Source SourceConfig
}

ModuleConfig names a source group inside a GOWDK app. Build discovery uses selected module sources to decide what gets compiled into output, generated apps, and generated binaries. Type is user-defined metadata.

type RenderConfig

type RenderConfig struct {
	Default RenderMode
}

RenderConfig controls default render behavior. SPA is the default when omitted.

func (RenderConfig) DefaultMode

func (config RenderConfig) DefaultMode() RenderMode

DefaultMode returns SPA when no explicit default render mode is set.

type RenderMode

type RenderMode string

RenderMode describes where full-page HTML is produced.

const (
	// SPA emits a non-SSR app shell and client-side route experience.
	SPA RenderMode = "spa"
	// Action emits a non-SSR app shell while allowing backend actions.
	Action RenderMode = "action"
	// Hybrid allows a route to combine app output and request-time behavior.
	Hybrid RenderMode = "hybrid"
	// SSR renders full pages at request time through the SSR addon.
	SSR RenderMode = "ssr"
)

func ParseRenderMode

func ParseRenderMode(value string) (RenderMode, error)

ParseRenderMode validates a render mode from source.

func (RenderMode) IsBuildTime

func (mode RenderMode) IsBuildTime() bool

IsBuildTime reports whether this mode is always build-time. Hybrid defaults to build-time unless explicit request-time capabilities are declared.

func (RenderMode) RequiresSSR

func (mode RenderMode) RequiresSSR() bool

RequiresSSR reports whether this mode always needs the SSR addon. Hybrid pages need SSR only when they declare explicit request-time capabilities.

type SourceConfig

type SourceConfig struct {
	Include []string
	Exclude []string
}

SourceConfig selects portable .gwdk files for discovery.

type SourcePosition added in v0.1.5

type SourcePosition struct {
	Line   int
	Column int
}

SourcePosition is a 1-based source location exposed to addon go block consumers.

type SourceSpan added in v0.1.5

type SourceSpan struct {
	Start SourcePosition
	End   SourcePosition
}

SourceSpan is a 1-based source range exposed to addon go block consumers.

type Stylesheet

type Stylesheet struct {
	Href string
}

Stylesheet describes one stylesheet link emitted into generated HTML.

Directories

Path Synopsis
addons
api
contracts
Package contracts declares the contract-driven runtime compiler capability.
Package contracts declares the contract-driven runtime compiler capability.
css
Package css registers compile-time CSS extension support.
Package css registers compile-time CSS extension support.
ratelimit
Package ratelimit provides HTTP rate limiting for generated or user-owned request-time handlers.
Package ratelimit provides HTTP rate limiting for generated or user-owned request-time handlers.
spa
ssr
tailwind
Package tailwind integrates Tailwind CSS v4 through the standalone CLI.
Package tailwind integrates Tailwind CSS v4 through the standalone CLI.
cmd
gowdk command
gowdk-wasm command
examples
css command
login command
tailwind command
internal
appgen
Package appgen emits a generated Go app that embeds build output.
Package appgen emits a generated Go app that embeds build output.
buildgen
Package buildgen emits app-shell HTML artifacts for build-time pages.
Package buildgen emits app-shell HTML artifacts for build-time pages.
clientlang
Package clientlang parses GOWDK component-local client handlers.
Package clientlang parses GOWDK component-local client handlers.
clientrt
Package clientrt emits the tiny client runtime used for partial updates.
Package clientrt emits the tiny client runtime used for partial updates.
contractscan
Package contractscan discovers runtime contract registrations in normal Go source using the standard Go AST.
Package contractscan discovers runtime contract registrations in normal Go source using the standard Go AST.
cssscope
Package cssscope builds deterministic scope and hash metadata for scoped CSS.
Package cssscope builds deterministic scope and hash metadata for scoped CSS.
discover
Package discover finds portable .gwdk files from source include patterns.
Package discover finds portable .gwdk files from source include patterns.
goblockgen
Package goblockgen turns captured go blocks into normal generated Go package source used by build and app generation.
Package goblockgen turns captured go blocks into normal generated Go package source used by build and app generation.
gotypes
Package gotypes resolves Go contracts referenced from .gwdk component files.
Package gotypes resolves Go contracts referenced from .gwdk component files.
gwdkanalysis
Package gwdkanalysis lowers GOWDK AST files into normalized manifest and IR metadata.
Package gwdkanalysis lowers GOWDK AST files into normalized manifest and IR metadata.
gwdkast
Package gwdkast defines the typed syntax tree for .gwdk source files.
Package gwdkast defines the typed syntax tree for .gwdk source files.
gwdkir
Package gwdkir defines the stable internal representation shared by GOWDK compiler passes after .gwdk AST analysis.
Package gwdkir defines the stable internal representation shared by GOWDK compiler passes after .gwdk AST analysis.
lsp
Package lsp implements the GOWDK Language Server Protocol entrypoint.
Package lsp implements the GOWDK Language Server Protocol entrypoint.
parser
Package parser turns .gwdk source files into syntax trees.
Package parser turns .gwdk source files into syntax trees.
project
Package project loads project-level compiler configuration.
Package project loads project-level compiler configuration.
view
Package view parses and renders the first subset of view {} markup.
Package view parses and renders the first subset of view {} markup.
Package playground exposes an in-memory compiler suitable for browser playgrounds and WASM wrappers.
Package playground exposes an in-memory compiler suitable for browser playgrounds and WASM wrappers.
runtime
adapters/echo
Package echo adapts a generated GOWDK app handler to Echo.
Package echo adapts a generated GOWDK app handler to Echo.
adapters/fiber
Package fiber adapts a generated GOWDK app handler to Fiber.
Package fiber adapts a generated GOWDK app handler to Fiber.
adapters/gin
Package gin adapts a generated GOWDK app handler to Gin.
Package gin adapts a generated GOWDK app handler to Gin.
app
contracts
Package contracts provides the local typed contract registry used by GOWDK runtime roles.
Package contracts provides the local typed contract registry used by GOWDK runtime roles.
contracts/fileoutbox
Package fileoutbox provides a dependency-free JSON Lines outbox adapter for runtime/contracts.
Package fileoutbox provides a dependency-free JSON Lines outbox adapter for runtime/contracts.
contracts/membroker
Package membroker provides an in-memory broker adapter for runtime/contracts.
Package membroker provides an in-memory broker adapter for runtime/contracts.
contracts/natsbroker
Package natsbroker provides a NATS adapter for runtime/contracts.
Package natsbroker provides a NATS adapter for runtime/contracts.
contracts/redisstream
Package redisstream provides a Redis Streams adapter for runtime/contracts.
Package redisstream provides a Redis Streams adapter for runtime/contracts.
contracts/sse
Package sse provides a dependency-free server-sent events presentation fanout adapter for runtime/contracts.
Package sse provides a dependency-free server-sent events presentation fanout adapter for runtime/contracts.
contracts/websocketfanout
Package websocketfanout provides a WebSocket presentation fanout adapter for runtime/contracts.
Package websocketfanout provides a WebSocket presentation fanout adapter for runtime/contracts.
testfixture

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL