The Locus language is a declarative language for defining full-stack web applications. It is designed to be simple, expressive, and easy to learn. A Locus application is defined in one or more .locus
files, which are then compiled into a complete web application.
A Locus application is built from a few core concepts:
database
: Defines the data models, fields, and relationships for your application.page
: A top-level, routable component.component
: A reusable piece of UI and logic.store
: A block for defining globally accessible state.database
BlockThe database
block is used to define your application’s data structure. The Locus compiler will discover all .locus
files in your project, parse every database
block, and merge their contents into a single, unified schema.
An entity
is a blueprint for a data model, which translates directly to a database table.
database {
entity Customer {
name: String
email: String (unique)
subscribedAt: DateTime (default: now())
isActive: Boolean (default: true)
}
}
Type | Description |
---|---|
String |
For short text, like names, titles, or emails. |
Text |
For long-form text. |
Integer |
For whole numbers. |
Decimal |
For numbers with decimal points. |
Boolean |
For true/false values. |
DateTime |
For storing specific dates and times. |
Json |
For storing arbitrary JSON data. |
?
(Optional Marker): Marks a field as optional.(unique)
: Ensures that every value in this column is unique.(default: ...)
: Provides a default value.(map: "db_column_name")
: Specifies a different underlying column name in the database.orders: has_many Order
and customer: belongs_to Customer
.categories: has_many Category
and products: has_many Product
.(unique)
attribute to a belongs_to
field.page
, component
, and store
page
and component
StructureA page
or component
is organized into four main blocks:
state
: Declares the reactive data for the component.on load
and on unload
.action
: Contains the business logic.ui
: Declaratively describes the user interface.page CustomerList {
state {
customers: list of Customer = []
}
on load {
customers = find(Customer)
}
action deleteCustomer(customerToDelete: Customer) {
delete(customerToDelete)
customers.remove(customerToDelete)
}
ui {
// ...
}
}
store
)A store
defines state that is globally accessible.
store Auth {
currentUser: User?
isLoggedIn: false
}
Locus provides high-level functions for interacting with the database:
find(Entity)
findOne(Entity, where: { ... })
create(Entity, { ... })
update(record, { ... })
delete(record)
The ui
block uses an XML-like syntax to describe the user interface.
Use the bind:value
directive for two-way data binding on form inputs.
<TextField placeholder="Enter your name" bind:value={name} />
Use the on:event
directive to link UI events to actions.
<Button on:click={increment}>+1</Button>
<if>
, <elseif>
, <else>
for:each
<if condition={status == "loading"}>
<Spinner />
</if>
<ProductCard for:each={product in products} product={product} />