Skip to content

Local Development ​

Start the App from the Project root. New Projects include the development configuration in .goforj.yml.

bash
forj dev
# Dev ready

GoForj runs the dependency setup, builds, and runtimes configured for your App. When you see Dev ready, try your first route in a second terminal. Press Ctrl+C to stop the session.

Use forj run <command> to run one App command outside the development loop.

What Happens When You Save ​

ChangeWhat GoForj does
Go source or environmentRebuild the App and restart it after a successful build.
Frontend sourceBuild the frontend, then rebuild and restart the App that serves it.
Build failureKeep the last working runtime and show the error in the transcript.

Fix a failed build and save again. The watcher picks up the edit. A failed frontend build leaves the App build alone until the frontend succeeds.

What forj dev Owns ​

SettingUse it for
dev.appsBuilding and running Apps and their frontends.
dev.watchesIndependent commands such as regenerating a client when its schema changes.

An App lifecycle builds only its own frontends. Custom watches share the development transcript. To make custom work a prerequisite for an App rebuild, include it in that App's build configuration.

Default App Lifecycle ​

In a Web UI Project, changes to Go or environment files go straight to the App build. Frontend changes go through the SPA build first.

The conventional runtime launches the App binary without arguments, which selects run. An explicit command such as ./bin/app worker selects that runtime instead.

The App Development Lifecycles reference shows the full npm example, including watcher paths and defaults. Generated npm tasks keep routine output quiet and retain error output. A successful SPA build can also be reused by forj build while its inputs and output are current. For templ and htmx, the App watcher includes .templ and ignores generated *_templ.go files.

Choose Which Apps Participate ​

List the Apps you want to manage in .goforj.yml.

yaml
dev:
  apps:
    app: true
    admin: true

true uses the conventional lifecycle. Omit an App to leave it unmanaged. Use dev.apps: {} to run only custom watches. CLI-only Apps are omitted by default. You can list one to build it, or set its run command to invoke it. Projects without a dev.apps key use legacy discovery.

Customize an App Lifecycle ​

SettingEffect
build: falseSkip the App build.
run: falseBuild the App without starting its runtime.
run: worker --queue reportsRun ./bin/<app> worker --queue reports.
run.exec: ./tools/serverRun the full command as written.
spas.frontend: ./cmd/app/frontendBuild the SPA at this path with the conventional lifecycle.

Use the build and run command reference for environment overrides, file matchers, polling, and other fields. App build ignores extend the conventional exclusions. A nonempty SPA ignore list replaces the SPA defaults.

Add a Custom Watch ​

Add a command under dev.watches when it can run independently of an App build. This one generates a client after a GraphQL schema changes.

yaml
dev:
  watches:
    - name: Generate API Client
      exec: go generate ./internal/client
      watch: [.graphql, .json]
      ignore: [generated, node_modules]
      root: .
      postpone: true

root identifies the watched directory. Set workdir separately when the command should run elsewhere. Custom watches use their own exclusions. See Native Matcher Syntax for lists and Legacy Watch Compatibility for scalar strings.

Startup and Shutdown ​

Startup builds any App commands needed by dev.pre, runs the pre-tasks, then runs configured database setup and migrations. Tasks that need the schema can run after migration. GoForj then builds frontends and their Apps and starts the persistent watchers and runtimes. See Development Tasks to configure setup and teardown.

On Ctrl+C, GoForj stops the watchers and runs dev.down when dev.down_on_exit is enabled. If local dependencies are still running after an interrupted session, run the teardown from the Project root.

bash
forj down

The command runs the configured down tasks in order and stops if a task fails.

Multi-App Projects ​

Run forj dev to manage all the Apps listed in dev.apps. To focus on the App named admin, run:

bash
forj admin dev

Project-level custom watches still run. App metadata assigns default HTTP ports such as 3000 for app, 3001 for admin, and 3002 for a third App. Use unique App-specific values for overrides. Additional Apps read their own port settings.

Environment Changes ​

GoForj watches the root .env and .env.* files even when a build watch list omits them. It reloads those files and coordinates rebuilds of participating Apps.

Transcript and Controls ​

The transcript records build output, restarts, and errors. Press ? in the interactive session to see controls for restarting watchers, rendering the Project, running commands, and opening local links. You can also follow the transcript in Lighthouse when devwatch support is enabled.

Common Mistakes ​

Remove an App entry to leave it unmanaged. Set run: false when you still want its build. Use the built binary under a supervisor for production. Use an absolute path or a path relative to the Project for local module replacements.

Next Steps ​