@appweaver/create-weaver-app 1.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.
Files changed (64) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +7 -0
  3. package/create-weaver-app.d.ts +2 -0
  4. package/create-weaver-app.js +266 -0
  5. package/package.json +37 -0
  6. package/skill/GUIDELINES.md +298 -0
  7. package/skill/SKILL.md +593 -0
  8. package/skill/references/cache.md +207 -0
  9. package/skill/references/cli.md +213 -0
  10. package/skill/references/client.md +507 -0
  11. package/skill/references/configuration.md +402 -0
  12. package/skill/references/database.md +134 -0
  13. package/skill/references/dependency-injection.md +214 -0
  14. package/skill/references/events.md +152 -0
  15. package/skill/references/mailer.md +235 -0
  16. package/skill/references/queue.md +196 -0
  17. package/skill/references/resources.md +961 -0
  18. package/skill/references/scheduler.md +184 -0
  19. package/skill/references/security.md +694 -0
  20. package/skill/references/storage.md +251 -0
  21. package/templates/default/.dockerignore +5 -0
  22. package/templates/default/.env.tpl +1 -0
  23. package/templates/default/.prettierignore +3 -0
  24. package/templates/default/.prettierrc +7 -0
  25. package/templates/default/Dockerfile +56 -0
  26. package/templates/default/Dockerfile.bun +56 -0
  27. package/templates/default/README.md.tpl +7 -0
  28. package/templates/default/appweaver.dev.json.tpl +9 -0
  29. package/templates/default/appweaver.json.bun.tpl +17 -0
  30. package/templates/default/appweaver.json.tpl +16 -0
  31. package/templates/default/appweaver.test.json.tpl +30 -0
  32. package/templates/default/bunfig.toml.bun +8 -0
  33. package/templates/default/database/client.ts.tpl +7 -0
  34. package/templates/default/database/schema.prisma +13 -0
  35. package/templates/default/database/seeders/001-create-admin-user.ts.tpl +39 -0
  36. package/templates/default/eslint.config.mjs +55 -0
  37. package/templates/default/eslint.config.mjs.bun +53 -0
  38. package/templates/default/jest.config.json.node +23 -0
  39. package/templates/default/package.json.bun.tpl +39 -0
  40. package/templates/default/package.json.tpl +44 -0
  41. package/templates/default/prisma.config.ts.tpl +14 -0
  42. package/templates/default/public/favicon.ico +0 -0
  43. package/templates/default/public/robots.txt +2 -0
  44. package/templates/default/src/features/index.ts.tpl +0 -0
  45. package/templates/default/src/main.ts.tpl +7 -0
  46. package/templates/default/src/resources/user/model.ts.tpl +28 -0
  47. package/templates/default/src/resources/user/policy.ts.tpl +3 -0
  48. package/templates/default/src/resources/user/routes.ts.tpl +3 -0
  49. package/templates/default/src/resources/user/service.ts.tpl +16 -0
  50. package/templates/default/src/types/generated.ts.tpl +1 -0
  51. package/templates/default/src/types/index.ts.tpl +1 -0
  52. package/templates/default/start.sh +26 -0
  53. package/templates/default/start.sh.bun +26 -0
  54. package/templates/default/swc.config.json.node +13 -0
  55. package/templates/default/test/e2e/jest.e2e-config.json.node +22 -0
  56. package/templates/default/test/e2e/main.test.ts.tpl +24 -0
  57. package/templates/default/test/e2e/support/each.ts.tpl +13 -0
  58. package/templates/default/test/e2e/support/preload.ts.bun +13 -0
  59. package/templates/default/test/e2e/support/setup.ts.tpl +13 -0
  60. package/templates/default/test/e2e/support/teardown.ts.tpl +13 -0
  61. package/templates/default/test/unit/sample.test.ts.tpl +5 -0
  62. package/templates/default/tsconfig.build.json +10 -0
  63. package/templates/default/tsconfig.json +27 -0
  64. package/templates/default/tsconfig.json.bun +28 -0
