PhaseLock for developers
Fall in love with building apps that people fall in love with
Your apps should bring joy to the people who use them.
Navigation should be instant, collaboration should be live, and features should Just Work even when the network fails.
With traditional systems, building those features ranges from "difficult" to "nightmarish".
But PhaseLock makes those features automatic. Your PhaseLock app has features on day one that most apps will never achieve, and you get to focus on building delightful experiences atop that foundation.
What are the steps to build a PhaseLock app?
If you know how to build a CRUD app, you already know all the steps to building a PhaseLock app. Each step just looks a bit different for PhaseLock:
| PhaseLock step | CRUD equivalent |
|---|---|
| Write your data model | an SQL schema and OpenAPI spec |
| Write your business logic | GET and POST request handlers |
| Connect your UI | fetching, caching, and invalidating |
Let's look at each step one by one.
1 Write your data model
First step: define your data model. In PhaseLock, this means declaring your store types, your mutations, and your queries.
In CRUD, this step probably means SQL to define the database schema and an OpenAPI spec to declare the POST and GET requests and responses.
In PhaseLock, it's all done in TypeSpec, looking something like this:
alias Uuid = string; alias Isbn = string; // a store object model Book { id: Uuid; isbn: Isbn; title: string; } interface BookQueries extends Queries { // a query definition getBook(id: Uuid): Book; } // a mutation object model RetitleBook { type: "retitle-book"; bookId: Uuid; title: string; }
2 Write your business logic
Next, you define your business logic (queries and mutation handling). In a CRUD app, these are GET and POST request handlers in the API server, written in a mix of server code and SQL code.
In PhaseLock, they're plain TypeScript functions. The queries run in the client against the client's local store, and the mutation handlers run in both the server and the client (for optimistic updates and offline mode).
Here's an example:
// a simple query definition function getBook( qx: BookQueryContext, id: Uuid, ): Book { return qx.get.book(id); } // a simple mutation handler function handleRetitleBook( txn: BookTxn, req: RetitleBook, ): void { txn.update.book(req.bookId, (book) => { book.title = req.title; }); }
LLMs are exceedingly good at authoring this sort of business logic.
3 Connect your UI
PhaseLock queries are live queries designed to be connected to reactive UIs.
Here's an example of a React UI component to show a book title:
type Props = { queries: BookQueries; id: Uuid };
export function BookTitle({ queries, id }: Props) {
const book = useQuery(queries, 'getBook', id);
return <h2>{book?.title ?? 'Loading…'}</h2>;
}
And here's an example using Jetpack Compose on Android:
@Composable fun BookTitle(queries: BookQueries, id: String) { val book by remember(queries, id) { queries.getBook(id) }.collectAsStateWithLifecycle(null) Text(book?.title ?: "Loading…") }
Conclusion
PhaseLock takes the same conceptual steps you follow for your CRUD app and rearranges them into a tech stack that delivers advanced features like instant navigation, live sync, and offline mode. See it in action with our interactive demo.
Ready to get started?