Bwf/ GuideFrançais
Bwf Guide

Explore and modify the Journal

Run the Journal shipped with Bwf. Follow a two-reader workflow through its views, controllers, PostgreSQL queries, and live updates.

Start the Journal

Install the Bwf build tools and the Journal’s database and cryptography dependencies. On macOS with Homebrew, run brew install libpq openssl@3 postgresql@18, then export BWF_PG_BIN="$(brew --prefix postgresql@18)/bin". On Debian or Ubuntu, run sudo apt install postgresql libpq-dev libssl-dev.

Open a terminal in the directory where you want to clone Bwf. On macOS, use the same terminal where you set BWF_PG_BIN.

git clone https://github.com/vcombey/bwf.git &&
cd bwf &&
npm ci &&
./scripts/bwf dev

If you already cloned Bwf and ran npm ci, run ./scripts/bwf dev from the checkout root. If port 18088 is busy, run BWF_PORT=18089 ./scripts/bwf dev and use port 18089 throughout this tutorial. The first launch installs Bend, compiles the tools, and creates the Journal’s development database in .bwf/postgres. If Bwf can’t find the server tools, set BWF_PG_BIN to the directory containing postgres, initdb, and pg_ctl.

Wait for Bwf listening and open the local Journal. A fresh database shows an empty feed. Keep the server running for the rest of the tutorial. The file paths below start at examples/canonical/ inside your checkout.

1. Change the home page

In View/Home.bsx, change the text in <h1>Journal</h1>. Save, wait for the rebuild to finish, and reload the page. The heading reflects your edit.

In openapi.yaml, find the GET for /. RouteBindings.bend maps Api.OnHome to the action in Controller/Articles/Index.bend. That action loads the feed and renders the view you edited. For a minimal server you can write yourself, see Your first BSX page.

2. Register two readers

Register camille with camille@example.test and a test password of at least eight characters. In a private window, register lou with lou@example.test. Use unique addresses and names if you’ve used the database before. Open Settings in each window and compare the usernames.

Read the POST /register contract and Controller/Account/Register/Submit.bend. The action validates the input, writes the account, and returns a redirect that signs the reader in. The two windows retain independent session cookies. See Sessions and access and Form validation.

3. Publish and edit an article

As Camille, select Write. Enter My first keyboard, a description, and a body. Use the tags workshop, keyboard and select Save article. Copy the article URL. Edit its title, then open the copied URL as Lou. The new title is visible and editing controls appear only for Camille.

Compare Controller/Articles/Create.bend and Controller/Articles/Update.bend. Creation assigns the slug. The update uses the slug and the signed-in author ID in the same SQL predicate. See Authorization and ownership.

4. Filter the feed by tag

Publish a second article without the keyboard tag. Select keyboard under Popular tags. Open the resulting /?tag=keyboard URL as Lou. The second article is absent.

Open Controller/Articles/Index.bend and View/Feed.bsx. The query fetches up to eleven rows. The view renders ten and shows Next when the extra row exists. Follow the query and link construction in the pagination chapter.

5. Discuss the article

As Lou, use Post comment to add a message. Open the article as Camille and reply. Each reader can delete their own comment. Open the article in a signed-out browser session to confirm that the discussion is public.

View/Article.bsx renders the forms. Controller/Articles/Comments/Remove.bend checks the comment ID, article, and signed-in author in the deletion query. See Forms and CSRF protection.

6. Follow an author

Give Camille a bio from Settings. As Lou, select Camille’s username on the article, check her bio, then select Follow. Select Following on the home page. Camille’s articles are in the feed. Unfollow her and compare.

In Migrations/007_journal_schema.sql, the follows table stores the reader in follower and the author in followed. The feed query uses that direction when selecting articles. See Social feeds and profiles.

7. Save a favorite

As Lou, select the heart on the keyboard article. Open /profile/lou/favorites, using your actual username if it differs. The article appears under Favorited articles. Remove the favorite and check the list again.

Read Controller/Articles/Favorites/Add.bend and Remove.bend in the same directory. The operation changes a row in article_favorites. Its composite key limits each reader to one favorite per article.

8. Watch a live update and read the JSON

Open the same article in both windows. Type a draft comment as Camille and leave it unsent. Post another comment as Lou. Camille’s discussion updates and her draft stays in the input. The HTML action in Controller/Articles/Show.bend uses AutoRefresh.autoRefreshWith through its Live import. See Auto Refresh.

As Camille, edit the article and add **Build complete** on its own line. The article displays it in bold. The Markdown source is rendered by static/journal.mjs.

In another terminal, set ARTICLE_URL to the article URL you copied. Request the same article with a JSON Accept header. The response has Content-Type: application/json. You can also explore the contract on the local Swagger UI.

curl -i -H 'Accept: application/json' "$ARTICLE_URL"