---
title: "Build a chat app"
description: "Every ArkAPI feature in one small app, step by step."
url: "https://arkapi.emincanozcan.com/docs/tutorial"
---

# Build a chat app

Every ArkAPI feature in one small app, step by step.

In this tutorial you build a group chat for HarmonyOS. People pick a name, send messages and photos, and see who is typing. A script outside the app can post announcements, and old messages clean themselves up. At the end it runs on the hosted service.

The backend is one file of about 100 lines. The screen is one ArkTS page. Along the way you use everything ArkAPI has:

| You will use | For |
|---|---|
| `caller()`, `online()` | who is calling, who is connected |
| `ApiError` | errors the screen can react to |
| `LiveValue`, `AsyncValue` | data that updates by itself, buttons with loading and error state |
| `event()` | "Ada is typing…" |
| `files`, `uploadFile` | photos |
| `routes` | announcements from a script |
| `every()` | hourly cleanup |
| `watch`, `deploy`, `open`, `logs`, `env` | the CLI |

That table is the whole API. There is nothing else to learn.

## How ArkAPI works

You write the backend as TypeScript functions in a file that ends in `.api.ts`, next to your screen. ArkAPI reads the function signatures and generates a typed ArkTS client with the same name and `.api.ets`. Your screen imports from it as if the functions were local:

```ets
import { setName } from './chat.api'
```

A call runs on the server, never on the device. You do not write URLs, request bodies or JSON parsing, and if the backend and the screen disagree on a type, the app does not compile.

## Set up the project

You need [Bun](https://bun.sh) and DevEco Studio. In DevEco Studio, create a new project with the **Empty Ability** template. Then, in the project root:

```sh
bun add -d git+ssh://git@github.com/emincanozcan/arkapi.git
bunx arkapi init
```

No project yet? In an empty folder, `bunx arkapi init --create` makes a blank phone project first.

`init` adds the client library, `arkapi.config.ts` and an `AGENTS.md` guide for coding agents. It also adds an example, `entry/src/main/ets/pages/hello.api.ts`. Delete it and its generated `hello.api.ets`; you will write your own.

## Run the backend on your computer

```sh
bunx arkapi watch
```

`watch` runs the backend on port 3000 and regenerates the client whenever you save an `.api.ts` file. Keep it running for the whole tutorial. The data goes to `app.db`, a SQLite file in the project root.

Run the app on the emulator from DevEco Studio. The emulator reaches your computer at `10.0.2.2`, which is where the generated client points while `watch` runs. To use a phone on your network instead, set `deviceHost` in `arkapi.config.ts` to your computer's address.

Next: [pick a name](/docs/tutorial-names.md).
