Deep dives Chapter 1 of 9

One program

How one executable file contains the Chatto server, its data store, and the web app.

4 min Checked against its records on 2026-12-01 Source file

Chatto is one executable file. When you run chatto run, one process starts a data store, an HTTP server, and the web app. You give it a port and a data directory (ADR-002).

You do not install a database, a message broker, or a web server. Those parts are inside the program. The sections below show each part and how the parts connect.

What is inside the file

The executable has three parts:

  • The Go server. It contains the API, the realtime connection, and the core that applies the rules of Chatto.
  • A NATS server. NATS is a messaging system that sends messages from publishers to subscribers by subject name. Its JetStream layer stores messages on disk.
  • The web app. It is a set of static files: HTML, JavaScript, and styles.

Chatto has no relational database and no SQL. NATS with JetStream is the only data store (ADR-001). ADR-001 is partially superseded: later records changed how Chatto arranges its data inside NATS. The decision not to add a separate database or broker is still in effect.

The data store runs in the same process

NATS is written in Go, and a Go program can start a NATS server as a library. Chatto does this (ADR-002). The NATS server starts first, because all other parts need it.

Then Chatto connects to this server as a normal NATS client. The connection stays in the process and does not use the network. By default, Chatto opens no NATS port at all. You can configure a TCP port if you want to use NATS tools from outside.

The NATS server writes its data to the data directory. This directory contains the messages, the users, the rooms, and the uploaded files. The configuration key is nats.embedded.data_dir.

The code that starts and stops the embedded server is a small shared module, pkg/natsruntime. It starts the server, waits until the server accepts connections, makes the in-process connection option, and shuts the server down (ADR-058). Chatto keeps control of its own configuration: the storage path, the listener, and the authentication.

Uploaded files need a store too. By default, Chatto keeps them in a NATS Object Store, which is JetStream storage for large binary objects. Thus a small server needs nothing more than its data directory (ADR-021).

An operator can configure a storage service that is compatible with S3. New uploads then go to S3. Each asset records where its bytes are, so files from before the change stay readable in NATS.

The web app is part of the file

The web app is a SvelteKit application. The build makes it a static single-page app: the browser renders all pages, and the server renders none. The Go compiler then puts the built files into the executable (ADR-018).

At runtime, the HTTP server sends these files from memory. For a path that it does not know, it sends the fallback page, and the app in the browser shows the correct screen. Files with a content hash in their name get a cache lifetime of one year.

One result is that the server and the web app always have the same version. An update replaces one file and restarts one process.

Optional runtime units

Some functions do not need to be in the main process. Chatto calls them runtime units (ADR-041). A runtime unit can run in two ways:

  • Embedded: chatto run starts the unit when its configuration section has enabled = true.
  • Standalone: a separate command, such as chatto exporter, starts only this unit as its own process.

Two units are in the catalogue of chatto run: the metrics exporter and the bundled message-search provider. A third unit, chatto asset-processing, is a standalone worker for video and animated images. The main process can do the same media work itself.

A standalone unit does not start a NATS server. It connects to an existing NATS server as a client. If an embedded unit stops with an error, chatto run starts it again after a delay. The delay grows to a maximum of 30 seconds. The main app stays available during this time.

An external NATS cluster

The embedded NATS server is a convenience and not a limit. You can set nats.embedded.enabled to false and give Chatto the address of an external NATS server or cluster (ADR-002).

The server code does not change in this mode. It is a NATS client in both cases. Only the location of the NATS server is different.

With an external cluster, more than one Chatto process can use the same data. A different chapter explains how these processes work together.

Read the code

The records behind this chapter

Esc