@@ -0,0 +1,402 @@
1
+ # Configuration
2
+
3
+ Appweaver uses a centralized configuration system based on TypeBox schema validation. Configuration values are loaded
4
+ from multiple sources and merged in priority order.
5
+
6
+ ## Configuration loading order
7
+
8
+ Configuration is loaded and merged in the following order (later sources override earlier ones):
9
+
10
+ 1. **Default values** defined in the TypeBox schema
11
+ 2. **Global JSON config** `appweaver.json` (properties under the `config` key)
12
+ 3. **Environment-specific JSON config** `appweaver.{NODE_ENV}.json`
13
+ 4. **Default .env file** `.env`
14
+ 5. **Environment-specific .env file** `.env.{NODE_ENV}` (overrides all above)
15
+
16
+ ## JSON configuration format
17
+
18
+ Configuration in JSON files is nested under the `config` key using camelCase property names. This is the preferred way
19
+ for application configuration (except for passwords and secrets, then use the.env file instead). These are automatically
20
+ mapped to their `SCREAMING_SNAKE_CASE` equivalents:
21
+
22
+ ```json
23
+ {
24
+ "config": {
25
+ "app": {
26
+ "name": "MyApp",
27
+ "env": "prod"
28
+ },
29
+ "server": {
30
+ "port": 3000,
31
+ "apiPrefix": "/api"
32
+ },
33
+ "database": {
34
+ "url": "postgresql://user:pass@localhost:5432/mydb"
35
+ }
36
+ }
37
+ }
38
+ ```
39
+
40
+ ## Environment variable parsing
41
+
42
+ - **Boolean**: `'true'`, `'on'`, `'yes'`, `'1'` (case-insensitive) are parsed as `true`; all others as `false`
43
+ - **Array**: Comma-separated values are automatically split into arrays
44
+ - **Numbers**: Parsed as integers or floats based on schema type
45
+ - **Strings**: Used as-is
46
+
47
+ Unknown environment variables are preserved with an `_appweaver_` prefix.
48
+
49
+ ## Config helper methods
50
+
51
+ The config object provides type-safe accessor methods:
52
+
53
+ ```ts
54
+ import { config } from '@appweaver/common';
55
+
56
+ config.env('APP_ENV', 'prod'); // string
57
+ config.str('APP_NAME', 'MyApp'); // string
58
+ config.int('SERVER_PORT', 5000); // number (integer)
59
+ config.float('SOME_RATIO', 0.5); // number (float)
60
+ config.bool('CACHE_ENABLED', true); // boolean
61
+ config.arr('CORS_METHODS', ['*']); // string[]
62
+ ```
63
+
64
+ The config object is frozen with `Object.freeze()` after loading to prevent runtime mutations.
65
+
66
+ ---
67
+
68
+ ## Configuration properties
69
+
70
+ ### Application (APP_*)
71
+
72
+ | Property | Type | Default | Description |
73
+ |--------------------------|----------|------------------------------------|-----------------------------------------------------------------------------------------------------------|
74
+ | `APP_ENV` | enum | `'prod'` | Application environment. Values: `test`, `local`, `dev`, `staging`, `qa`, `prod`. Mapped from `NODE_ENV`. |
75
+ | `APP_NAME` | string | `'Appweaver'` | Application name. |
76
+ | `APP_DESCRIPTION` | string? | - | Application description. |
77
+ | `APP_HOSTNAME` | string | `'http://localhost:{SERVER_PORT}'` | Application hostname URL. |
78
+ | `APP_RUNTIME` | string | `'node'` | Application runtime. Autodetects Bun global module. Values: `node`, `bun` |
79
+ | `APP_VERSION` | string | `'unknown'` | Application version. Mapped from `npm_package_version`. |
80
+ | `APP_BUILD_PATH` | string | `'./dist'` | Path to compiled build artifacts. |
81
+ | `APP_SOURCE_PATH` | string | `'./src'` | Path to the application source code. Used in other path variables with <srcPath> placeholder. |
82
+ | `APP_SCAN_FILES_PATTERN` | string | `'<srcPath>/*/index.ts'` | Glob pattern for scanning application files. |
83
+ | `APP_MAIN_FILE_PATH` | string | `'<srcPath>/main.ts'` | Path to main application entrypoint file. |
84
+ | `APP_AUTOLOAD_MODULES` | string[] | `[]` | Module paths to auto-load on startup. |
85
+
86
+ ### Logging (LOG_*)
87
+
88
+ | Property | Type | Default | Description |
89
+ |------------------------|---------|----------|------------------------------------------------------------------------------------------|
90
+ | `LOG_LEVEL` | enum | `'info'` | Minimum log level. Values: `silent`, `trace`, `debug`, `info`, `warn`, `error`, `fatal`. |
91
+ | `LOG_PATH` | string? | - | Path to log file. If unset, logs to console only. |
92
+ | `LOG_ROTATE` | boolean | `true` | Enable log file rotation. |
93
+ | `LOG_ROTATE_SIZE` | string | `'100M'` | Maximum size per log file before rotation. |
94
+ | `LOG_ROTATE_MAX_SIZE` | string | `'5G'` | Maximum total size of all log files. |
95
+ | `LOG_ROTATE_MAX_FILES` | integer | `1000` | Maximum number of rotated log files to keep. |
96
+ | `LOG_ROTATE_INTERVAL` | string | `'1d'` | Rotation interval (e.g. `'1d'` for daily). |
97
+ | `LOG_ROTATE_COMPRESS` | boolean | `true` | Compress rotated log files with gzip. |
98
+ | `LOG_PRETTY` | boolean | `false` | Enable pretty-printed JSON logs. |
99
+
100
+ ### Server (SERVER_*)
101
+
102
+ | Property | Type | Default | Description |
103
+ |----------------------------------|---------|--------------|-----------------------------------------------------|
104
+ | `SERVER_PORT` | integer | `5000` | HTTP server listening port. |
105
+ | `SERVER_HOST` | string | `'0.0.0.0'` | HTTP server listening host/IP. |
106
+ | `SERVER_API_PREFIX` | string | `'/api'` | Base path prefix for all API routes. |
107
+ | `SERVER_BODY_MAX_SIZE` | string | `100M` | Maximum request body size. |
108
+ | `SERVER_STATIC_ENABLED` | boolean | `true` | Enable serving static files from disk. |
109
+ | `SERVER_STATIC_DIR_PATH` | string | `'./public'` | Directory containing static files. |
110
+ | `SERVER_STATIC_ROUTE_PREFIX` | string | `'/public'` | URL prefix for static file routes. |
111
+ | `SERVER_STATIC_MAX_AGE` | string | `'30d'` | Cache-Control max-age for static files. |
112
+ | `SERVER_STATIC_ALLOWED_HOST` | string? | - | Host allowed to access static files (CORS). |
113
+ | `SERVER_TRUST_PROXY` | boolean | `true` | Trust `X-Forwarded-*` headers from reverse proxies. |
114
+ | `SERVER_REQUEST_LOGGING_ENABLED` | boolean | `false` | Enable HTTP request/response logging. |
115
+
116
+ ### Rate limiting (RATE_LIMIT_*)
117
+
118
+ | Property | Type | Default | Description |
119
+ |-------------------------|-----------|-----------|------------------------------------------------------------------|
120
+ | `RATE_LIMIT_ENABLED` | boolean | `true` | Enable global rate limiting middleware. |
121
+ | `RATE_LIMIT_MAX` | integer | `1000` | Maximum requests allowed per time window. |
122
+ | `RATE_LIMIT_WINDOW` | integer | `60000` | Rate limit window in milliseconds. |
123
+ | `RATE_LIMIT_ALLOW_LIST` | string[]? | - | IP addresses/patterns exempt from rate limiting. |
124
+ | `RATE_LIMIT_STORE` | enum | `'redis'` | Store backend for tracking limits. Values: `redis`, `in-memory`. |
125
+
126
+ ### Swagger / OpenAPI (SWAGGER_*)
127
+
128
+ | Property | Type | Default | Description |
129
+ |-------------------------|---------|--------------|---------------------------------------------|
130
+ | `SWAGGER_ENABLED` | boolean | `true` | Enable Swagger/OpenAPI documentation UI. |
131
+ | `SWAGGER_PATH` | string | `'/swagger'` | URL path for the Swagger UI. |
132
+ | `SWAGGER_HIDE_UNTAGGED` | boolean | `false` | Hide untagged endpoints from documentation. |
133
+
134
+ ### Health check (HEALTH_CHECK_*)
135
+
136
+ | Property | Type | Default | Description |
137
+ |-------------------------------|-----------|-------------|---------------------------------------------------------------|
138
+ | `HEALTH_CHECK_ENABLED` | boolean | `true` | Enable the health check endpoint. |
139
+ | `HEALTH_CHECK_AUTH` | boolean | `true` | Require authentication for health check. |
140
+ | `HEALTH_CHECK_ROUTE_PREFIX` | string | `'/health'` | URL prefix for health check routes. |
141
+ | `HEALTH_CHECK_CACHE_TTL` | number | `3000` | Cache TTL for the health check response in milliseconds. |
142
+ | `HEALTH_CHECK_PICK_INSTANCES` | string[]? | - | List of health check instance names to include in response. |
143
+ | `HEALTH_CHECK_OMIT_INSTANCES` | string[]? | - | List of health check instance names to exclude from response. |
144
+
145
+ ### CORS (CORS_*)
146
+
147
+ | Property | Type | Default | Description |
148
+ |------------------------|----------|---------|-----------------------------------------------|
149
+ | `CORS_ORIGIN` | string | `'*'` | Allowed origin(s) for CORS requests. |
150
+ | `CORS_METHODS` | string[] | `['*']` | Allowed HTTP methods. |
151
+ | `CORS_ALLOWED_HEADERS` | string[] | `['*']` | Allowed request headers. |
152
+ | `CORS_EXPOSED_HEADERS` | string[] | `['*']` | Headers exposed to the browser. |
153
+ | `CORS_MAX_AGE` | integer | `86400` | Preflight response cache duration in seconds. |
154
+ | `CORS_CREDENTIALS` | boolean | `true` | Allow credentials (cookies, auth headers). |
155
+
156
+ ### Resources (RESOURCE_*)
157
+
158
+ | Property | Type | Default | Description |
159
+ |---------------------------------|--------|--------------------------------------|---------------------------------------------|
160
+ | `RESOURCE_MODEL_PATTERN` | string | `'<srcPath>/resources/*/model.ts'` | Glob pattern for resource model files. |
161
+ | `RESOURCE_SERVICE_PATTERN` | string | `'<srcPath>/resources/*/service.ts'` | Glob pattern for resource service files. |
162
+ | `RESOURCE_POLICY_PATTERN` | string | `'<srcPath>/resources/*/policy.ts'` | Glob pattern for resource policy files. |
163
+ | `RESOURCE_ROUTES_PATTERN` | string | `'<srcPath>/resources/*/routes.ts'` | Glob pattern for resource routes files. |
164
+ | `RESOURCE_GENERATED_TYPES_PATH` | string | `'<srcPath>/types/generated.ts'` | Output path for generated TypeScript types. |
165
+
166
+ ### Data export (EXPORT_*)
167
+
168
+ | Property | Type | Default | Description |
169
+ |-----------------------------|---------|---------|--------------------------------------------------|
170
+ | `EXPORT_BATCH_SIZE` | integer | `1000` | Number of records per batch during export. |
171
+ | `EXPORT_CSV_DELIMITER` | string | `';'` | CSV field delimiter character. |
172
+ | `EXPORT_CSV_JOIN_DELIMITER` | string | `','` | Delimiter for joining array values in CSV cells. |
173
+ | `EXPORT_CSV_ADD_HEADERS` | boolean | `true` | Include a header row in CSV exports. |
174
+ | `EXPORT_CSV_ADD_SEP_ROW` | boolean | `false` | Add separator row (BOM) for Excel compatibility. |
175
+
176
+ ### Security (SECURITY_*)
177
+
178
+ #### General
179
+
180
+ | Property | Type | Default | Description |
181
+ |--------------------------------------|----------|---------------------------------------------------------|--------------------------------------------------|
182
+ | `SECURITY_ROUTE_PREFIX` | string | `'/auth'` | Base path for authentication routes. |
183
+ | `SECURITY_CACHE_TTL` | integer | `300000` | Security cache TTL in milliseconds. |
184
+ | `SECURITY_AUTH_OTT_TTL` | integer | `120000` | One-time token TTL for authentication (ms). |
185
+ | `SECURITY_ALLOWED_REDIRECT_HOSTS` | string[] | `['*']` | Allowed hosts for post-authentication redirects. |
186
+ | `SECURITY_STORE_PROVIDER` | string | `'@appweaver/core/security/store/redis-security-store'` | Security store implementation path. |
187
+ | `SECURITY_STORE_KEEP_DATABASE_TABLE` | boolean | `false` | Keep database table after migrations. |
188
+
189
+ #### Password policy
190
+
191
+ | Property | Type | Default | Description |
192
+ |--------------------------------|---------|---------|-----------------------------------------|
193
+ | `SECURITY_PASSWORD_ENABLED` | boolean | `true` | Enable password-based authentication. |
194
+ | `SECURITY_PASSWORD_MIN_LENGTH` | integer | `8` | Minimum password length. |
195
+ | `SECURITY_PASSWORD_MAX_LENGTH` | integer | `100` | Maximum password length. |
196
+ | `SECURITY_PASSWORD_UPPERCASE` | boolean | `true` | Require at least one uppercase letter. |
197
+ | `SECURITY_PASSWORD_LOWERCASE` | boolean | `true` | Require at least one lowercase letter. |
198
+ | `SECURITY_PASSWORD_NUMERIC` | boolean | `true` | Require at least one digit. |
199
+ | `SECURITY_PASSWORD_SPECIAL` | boolean | `true` | Require at least one special character. |
200
+
201
+ #### Account management
202
+
203
+ | Property | Type | Default | Description |
204
+ |-------------------------------------------|---------|-------------------|-----------------------------------------------------|
205
+ | `SECURITY_ACCOUNT_ROUTE_PREFIX` | string | `'/auth/account'` | Base path for account management routes. |
206
+ | `SECURITY_ACCOUNT_VERIFY_EMAIL_ENABLED` | boolean | `true` | Enable email verification flow. |
207
+ | `SECURITY_ACCOUNT_VERIFY_EMAIL_OTT_TTL` | integer | `7200000` | Email verification token TTL (ms, default 2 hours). |
208
+ | `SECURITY_ACCOUNT_RESET_PASSWORD_ENABLED` | boolean | `true` | Enable password reset flow. |
209
+ | `SECURITY_ACCOUNT_RESET_PASSWORD_OTT_TTL` | integer | `1800000` | Password reset token TTL (ms, default 30 min). |
210
+ | `SECURITY_ACCOUNT_2FA_ENABLED` | boolean | `true` | Enable two-factor authentication. |
211
+ | `SECURITY_ACCOUNT_2FA_FORCED` | boolean | `false` | Force 2FA for all users. |
212
+ | `SECURITY_ACCOUNT_2FA_OTT_TTL` | integer | `300000` | 2FA verification code TTL (ms, default 5 min). |
213
+
214
+ #### reCAPTCHA
215
+
216
+ | Property | Type | Default | Description |
217
+ |----------------------------------|---------|-----------------------------------------------------|----------------------------------------------|
218
+ | `SECURITY_RECAPTCHA_ENABLED` | boolean | `false` | Enable Google reCAPTCHA verification. |
219
+ | `SECURITY_RECAPTCHA_SECRET` | string? | - | Google reCAPTCHA secret key. |
220
+ | `SECURITY_RECAPTCHA_HEADER_NAME` | string | `'x-recaptcha-token'` | Request header name for the reCAPTCHA token. |
221
+ | `SECURITY_RECAPTCHA_MIN_SCORE` | number | `0.4` | Minimum reCAPTCHA v3 score threshold (0-1). |
222
+ | `SECURITY_RECAPTCHA_VERIFY_URL` | string | `'https://www.google.com/recaptcha/api/siteverify'` | Google reCAPTCHA verification endpoint URL. |
223
+
224
+ #### HTTP Basic authentication
225
+
226
+ | Property | Type | Default | Description |
227
+ |-----------------------------|---------|---------|-----------------------------------|
228
+ | `SECURITY_BASIC_ENABLED` | boolean | `false` | Enable HTTP Basic authentication. |
229
+ | `SECURITY_BASIC_REALM` | string? | - | HTTP Basic auth realm name. |
230
+ | `SECURITY_BASIC_PROXY_MODE` | boolean | `false` | Enable proxy mode for Basic auth. |
231
+
232
+ #### API key authentication
233
+
234
+ | Property | Type | Default | Description |
235
+ |----------------------------------------|----------|---------------|----------------------------------------------------|
236
+ | `SECURITY_API_KEY_ENABLED` | boolean | `false` | Enable API key authentication. |
237
+ | `SECURITY_API_KEY_KEEP_DATABASE_TABLE` | boolean | `false` | Keep API key database table after migrations. |
238
+ | `SECURITY_API_KEY_HEADER_NAME` | string | `'x-api-key'` | Request header name for the API key. |
239
+ | `SECURITY_API_KEY_MAX_DURATION` | integer? | - | Maximum API key validity duration in milliseconds. |
240
+ | `SECURITY_API_KEY_DELIMITER` | string | `'AK'` | Prefix delimiter between key ID and secret value. |
241
+
242
+ #### JWT (JSON Web Tokens)
243
+
244
+ | Property | Type | Default | Description |
245
+ |-----------------------------------|---------|--------------------------------|-------------------------------------------------------------------------------|
246
+ | `SECURITY_JWT_SECRET` | string? | - | HMAC secret for symmetric JWT signing (HS256). If set, RSA keys are not used. |
247
+ | `SECURITY_JWT_PUBLIC_KEY_PATH` | string | `'./storage/keys/public.key'` | Path to RSA public key for JWT verification (RS256). |
248
+ | `SECURITY_JWT_PRIVATE_KEY_PATH` | string | `'./storage/keys/private.key'` | Path to RSA private key for JWT signing (RS256). |
249
+ | `SECURITY_JWT_AUTO_GENERATE_KEYS` | boolean | `true` | Auto-generate RSA 2048-bit key pair if missing. |
250
+ | `SECURITY_JWT_EXPIRES_IN` | integer | `2592000` | Access token expiration in seconds (default 30 days). |
251
+ | `SECURITY_JWT_REFRESH_EXPIRES_IN` | integer | `5184000` | Refresh token expiration in seconds (default 60 days). |
252
+
253
+ #### OAuth2 general
254
+
255
+ | Property | Type | Default | Description |
256
+ |-----------------------------|---------|----------|--------------------------------------------------------------|
257
+ | `SECURITY_OAUTH2_STATE_TTL` | integer | `600000` | OAuth2 state parameter TTL in milliseconds (default 10 min). |
258
+
259
+ #### OAuth2 Google
260
+
261
+ | Property | Type | Default | Description |
262
+ |----------------------------------------|---------|---------------------------------------------------|--------------------------------|
263
+ | `SECURITY_OAUTH2_GOOGLE_ENABLED` | boolean | `false` | Enable Google OAuth2 provider. |
264
+ | `SECURITY_OAUTH2_GOOGLE_CLIENT_ID` | string? | - | Google OAuth2 client ID. |
265
+ | `SECURITY_OAUTH2_GOOGLE_CLIENT_SECRET` | string? | - | Google OAuth2 client secret. |
266
+ | `SECURITY_OAUTH2_GOOGLE_USER_INFO_URL` | string | `'https://www.googleapis.com/oauth2/v2/userinfo'` | Google user info endpoint. |
267
+
268
+ #### OAuth2 Facebook
269
+
270
+ | Property | Type | Default | Description |
271
+ |------------------------------------------|---------|-----------------------------------|----------------------------------|
272
+ | `SECURITY_OAUTH2_FACEBOOK_ENABLED` | boolean | `false` | Enable Facebook OAuth2 provider. |
273
+ | `SECURITY_OAUTH2_FACEBOOK_CLIENT_ID` | string? | - | Facebook OAuth2 client ID. |
274
+ | `SECURITY_OAUTH2_FACEBOOK_CLIENT_SECRET` | string? | - | Facebook OAuth2 client secret. |
275
+ | `SECURITY_OAUTH2_FACEBOOK_USER_INFO_URL` | string | `'https://graph.facebook.com/me'` | Facebook user info endpoint. |
276
+
277
+ #### OAuth2 Custom (OpenID Connect)
278
+
279
+ | Property | Type | Default | Description |
280
+ |----------------------------------------|---------|---------|-------------------------------------------------|
281
+ | `SECURITY_OAUTH2_CUSTOM_ENABLED` | boolean | `false` | Enable custom OpenID Connect provider. |
282
+ | `SECURITY_OAUTH2_CUSTOM_CLIENT_ID` | string? | - | Custom OAuth2 client ID. |
283
+ | `SECURITY_OAUTH2_CUSTOM_CLIENT_SECRET` | string? | - | Custom OAuth2 client secret. |
284
+ | `SECURITY_OAUTH2_CUSTOM_ISSUER` | string? | - | OpenID Connect issuer URL (used for discovery). |
285
+
286
+ ### Database (DATABASE_*)
287
+
288
+ | Property | Type | Default | Description |
289
+ |-----------------------------------|----------|----------------------------------------------|--------------------------------------------------------------------------|
290
+ | `DATABASE_TYPE` | enum? | - | Database type. Values: `sqlite`, `postgresql`, `mysql`, `sqlserver`. |
291
+ | `DATABASE_URL` | string | `''` | Database connection URL/DSN. |
292
+ | `DATABASE_SCHEMA_PATH` | string | `'./database/schema.prisma'` | Path to Prisma schema file. |
293
+ | `DATABASE_MIGRATIONS_DIR_PATH` | string | `'./database/migrations'` | Path to database migrations directory. |
294
+ | `DATABASE_SEEDERS_DIR_PATH` | string | `'./database/seeders'` | Path to database seeders directory. |
295
+ | `DATABASE_CLIENT_OUTPUT_DIR_PATH` | string | `'./database/client'` | Path for generated Prisma client output. |
296
+ | `DATABASE_TRANSACTION_MAX_WAIT` | integer | `2000` | Max wait time for acquiring a transaction lock (ms). |
297
+ | `DATABASE_TRANSACTION_TIMEOUT` | integer | `5000` | Transaction timeout in milliseconds. |
298
+ | `DATABASE_LOG_EVENTS` | string[] | `[]` | List of database events to log. Values: `query`, `info`, `warn`, `error` |
299
+ | `DATABASE_PROVIDER` | string | `'@appweaver/core/database/prisma-database'` | Database provider implementation path. |
300
+
301
+ ### File storage (STORAGE_*)
302
+
303
+ | Property | Type | Default | Description |
304
+ |------------------------------|---------|------------------------------------------------|-----------------------------------------------|
305
+ | `STORAGE_PATH` | string | `'./storage'` | Base directory for file storage. |
306
+ | `STORAGE_NAME_PATTERN` | string | `'{name}-{hash}.{extension}'` | File naming pattern for stored files. |
307
+ | `STORAGE_CACHE_TTL` | integer | `86400000` | File storage cache TTL in milliseconds. (24h) |
308
+ | `STORAGE_FILES_ROUTE_PREFIX` | string | `/files` | URL prefix for file access routes. |
309
+ | `STORAGE_PROVIDER` | string | `'@appweaver/core/storage/filesystem-storage'` | Storage provider implementation path. |
310
+
311
+ ### Redis (REDIS_*)
312
+
313
+ | Property | Type | Default | Description |
314
+ |------------------|--------|----------------------------------|-------------------------------------|
315
+ | `REDIS_URL` | string | `'redis://localhost:6379/0'` | Redis connection URL. |
316
+ | `REDIS_PROVIDER` | string | `'@appweaver/core/memory/redis'` | Redis provider implementation path. |
317
+
318
+ ### In-memory store (MEMORY_*)
319
+
320
+ | Property | Type | Default | Description |
321
+ |-------------------|---------|--------------------------------------|-----------------------------------------|
322
+ | `MEMORY_MAX_SIZE` | string? | - | Maximum size of the in-memory store. |
323
+ | `MEMORY_PROVIDER` | string | `'@appweaver/core/memory/in-memory'` | In-memory provider implementation path. |
324
+
325
+ ### Cache (CACHE_*)
326
+
327
+ | Property | Type | Default | Description |
328
+ |-------------------------------|---------|---------------------------------------|------------------------------------------------------------------------|
329
+ | `CACHE_ENABLED` | boolean | `true` | Enable the caching system. |
330
+ | `CACHE_CLEAN_START` | boolean | `false` | Clear all cache entries on application startup. |
331
+ | `CACHE_KEY_PREFIX` | string | `'cache:'` | Prefix prepended to all cache keys. |
332
+ | `CACHE_MAX_ITEMS` | integer | `1000` | Maximum number of items in the cache. |
333
+ | `CACHE_CACHE_MAX_SIZE` | string? | - | Maximum size used by the cache. |
334
+ | `CACHE_DEFAULT_TTL` | integer | `5000` | Default time-to-live for cache entries in milliseconds. |
335
+ | `CACHE_EVICTION_GRACE_PERIOD` | integer | `1000` | Grace period before evicting expired items (ms). |
336
+ | `CACHE_EVICTION_STRATEGY` | enum | `'LRU'` | Eviction strategy. Values: `LRU`, `LFU`, `FIFO`. |
337
+ | `CACHE_EVICTION_DEFERRED` | boolean | `false` | Defer eviction to a background process. |
338
+ | `CACHE_INVALIDATION_STRATEGY` | enum | `'expire-related'` | Invalidation strategy. Values: `expire-related`, `expire-all`, `none`. |
339
+ | `CACHE_INVALIDATION_DEFERRED` | boolean | `false` | Defer invalidation to a background process. |
340
+ | `CACHE_PROVIDER` | string | `'@appweaver/core/cache/redis-cache'` | Cache provider implementation path. |
341
+
342
+ ### Job queue (QUEUE_*)
343
+
344
+ | Property | Type | Default | Description |
345
+ |--------------------------------|----------|--------------------------------------|--------------------------------------------------------|
346
+ | `QUEUE_KEEP_COMPLETED_COUNT` | integer | `0` | Number of completed jobs to retain in the queue. |
347
+ | `QUEUE_KEEP_COMPLETED_SECONDS` | integer? | - | Time to keep completed jobs in seconds. |
348
+ | `QUEUE_KEEP_FAILED_COUNT` | integer | `50` | Number of failed jobs to retain in the queue. |
349
+ | `QUEUE_KEEP_FAILED_SECONDS` | integer? | - | Time to keep failed jobs in seconds. |
350
+ | `QUEUE_RETRY_ATTEMPTS` | integer | `3` | Number of retry attempts for failed jobs. |
351
+ | `QUEUE_RETRY_BACKOFF` | integer | `3000` | Initial backoff delay between retries in milliseconds. |
352
+ | `QUEUE_RETRY_BACKOFF_TYPE` | enum | `'fixed'` | Retry backoff type. Values: `fixed`, `exponential`. |
353
+ | `QUEUE_PROVIDER` | string | `'@appweaver/core/queue/bull-queue'` | Job queue provider implementation path. |
354
+
355
+ ### Scheduler (SCHEDULER_*)
356
+
357
+ | Property | Type | Default | Description |
358
+ |----------------------------|---------|----------------------------------------------|---------------------------------------------------|
359
+ | `SCHEDULER_AUTO_START_JOB` | boolean | `true` | Auto-start scheduled jobs on application startup. |
360
+ | `SCHEDULER_PROVIDER` | string | `'@appweaver/core/scheduler/cron-scheduler'` | Scheduler provider implementation path. |
361
+
362
+ ### Events (EVENTS_*)
363
+
364
+ | Property | Type | Default | Description |
365
+ |------------------------|---------|----------------------------------------|---------------------------------------------|
366
+ | `EVENTS_MAX_LISTENERS` | integer | `20` | Maximum event listeners per event type. |
367
+ | `EVENTS_PROVIDER` | string | `'@appweaver/core/events/node-events'` | Event emitter provider implementation path. |
368
+
369
+ ### Mailer (MAILER_*)
370
+
371
+ | Property | Type | Default | Description |
372
+ |-------------------------|---------|----------------------------------------|------------------------------------------|
373
+ | `MAILER_SENDER_NAME` | string? | - | Default sender name for outgoing emails. |
374
+ | `MAILER_SENDER_ADDRESS` | string? | - | Default sender email address. |
375
+ | `MAILER_PROVIDER` | string | `'@appweaver/core/mailer/smtp-mailer'` | Mailer provider implementation path. |
376
+ | `MAILER_SMTP_HOST` | string | `'127.0.0.1'` | SMTP server hostname. |
377
+ | `MAILER_SMTP_PORT` | integer | `587` | SMTP server port. |
378
+ | `MAILER_SMTP_SECURE` | boolean | `false` | Use TLS/SSL for SMTP connections. |
379
+ | `MAILER_SMTP_USER` | string? | - | SMTP authentication username. |
380
+ | `MAILER_SMTP_PASSWORD` | string? | - | SMTP authentication password. |
381
+
382
+ ### System (SYSTEM_*)
383
+
384
+ | Property | Type | Default | Description |
385
+ |---------------------------------|---------|------------------------|---------------------------------------------------|
386
+ | `SYSTEM_ADMIN_INITIAL_EMAIL` | string | `'admin@appweaver.co'` | Initial admin account email created on first run. |
387
+ | `SYSTEM_ADMIN_INITIAL_PASSWORD` | string? | - | Initial admin account password. |
388
+
389
+ ---
390
+
391
+ ## Configuration files summary
392
+
393
+ | File | Purpose |
394
+ |------------------------|---------------------------------------------|
395
+ | `appweaver.json` | Global configuration (all environments) |
396
+ | `appweaver.{env}.json` | Environment-specific overrides |
397
+ | `.env` | Environment variables (all environments) |
398
+ | `.env.{env}` | Environment-specific env variable overrides |
399
+
400
+ ## Environment values
401
+
402
+ `test`, `local`, `dev`, `staging`, `qa`, `prod` or any custom value like `preStaging` or `prod-us-east`
@@ -0,0 +1,134 @@
1
+ # Database
2
+
3
+ The database module exposes a thin abstraction over the underlying database client. The default implementation
4
+ wraps [Prisma](https://www.prisma.io/) and is registered under the abstract `Database` class. The framework connects on
5
+ startup and disconnects on shutdown automatically.
6
+
7
+ ## Injecting the client
8
+
9
+ ```ts
10
+ import { inject } from '@appweaver/core';
11
+ import { Database } from '@appweaver/common';
12
+ import { PrismaClient } from '@db/client/client';
13
+
14
+ export const db = inject(Database).client<PrismaClient>();
15
+
16
+ export default db;
17
+ ```
18
+
19
+ #### `db.client<T>()`
20
+
21
+ Returns the underlying database client cast to type `T`. For the default Prisma provider `T` is `PrismaClient`.
22
+
23
+ ```ts
24
+ const users = await client.user.findMany({ where: { active: true } });
25
+ ```
26
+
27
+ #### `db.connect()`
28
+
29
+ Opens the database connection. Called automatically by the framework during `onInit`.
30
+
31
+ #### `db.disconnect()`
32
+
33
+ Closes the database connection. Called automatically by the framework during `onDestroy`.
34
+
35
+ #### `db.checkHealth()`
36
+
37
+ Returns a `HealthCheckResult`. Executes a lightweight `SELECT 1` query to verify the connection.
38
+
39
+ ---
40
+
41
+ ## Schema and migrations
42
+
43
+ By convention the Prisma schema lives at `./database/schema.prisma` and migrations at `./database/migrations/`. These
44
+ paths are configurable.
45
+
46
+ **schema.prisma example:**
47
+
48
+ ```prisma
49
+ datasource db {
50
+ provider = env("DATABASE_TYPE")
51
+ url = env("DATABASE_URL")
52
+ }
53
+
54
+ generator client {
55
+ provider = "prisma-client-js"
56
+ }
57
+
58
+ model User {
59
+ id Int @id @default(autoincrement())
60
+ email String @unique
61
+ name String
62
+ }
63
+ ```
64
+
65
+ Generate the Prisma schema and client after resource models change:
66
+
67
+ ```bash
68
+ weaver generate
69
+ ```
70
+
71
+ Create new migrations:
72
+
73
+ ```bash
74
+ weaver migration new <migration_name>
75
+ ```
76
+
77
+ Run pending migrations:
78
+
79
+ ```bash
80
+ weaver migrate
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Configuration
86
+
87
+ | Key | Type | Default | Description |
88
+ |---------------------------------|----------|----------------------------------------------|-------------------------------------------------|
89
+ | `DATABASE_TYPE` | `enum` | — | `sqlite`, `postgresql`, `mysql`, or `sqlserver` |
90
+ | `DATABASE_URL` | `string` | — | Connection string / DSN |
91
+ | `DATABASE_SCHEMA_PATH` | `string` | `'./database/schema.prisma'` | Path to the Prisma schema file |
92
+ | `DATABASE_MIGRATIONS_DIR_PATH` | `string` | `'./database/migrations'` | Path to the migrations directory |
93
+ | `DATABASE_TRANSACTION_MAX_WAIT` | `int` | `2000` | Max time (ms) to wait to acquire a transaction |
94
+ | `DATABASE_TRANSACTION_TIMEOUT` | `int` | `5000` | Max time (ms) a transaction may run |
95
+ | `DATABASE_PROVIDER` | `string` | `'@appweaver/core/database/prisma-database'` | Path to the Database implementation |
96
+
97
+ **`appweaver.json` example:**
98
+
99
+ ```json
100
+ {
101
+ "DATABASE_TYPE": "postgresql",
102
+ "DATABASE_URL": "postgresql://user:pass@localhost:5432/myapp?schema=public"
103
+ }
104
+ ```
105
+
106
+ **`.env` example:**
107
+
108
+ ```
109
+ DATABASE_TYPE=postgresql
110
+ DATABASE_URL=postgresql://user:pass@localhost:5432/myapp?schema=public
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Real-world example
116
+
117
+ ```ts
118
+ import { inject } from '@appweaver/core';
119
+ import db from '@db/client';
120
+
121
+ export class UserRepository {
122
+ async findById(id: number) {
123
+ return db.user.findUnique({ where: { id } });
124
+ }
125
+
126
+ async create(data: { email: string; name: string }) {
127
+ return db.user.create({ data });
128
+ }
129
+
130
+ async runInTransaction<T>(fn: (tx: PrismaClient) => Promise<T>): Promise<T> {
131
+ return db.$transaction(fn);
132
+ }
133
+ }
134
+ ```