@appweaver/skill 0.0.0-stage → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,312 @@
1
+ # Time series
2
+
3
+ The `series` section of a resource model declares numeric and boolean fields measured over time, i.e. the temperature
4
+ of a sensor, the price of a product, or the open tickets of a team. Their points live apart from the records of the
5
+ model, in a `TimeSeries` store, each point belonging to one resource and keyed by its time, and they are written and
6
+ queried through their own routes and the `TimeSeriesService` of `@appweaver/core`.
7
+
8
+ ## Declaring series fields
9
+
10
+ ```ts
11
+ import { createModel } from '@appweaver/data';
12
+
13
+ export default createModel({
14
+ name: 'Sensor',
15
+ scalars: {
16
+ serial: { type: 'string', unique: true }
17
+ },
18
+ series: {
19
+ temperature: {
20
+ type: 'float',
21
+ minimum: -50,
22
+ maximum: 150,
23
+ description: 'Degrees Celsius'
24
+ },
25
+ errors: { type: 'int', minimum: 0 },
26
+ online: { type: 'boolean' }
27
+ },
28
+ seriesOptions: {
29
+ ingest: 'queue', // or 'direct' / 'auto', default: the `timeseries.ingest` config
30
+ retention: '365d', // deleted after a year
31
+ compressAfter: '30d', // TimescaleDB: compressed after a month
32
+ chunkInterval: '7d' // TimescaleDB: the time range of a chunk
33
+ }
34
+ });
35
+ ```
36
+
37
+ | Series field option | Description |
38
+ | ------------------- | --------------------------------------------------------- |
39
+ | `type` | `float`, `int` or `boolean` |
40
+ | `minimum` | The smallest value accepted, of a numeric field |
41
+ | `maximum` | The largest value accepted, of a numeric field |
42
+ | `description` | The description of the field in the OpenAPI specification |
43
+ | `example` | The example of the field in the OpenAPI specification |
44
+
45
+ | Series option | Description |
46
+ | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
47
+ | `ingest` | `direct`, `queue` or `auto`, how the points are written (see [Ingestion](#ingestion)) |
48
+ | `tableName` | The table of the points, default `<Model>Series` or `<tableName>_series` |
49
+ | `retention` | How long the points are kept, a duration (`90d`), overriding the retention of the store: `timeseries.database.retention` or `timeseries.timescale.retention` |
50
+ | `compressAfter` | The age TimescaleDB compresses the points from, default `timeseries.timescale.compressAfter` |
51
+ | `chunkInterval` | The time range of a TimescaleDB chunk, default `timeseries.timescale.chunkInterval` |
52
+
53
+ A field cannot be named `time` or `resourceId`, the time and the resource of a point, nor `resource` with the
54
+ `database` store (the relation of its Prisma model). The durations are a number and a unit of `ms`, `s`, `m`, `h`, `d`
55
+ or `w` (`15m`, `1h`, `7d`), of whole seconds; `createModel` rejects an invalid option at once, whatever the store.
56
+
57
+ A point carries the values of any of the fields, and a point written at the time of a stored one merges into it: the
58
+ fields it carries replace the stored ones, the others stay. So a retried write never duplicates a point. The values of
59
+ the fields a point does not carry are `null` when it is read.
60
+
61
+ `weaver generate` emits the `<Model>Series` type of the values (`SensorSeries`), registered as the `series` of the
62
+ model in the `ResourceRegistry`, so the `TimeSeriesService` types the values of `write` and `query` by the model name.
63
+
64
+ ## Stores
65
+
66
+ The store is selected by `timeseries.provider`:
67
+
68
+ | Provider | Package | Store |
69
+ | ----------- | ----------------- | -------------------------------------------------------------------------------------- |
70
+ | `database` | `@appweaver/data` | The `<Model>Series` table of the database, on SQLite, PostgreSQL, MySQL and SQL Server |
71
+ | `timescale` | `@appweaver/data` | The same table, a TimescaleDB hypertable on PostgreSQL, with compression and retention |
72
+ | `memory` | `@appweaver/core` | The process memory, for the tests |
73
+ | `none` | — | No store: the `TimeSeriesService` and the series routes are left out |
74
+
75
+ With `auto` (the default), the driver of an enabled module package wins, otherwise `database` with `@appweaver/data`.
76
+ `timescale` and `memory` are selected by their names only. Both SQL stores take part in the transactions, delete the
77
+ points of a range, and delete the points of a resource with it by the foreign key of the table. Another store is
78
+ written as a module package, its driver tested with the [contract suite](#testing).
79
+
80
+ ### database
81
+
82
+ `weaver generate` adds a table for every model with series fields to the Prisma schema: the `resourceId` and the
83
+ `time` as its primary key, a nullable column per field, and a foreign key to the resource deleting its points with it.
84
+
85
+ ```prisma
86
+ model SensorSeries {
87
+ resourceId Int
88
+ time DateTime
89
+ temperature Float?
90
+ errors Int?
91
+ online Boolean?
92
+
93
+ /// Related columns
94
+ resource Sensor @relation("SensorSeries", fields: [resourceId], references: [id], onDelete: Cascade)
95
+
96
+ @@id([resourceId, time])
97
+ }
98
+ ```
99
+
100
+ The model gets the `seriesPoints` relation of its points, so neither `<Model>Series` nor a `seriesPoints` field may be
101
+ declared by the application. Create the migration of the table like any other: `weaver migration new add_sensor_series`.
102
+ The buckets are computed in SQL on every database (`date_bin` on PostgreSQL, `TIMESTAMPDIFF` on MySQL, `strftime` on
103
+ SQLite, `DATEADD` on SQL Server), suited to moderate volumes; a high volume belongs in TimescaleDB. The table is left
104
+ out of the Prisma schema when another store holds the points (`memory`, `none`, a module path, or `auto` with the
105
+ module package of another store enabled). On PostgreSQL the SQL of the points names the schema of the `schema`
106
+ parameter of `database.url`, like the queries of Prisma, `public` without one.
107
+
108
+ The points older than the retention of their model (`seriesOptions.retention`, otherwise
109
+ `timeseries.database.retention`) are deleted by the `timeseriesRetention` maintenance job, once per cluster every hour
110
+ by default, a `DELETE` per model in batches of `maintenance.batchSize` (see the [maintenance jobs](./modules.md#maintenance-jobs)):
111
+ `maintenance.jobs.timeseriesRetention.schedule` changes it, and `weaver run maintenance timeseriesRetention` runs it
112
+ once.
113
+
114
+ ### timescale
115
+
116
+ The `database` store on PostgreSQL with the [TimescaleDB](https://www.timescale.com) extension (the
117
+ `timescale/timescaledb` image). When the application starts, it creates the extension when missing, turns every series
118
+ table into a hypertable partitioned by time (`create_hypertable`, without its default indexes, so the schema stays the
119
+ one of the Prisma migrations and `weaver migration new` sees no drift), and keeps the compression and retention policies
120
+ of each model in line with its `seriesOptions`, adding, replacing or removing them, all under an advisory lock so
121
+ starting instances set them up once. Only what differs is changed, so a start with the hypertables in place runs no
122
+ DDL. `weaver migrate` sets them up too, after the migrations, as the user of `database.migrationUrl`. The buckets use
123
+ `time_bucket`.
124
+
125
+ ```json
126
+ {
127
+ "config": {
128
+ "timeseries": {
129
+ "provider": "timescale",
130
+ "timescale": {
131
+ "chunkInterval": "7d",
132
+ "compressAfter": "30d",
133
+ "retention": "365d"
134
+ }
135
+ }
136
+ }
137
+ }
138
+ ```
139
+
140
+ Setting the hypertables up needs the right to create the extension (or the extension created beforehand with
141
+ `CREATE EXTENSION timescaledb`) and to own the series tables. With an application user that can only read and write
142
+ the data (see [database](./database.md#separate-migration-and-application-users)), `weaver migrate` sets them up, and a
143
+ start finding them out of date fails with `CONFIGURATION_INVALID`, asking to run `weaver migrate`. The compression and the retention policies are features of the Timescale License,
144
+ missing from the Apache-only builds of some managed PostgreSQL services: leave `compressAfter` and `retention` empty
145
+ there.
146
+
147
+ ## Ingestion
148
+
149
+ A write is validated first (the fields, their types and ranges, the times, `timeseries.maxPointsPerWrite`), so an invalid
150
+ one fails at once, then applied in one of two ways:
151
+
152
+ | Ingest | Behavior |
153
+ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
154
+ | `direct` | Written in the request (the default of `timeseries.ingest`), responding `200 { count, queued: false }` |
155
+ | `queue` | Sent to the `timeseries.queueName` queue in jobs of up to `timeseries.queueBatchSize` points, responding `202 { count, queued: true }`, and written by a worker |
156
+ | `auto` | Queued on a durable queue (BullMQ), written directly on the in-memory one |
157
+
158
+ The worker runs in every instance with `timeseries.queueWorker` (`true` by default), `timeseries.queueConcurrency` jobs
159
+ at once, retried with the `queue.retryAttempts` and `queue.retryBackoff` of the queue ([queue.md](./queue.md)). Since
160
+ a point merges into the one stored at its time, a retried job writes no duplicate. The points of a resource deleted
161
+ since they were queued are dropped, the others of the job written. `queue` with the in-memory queue loses the queued
162
+ points on a restart.
163
+
164
+ A write made in a transaction ([`runTransaction`](./database.md#transactions), a service hook) takes part in it on the
165
+ `database` and `timescale` stores, while a queued write, or a write to a store outside the database (a driver whose
166
+ `transactional` is `false`), waits for the commit and is dropped on a rollback.
167
+
168
+ A store unreachable when the application starts is set up by the next write or query (the hypertables of
169
+ TimescaleDB), and a failed retention delete is logged and run again at the next interval, while an invalid setup (a
170
+ retention that is not a duration) fails the start with `CONFIGURATION_INVALID`.
171
+
172
+ ## Routes
173
+
174
+ `createRoutes` registers the series routes of a model with series fields when its `actions` list them (`series` for
175
+ all three, or `seriesWrite`, `seriesQuery` and `seriesDelete` one by one; never for the routes of a view), configured by
176
+ `seriesWrite`, `seriesQuery` and `seriesDelete` (`exclude`, `roles`, `public`, `rateLimit`, ...):
177
+
178
+ | Route | Config | Description |
179
+ | ------------------------- | -------------- | ------------------------------------------------------------------------------------- |
180
+ | `POST /:id/series` | `seriesWrite` | Writes the points of a resource: `{ points: [{ time?, ...values }] }` |
181
+ | `POST /series` | `seriesWrite` | Writes the points of many resources: `{ points: [{ resourceId, time?, ...values }] }` |
182
+ | `GET /:id/series` | `seriesQuery` | Queries the points of a resource |
183
+ | `POST /series/query` | `seriesQuery` | Queries the points of the resources of the `ids`, the `filter`, or both |
184
+ | `POST /:id/delete-series` | `seriesDelete` | Deletes the points of a resource within `{ from?, to? }`, all without them |
185
+
186
+ ```ts
187
+ export default createRoutes({
188
+ modelName: 'Sensor',
189
+ actions: ['crud', 'series'],
190
+ seriesWrite: { auth: [AuthType.ApiKey], maxPoints: 1000, allowDirect: false },
191
+ seriesQuery: { roles: ['Analyst'] },
192
+ seriesDelete: { exclude: true }
193
+ });
194
+ ```
195
+
196
+ `seriesWrite` takes `maxPoints` (default `timeseries.maxPointsPerWrite`) and `allowDirect`: a write with
197
+ `?ingest=direct` skips the queue of a model queueing its points, unless `allowDirect: false`. A point's `time` is an ISO
198
+ 8601 string or the milliseconds since the epoch, now by default.
199
+
200
+ The query parameters (the body of `POST /series/query`):
201
+
202
+ | Parameter | Description |
203
+ | ----------- | ----------------------------------------------------------------------------------------------- |
204
+ | `fields` | The fields to return, comma separated in the query string (an array in a body), all by default |
205
+ | `from` | The start of the range, inclusive |
206
+ | `to` | The end of the range, exclusive |
207
+ | `bucket` | A duration (`15m`, `1h`, `1d`) aggregating the points of each bucket, aligned to the Unix epoch |
208
+ | `aggregate` | `avg` (the default with a bucket), `min`, `max`, `sum`, `count`, `first`, `last` |
209
+ | `order` | `asc` (default) or `desc`, by time |
210
+ | `limit` | The maximum number of points, at most `timeseries.maxPointsPerQuery` |
211
+
212
+ ```bash
213
+ GET /api/sensors/7/series?fields=temperature&from=2026-01-01T00:00:00Z&bucket=1h&aggregate=max
214
+ # { "items": [{ "time": "2026-01-01T00:00:00.000Z", "temperature": 21.4 }, ...] }
215
+
216
+ POST /api/sensors/series/query
217
+ { "filter": { "serial": { "_starts": "EU-" } }, "fields": ["errors"], "bucket": "1d", "aggregate": "sum" }
218
+ # { "items": [{ "resourceId": 7, "time": "2026-01-01T00:00:00.000Z", "errors": 3 }, ...] }
219
+ ```
220
+
221
+ The aggregates skip the null values, so `first` and `last` are the first and last values of each field in the bucket,
222
+ and `count` the number of its values. `avg`, `min`, `max` and `sum` count a boolean as `1` or `0`, so the `avg` of a
223
+ boolean is the share of `true` (a number in the response). An aggregate without a bucket returns one point per
224
+ resource, at the time of its first point. A bucket without any point is left out, and so is a point without a value of
225
+ the selected fields.
226
+
227
+ ### Access
228
+
229
+ Every route reads the resources through their resource service first, so the policy of the model applies (a resource
230
+ it cannot read is `RESOURCE_NOT_FOUND`), then checks the `series` of the policy, each check allowing the action when
231
+ left out:
232
+
233
+ ```ts
234
+ export default createPolicy({
235
+ modelName: 'Sensor',
236
+ series: {
237
+ canRead: (user, sensor) => sensor.ownerId === user?.id,
238
+ canWrite: (user) => hasRole(user, 'Device'),
239
+ canDelete: () => false
240
+ }
241
+ });
242
+ ```
243
+
244
+ A frequent writer is checked on every request unless `timeseries.accessCacheTtl` keeps an allowed check for that many
245
+ milliseconds. A query or a write of many covers up to `timeseries.maxResourcesPerQuery` resources.
246
+
247
+ ## TimeSeriesService
248
+
249
+ ```ts
250
+ import { inject, TimeSeriesService } from '@appweaver/core';
251
+
252
+ const timeSeries = inject(TimeSeriesService);
253
+
254
+ await timeSeries.write('Sensor', [
255
+ { resourceId: 7, values: { temperature: 21.5, online: true } }, // now
256
+ { resourceId: 7, time: '2026-01-01T12:00:00Z', values: { errors: 2 } }
257
+ ]);
258
+ await timeSeries.write('Sensor', points, { ingest: 'direct' });
259
+
260
+ const hourly = await timeSeries.query('Sensor', {
261
+ resourceIds: [7],
262
+ fields: ['temperature'],
263
+ from: new Date(Date.now() - 86_400_000),
264
+ bucket: '1h',
265
+ aggregate: 'avg'
266
+ });
267
+ // [{ resourceId: 7, time: Date, values: { temperature: 21.2 } }, ...]
268
+
269
+ await timeSeries.delete('Sensor', {
270
+ resourceIds: [7],
271
+ to: '2026-01-01T00:00:00Z'
272
+ });
273
+ ```
274
+
275
+ The service checks no policy, like the resource services called by the application. Its `normalizePoints` and
276
+ `normalizeQuery` validate the input the way the routes do. The `TimeSeriesService` is defined only when a store is
277
+ provided, so `inject(TimeSeriesService, false)` is `undefined` with `timeseries.provider: none`.
278
+
279
+ ## Limitations
280
+
281
+ - The buckets have a fixed width in UTC, so no time zones or calendar months. A point has millisecond precision.
282
+ - An `int` field is 32 bits, and a value is read as a JavaScript number, so a total past 2^53 loses precision.
283
+ - A `null` value never clears a stored one, delete the point instead.
284
+ - While the queue is down a queued write responds `503`, and a write from an event handler is lost unless it handles
285
+ the error.
286
+ - A soft deleted resource keeps its points until their retention, unreachable through the routes.
287
+ - TimescaleDB: the retention drops whole chunks, and the type of a field cannot change once a chunk is compressed.
288
+
289
+ ## Testing
290
+
291
+ Select the `memory` store in the `test` environment, unless the end-to-end tests run on the store of production:
292
+
293
+ ```json
294
+ { "environments": { "test": { "timeseries": { "provider": "memory" } } } }
295
+ ```
296
+
297
+ A driver of another store runs the contract suite of `@appweaver/testing`:
298
+
299
+ ```ts
300
+ import {
301
+ contractSeriesModel,
302
+ testTimeSeriesContract
303
+ } from '@appweaver/testing';
304
+
305
+ // The store creates the table of contractSeriesModel when it needs one
306
+ testTimeSeriesContract('QuestTimeSeries', () => new QuestTimeSeries());
307
+ ```
308
+
309
+ ## Scaffolding
310
+
311
+ `npm create @appweaver my-app -- --add timeseries` (or `weaver module add timeseries`) selects the `database` provider,
312
+ `timescale` on PostgreSQL, whose docker-compose service then runs the TimescaleDB image.
@@ -0,0 +1,223 @@
1
+ # Common tasks
2
+
3
+ The commands of the daily work on a project: build, start, generate, migrate, seed, OpenAPI, config, tasks, upgrade,
4
+ modules, tests, format and lint. Every option is in [cli.md](./cli.md).
5
+
6
+ ## Build application
7
+
8
+ ```sh
9
+ weaver build
10
+ weaver build --project tsconfig.build.json # path to tsconfig build file
11
+ ```
12
+
13
+ ## Start application
14
+
15
+ ```sh
16
+ weaver start # production
17
+ weaver start --watch # development (restarts on source, template and translation changes)
18
+ weaver start --project tsconfig.json # path to tsconfig file
19
+ ```
20
+
21
+ ## Generate types and schema
22
+
23
+ ```sh
24
+ weaver generate # everything: types, Prisma schema and config schema
25
+ weaver generate --types # TypeScript types only
26
+ weaver generate --prisma-schema # Prisma schema only
27
+ weaver generate --config-schema # appweaver.schema.json only, no @appweaver/data needed
28
+ weaver generate --no-prune # keep the framework models the project does not use
29
+ ```
30
+
31
+ The framework models are generated only when used: `Role`, `Permission`, `ApiKey`, `OneTimeToken` and
32
+ `ConnectedAccount` with an auth model, `File` when a model declares `files`, `Seeder` when the seeders directory exists.
33
+
34
+ ## Run database migrations
35
+
36
+ ```sh
37
+ weaver migrate # run pending migrations and SQL migrations, then set up the hypertables, geometry triggers and full-text indexes
38
+ weaver migrate --dry-run # print the pending migrations and their SQL, without applying them
39
+ weaver migration check # check if the models need a new migration, print its SQL (exit code 1)
40
+ weaver migration new <name> # create a new migration
41
+ weaver migration new <name> --sql # create a SQL migration of database/sql (triggers, views, expression indexes)
42
+ weaver migration reset # reset database (prompts confirmation)
43
+ weaver migration reset --yes --force # force reset, skip confirmation
44
+ ```
45
+
46
+ The SQL Prisma does not generate goes into `database/sql/<version>_<name>[.<database>].sql` and the repeatable
47
+ `functions/`, `views/` and `triggers/`, applied once by `weaver migrate` after the Prisma migrations (see
48
+ [database.md](./database.md#sql-migrations)).
49
+
50
+ ## Seed the database
51
+
52
+ ```sh
53
+ weaver seed # run seeders
54
+ weaver seed --build-project # build project first, then run seeders
55
+ weaver seed --build-project --project tsconfig.build.json # tsconfig file used for the build
56
+ weaver seed --continue-on-error # continue if a seeder throws error
57
+ weaver seed --fix-warnings # fix all warnings like invalid checksum or missing seeder
58
+ weaver seed --dry-run # print the pending seeders, without running them
59
+ ```
60
+
61
+ ## Generate OpenAPI specification
62
+
63
+ ```sh
64
+ weaver openapi # generate schema to ./openapi.json
65
+ weaver openapi --output-path ./generated/openapi.json # generate schema to a custom path
66
+ weaver openapi --format yaml # generate schema in yaml format (./openapi.yaml)
67
+ ```
68
+
69
+ ## Inspect the configuration
70
+
71
+ ```sh
72
+ weaver config schema # JSON Schema of appweaver.json from the enabled modules (./appweaver.schema.json)
73
+ weaver config print # every key with its source (override, env, json, default), the secrets hidden
74
+ NODE_ENV=prod weaver config check # validate every section, exit 1 listing the invalid keys (run in CI)
75
+ weaver doctor # check the packages, .env, config, generated files, migrations and skill
76
+ ```
77
+
78
+ The `$schema` of `appweaver.json` points to `./appweaver.schema.json`, which `weaver generate` writes from the config
79
+ sections the enabled modules list (rerun it after adding a module), and `weaver config schema` also for a section of an
80
+ application file outside a module. See
81
+ [configuration.md](./configuration.md#inspecting-the-config).
82
+
83
+ ## Run a one-shot task
84
+
85
+ ```sh
86
+ weaver run # list the tasks of src/tasks/ and the modules
87
+ weaver run orders:count Pending # run a task by its name with the arguments, then exit
88
+ weaver run orders:count --help # the arguments and options of a task
89
+ ```
90
+
91
+ ## Upgrade Appweaver packages
92
+
93
+ ```sh
94
+ weaver upgrade # upgrade all @appweaver/* packages to latest
95
+ weaver upgrade @appweaver/core @appweaver/cli # upgrade specific packages
96
+ weaver upgrade --target-version 1.2.3 # upgrade to a specific version
97
+ weaver upgrade --no-skill # skip upgrading AI agent skill files (.claude, .agents, …)
98
+ weaver upgrade --force # force upgrade despite peerDependency mismatches
99
+ weaver upgrade --no-companions # skip the companion packages (prisma, typebox, typescript, …)
100
+ weaver upgrade --tooling # also upgrade @types/bun (eslint, jest, prettier come with @appweaver/tooling)
101
+ weaver upgrade --dry-run # print the upgrades without installing them
102
+ weaver skill sync # copy the installed @appweaver/skill into the agent directories
103
+ ```
104
+
105
+ After the install, `weaver upgrade` runs `weaver skill sync`, which copies the skill of the project's `@appweaver/skill`
106
+ dev dependency into `skills/appweaver/` of every agent directory (`.claude`, `.agents`, `.github`, …); run it alone after
107
+ installing the package by hand. Besides the `@appweaver/*` packages, `weaver upgrade` bumps the companion packages the project already has (Prisma
108
+ and its adapters, TypeBox, TypeScript) to the exact versions the target release is built with. It never adds missing
109
+ packages or downgrades newer ones. The libraries of the drivers (BullMQ, Cron, Handlebars, IoRedis, Nodemailer, Sharp)
110
+ come with their `@appweaver/*` driver packages. Run `weaver generate` afterwards when Prisma is upgraded.
111
+
112
+ ## Managing modules
113
+
114
+ The optional modules of `@appweaver/create` are added to and removed from an existing project with the same templates,
115
+ of the version the project's `@appweaver/cli` is at:
116
+
117
+ ```sh
118
+ weaver module list # the modules, whether enabled, their packages and requirements
119
+ weaver module add redis queue docker # add modules with the modules they require, and install them
120
+ weaver module add sms # the Twilio SMS sender, logging the messages in dev and test
121
+ weaver module add web --database mysql # add the server and the database (data) it requires, on MySQL
122
+ weaver module add templates --dry-run # print the files and configuration it would change
123
+ weaver module add docker --force # overwrite the existing files instead of skipping them
124
+ weaver module remove docker # remove modules (alias: rm), deleting their files
125
+ weaver module remove mailer --no-install
126
+ weaver module add @acme/appweaver-gcs # install a module package (no install scripts), print its providers
127
+ weaver module new audit-log # create the local module src/modules/audit-log/
128
+ ```
129
+
130
+ A module is enabled when the project depends on its packages (`locales` and `docker` when `locales/` and `Dockerfile`
131
+ exist, `timeseries` when `appweaver.json` sets `timeseries.provider`). `add` writes the module's packages into `package.json`, its values into `appweaver.json`, its files (skipping
132
+ the existing ones that differ), and what it adds to the enabled modules: the database, migrations and seed services and
133
+ the Redis service of `docker-compose.yml`, the server port and health check, the Dockerfile `COPY` of the public,
134
+ template, translation and Prisma files, the email templates and texts of the mailer. `data` is added on the database of
135
+ `--database` (`sqlite` by default), with its password in `.env` and `.env.example`. Adding `locales` restores
136
+ the `t` calls of the scaffolded templates that still hold the English texts.
137
+
138
+ `remove` reverts all of it and deletes the module's files: the whole `templates/` or `locales/` directory, the Docker
139
+ files, the mailer's email templates and its unchanged `emails` texts of `locales/en.json`. Removing `locales` first
140
+ writes the English texts of `locales/en.json` into the
141
+ templates, so they keep rendering (the other languages are lost). A module another enabled module requires cannot be
142
+ removed alone (`queue` requires `redis`, `web` requires `data`). Removing `data` deletes the whole `database/`
143
+ directory and the generated types. An `appweaver.json` value changed in the project is kept, and the only files of
144
+ `src/` and `database/seeders/` touched are the scaffolded ones of `web` (the `User` resource and its admin seeder),
145
+ deleted only while unchanged, so remove the code using a removed module yourself.
146
+
147
+ A name that is not a scaffold module, with a scope, a `-` or a `/`, is a module package: `add` installs it with
148
+ `npm install --ignore-scripts` (`bun
149
+ add` on Bun) and prints the providers and requirements of its manifest. `new <name>` creates a local module (kebab-case
150
+ name) with its `module.ts`, `config.ts` (the camelCase section of the name) and `main.ts`, enabled without config. A
151
+ reusable module goes into a package of its own, created with `npm create @appweaver module <package> -- --contract
152
+ storage|mailer|sms|none`, i.e. a Postmark mailer or a Vonage SMS sender (see
153
+ [modules.md](./modules.md#creating-a-module-package)).
154
+
155
+ ## Run tests
156
+
157
+ ```sh
158
+ npm run test # weaver test --coverage: the unit tests with coverage
159
+ npm run e2e # weaver test --e2e: the e2e tests
160
+ weaver test test/unit/a.test.ts --watch # one file, again on every change
161
+ ```
162
+
163
+ `weaver test` runs the Jest of the `@appweaver/tooling` dev dependency on Node (the `"preset": "@appweaver/tooling"` of
164
+ `jest.config.json`: SWC, the JUnit report of `reports/`), and `bun test` on Bun. The lint, the format and the test tools
165
+ come with `@appweaver/tooling`: never add ESLint, Prettier, Jest or SWC to the project yourself.
166
+
167
+ Test files must use the **`.test.ts`** extension. Place unit tests in `test/unit/` and end-to-end tests in `test/e2e/`,
168
+ naming each file after its module. Add or update tests whenever a feature is added or existing behaviour changes.
169
+
170
+ On Node, the application of the e2e tests loads the compiled `dist`, not the sources: `npm run e2e` builds first (its
171
+ `pree2e` script, `weaver build`), while `weaver test --e2e` or `jest` run directly test the last build. A project
172
+ scaffolded before v3 adds `"pree2e": "weaver build"` to its scripts. Bun runs the sources.
173
+
174
+ The e2e setup and teardown are wired automatically, but **each e2e test file must register the per-file database reset
175
+ itself**, after the hook that stops the application:
176
+
177
+ ```ts
178
+ import { resetTestData } from './support/reset';
179
+
180
+ describe('My e2e test', () => {
181
+ let app: Application;
182
+
183
+ beforeAll(async () => {
184
+ // The test environment sets server.listen to false, so app.server.inject() serves the requests
185
+ app = await createApp();
186
+ });
187
+
188
+ afterAll(async () => {
189
+ await app.stop();
190
+ });
191
+
192
+ afterAll(resetTestData, 10_000);
193
+ });
194
+ ```
195
+
196
+ The reset drops the whole test database, so the e2e files run one at a time: keep `"maxWorkers": 1` in
197
+ `test/e2e/jest.e2e-config.json`. Run in parallel, the reset of one file drops the tables, the migrations table included,
198
+ under a file still running or resetting beside it (`P1014 The underlying table for model _prisma_migrations does not
199
+ exist` on a database server).
200
+
201
+ **AI agents and dangerous database actions.** Prisma refuses a database reset by an AI agent when
202
+ `DATABASE_AI_DANGEROUS_ACTIONS_ENABLED` is `false`. **Never change it yourself or get past the refusal another way**,
203
+ stop and ask the user to run the command.
204
+
205
+ ## Format code
206
+
207
+ ```sh
208
+ npm run format # weaver format: prettier --write "./**/*.ts"
209
+ weaver format --check # check without writing
210
+ ```
211
+
212
+ The Prettier config is `"prettier": "@appweaver/tooling/prettier"` of `package.json`.
213
+
214
+ ## Lint code
215
+
216
+ ```sh
217
+ npm run lint # weaver lint: eslint .
218
+ weaver lint --fix # fix what can be fixed
219
+ ```
220
+
221
+ `eslint.config.mjs` exports `eslintConfig({ rootDir: import.meta.dirname })` of `@appweaver/tooling/eslint`, the
222
+ recommended rules of ESLint 10 and the type checked typescript-eslint; extend the array it returns with the rules of the
223
+ project.