AppView in a box as a Vite plugin thing
hatk.dev
1---
2title: Configuration
3description: Configure your hatk project with hatk.config.ts.
4---
5
6hatk is configured through `hatk.config.ts` at the project root. The `defineConfig` helper provides type safety and autocompletion.
7
8## Minimal example
9
10Most projects only need a few options. Here is a minimal config that works for local development:
11
12```typescript
13import { defineConfig } from '@hatk/hatk/config'
14
15export default defineConfig({
16 port: 3000,
17 database: 'data/hatk.db',
18 oauth: {
19 clients: [
20 {
21 client_id: 'http://127.0.0.1:3000/oauth-client-metadata.json',
22 client_name: 'My App',
23 redirect_uris: ['http://127.0.0.1:3000/oauth/callback'],
24 },
25 ],
26 },
27})
28```
29
30## Production example
31
32A real-world config that switches between local and production settings:
33
34```typescript
35import { defineConfig } from '@hatk/hatk/config'
36
37const isProd = process.env.NODE_ENV === 'production'
38const prodDomain = process.env.RAILWAY_PUBLIC_DOMAIN
39
40export default defineConfig({
41 relay: isProd ? 'wss://bsky.network' : 'ws://localhost:2583',
42 plc: isProd ? 'https://plc.directory' : 'http://localhost:2582',
43 port: 3000,
44 database: isProd ? '/data/hatk.db' : 'data/hatk.db',
45 backfill: {
46 parallelism: 5,
47 signalCollections: ['xyz.statusphere.status'],
48 },
49 oauth: {
50 issuer: isProd && prodDomain ? `https://${prodDomain}` : undefined,
51 scopes: ['atproto'],
52 clients: [
53 ...(prodDomain
54 ? [{
55 client_id: `https://${prodDomain}/oauth-client-metadata.json`,
56 client_name: 'My App',
57 redirect_uris: [`https://${prodDomain}/oauth/callback`],
58 }]
59 : []),
60 {
61 client_id: 'http://127.0.0.1:3000/oauth-client-metadata.json',
62 client_name: 'My App',
63 redirect_uris: ['http://127.0.0.1:3000/oauth/callback'],
64 },
65 ],
66 },
67})
68```
69
70## Server options
71
72| Option | Type | Default | Env | Description |
73| --- | --- | --- | --- | --- |
74| `relay` | `string` | `'ws://localhost:2583'` | `RELAY` | WebSocket URL for the AT Protocol firehose relay. Use `wss://bsky.network` in production. |
75| `plc` | `string` | `'https://plc.directory'` | `DID_PLC_URL` | PLC directory URL for DID resolution. Use `http://localhost:2582` for local dev. |
76| `port` | `number` | `3000` | `PORT` | HTTP port for the hatk backend server. |
77| `publicDir` | `string \| null` | `'./public'` | -- | Directory for static files. Set to `null` to disable static file serving. |
78| `collections` | `string[]` | `[]` | -- | Collection NSIDs to index. If empty, auto-derived from your lexicon record definitions. |
79| `admins` | `string[]` | `[]` | `ADMINS` | DIDs allowed to access `/admin/*` endpoints. Env var is comma-separated. |
80
81## Database options
82
83| Option | Type | Default | Env | Description |
84| --- | --- | --- | --- | --- |
85| `database` | `string` | `':memory:'` | `DATABASE` | SQLite database file path, resolved relative to the config file. Use an absolute path in production (e.g., `/data/hatk.db`). |
86
87## Backfill options
88
89The `backfill` object controls how the server catches up on historical data from the AT Protocol network.
90
91| Option | Type | Default | Env | Description |
92| --- | --- | --- | --- | --- |
93| `backfill.parallelism` | `number` | `3` | `BACKFILL_PARALLELISM` | Number of concurrent repo fetches. |
94| `backfill.fetchTimeout` | `number` | `300` | `BACKFILL_FETCH_TIMEOUT` | Timeout per repo fetch in seconds. |
95| `backfill.maxRetries` | `number` | `5` | `BACKFILL_MAX_RETRIES` | Max retry attempts for failed repo fetches. |
96| `backfill.fullNetwork` | `boolean` | `false` | `BACKFILL_FULL_NETWORK` | Backfill the entire network (not just repos that interact with your collections). |
97| `backfill.repos` | `string[]` | -- | `BACKFILL_REPOS` | Pin specific DIDs to always backfill. Env var is comma-separated. |
98| `backfill.signalCollections` | `string[]` | -- | -- | Collections that trigger a backfill when a new record appears. Defaults to your top-level `collections`. |
99
100## Full-text search
101
102| Option | Type | Default | Env | Description |
103| --- | --- | --- | --- | --- |
104| `ftsRebuildInterval` | `number` | `5000` | `FTS_REBUILD_INTERVAL` | DuckDB only. Rebuild the FTS index every N writes. Lower values mean fresher search results but more CPU usage. SQLite uses incremental FTS updates and ignores this setting. |
105
106## OAuth options
107
108The `oauth` object configures AT Protocol OAuth for authenticated endpoints. Set to `null` or omit entirely to disable auth.
109
110| Option | Type | Default | Env | Description |
111| --- | --- | --- | --- | --- |
112| `oauth.issuer` | `string` | `'http://127.0.0.1:{port}'` | `OAUTH_ISSUER` | The OAuth issuer URL. Typically your server's public URL. |
113| `oauth.scopes` | `string[]` | `['atproto']` | -- | OAuth scopes to request. Use [granular scopes](https://atproto.com/specs/oauth#scopes) to limit access (e.g., `'repo:xyz.statusphere.status?action=create&action=delete'`). |
114| `oauth.clients` | `OAuthClientConfig[]` | `[]` | -- | Allowed OAuth clients. Each entry needs `client_id`, `client_name`, and `redirect_uris`. |
115| `oauth.cookieName` | `string` | `'__hatk_session'` | -- | Name of the session cookie. |
116
117### OAuth client fields
118
119Each entry in `oauth.clients` has:
120
121| Field | Type | Required | Description |
122| --- | --- | --- | --- |
123| `client_id` | `string` | Yes | Client identifier URL (points to your OAuth client metadata JSON). |
124| `client_name` | `string` | Yes | Human-readable name shown during the authorization flow. |
125| `redirect_uris` | `string[]` | Yes | Allowed redirect URIs after authorization. |
126| `scope` | `string` | No | Scope override for this specific client. |
127
128## Environment variable overrides
129
130Every option that lists an **Env** column can be set via environment variables. Environment variables take precedence over values in `hatk.config.ts`. This is useful for production deployments where you set secrets and infrastructure-specific values through your hosting platform's environment configuration.