This guide covers the typical day-to-day workflow you’ll use when building an application with Locus. The process is designed to be fast, iterative, and keep you in a state of flow.
Your primary tool during development is the locus dev
command.
locus dev
This single command compiles your entire project, starts the backend API and frontend web server, and then actively watches all your .locus
files for changes.
Open Your Editor and Browser: Arrange your windows side-by-side. On one screen, have your code editor open to your .locus
files. On the other, have your web browser open to http://localhost:3000
.
.locus
files. The moment you hit save, locus dev
detects the change, incrementally rebuilds only what’s necessary, and automatically refreshes your browser. Changes to your UI and styling appear almost instantly.This edit -> save -> see changes
loop is the heart of the Locus workflow.
When you edit a database
block in any .locus
file, the workflow is slightly different.
entity
, field, or relationship.locus dev
will detect the change and print a message in your terminal telling you that your database schema is out of sync with your code. It will give you a locus db migrate
command to run.locus dev
running in the first) and run the suggested command. This will generate and apply a new migration, safely updating your database to match your new schema.Keeping a second terminal window open for database commands is a common practice during Locus development.
If things aren’t working as expected, you have a few tools at your disposal:
action
and on load
blocks.log()
function inside any action
to print values to the browser’s JavaScript console.
action doSomething() {
const myValue = "Hello, World!"
log(myValue) // This will appear in the browser console
}
locus db studio
in your second terminal to get a complete GUI for inspecting, adding, and deleting records in your database..locus
file, it’s often cleaner to separate major features into their own files (e.g., users.locus
, products.locus
, admin.locus
). Locus automatically merges them all at compile time.component
to keep your code DRY (Don’t Repeat Yourself).store
. For state that’s only used by a single page, keep it in that page’s state
block.design_system
block and reuse them. This makes it easy to keep your application’s look and feel consistent.