chadstart 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 (115) hide show
  1. package/.dockerignore +10 -0
  2. package/.env.example +46 -0
  3. package/.github/workflows/browser-test.yml +34 -0
  4. package/.github/workflows/docker-publish.yml +54 -0
  5. package/.github/workflows/docs.yml +31 -0
  6. package/.github/workflows/npm-chadstart.yml +27 -0
  7. package/.github/workflows/npm-sdk.yml +38 -0
  8. package/.github/workflows/test.yml +85 -0
  9. package/.weblate +9 -0
  10. package/Dockerfile +23 -0
  11. package/README.md +348 -0
  12. package/admin/index.html +2802 -0
  13. package/admin/login.html +207 -0
  14. package/chadstart.example.yml +416 -0
  15. package/chadstart.schema.json +367 -0
  16. package/chadstart.yaml +53 -0
  17. package/cli/cli.js +295 -0
  18. package/core/api-generator.js +606 -0
  19. package/core/auth.js +298 -0
  20. package/core/db.js +384 -0
  21. package/core/entity-engine.js +166 -0
  22. package/core/error-reporter.js +132 -0
  23. package/core/file-storage.js +97 -0
  24. package/core/functions-engine.js +353 -0
  25. package/core/openapi.js +171 -0
  26. package/core/plugin-loader.js +92 -0
  27. package/core/realtime.js +93 -0
  28. package/core/schema-validator.js +50 -0
  29. package/core/seeder.js +231 -0
  30. package/core/telemetry.js +119 -0
  31. package/core/upload.js +372 -0
  32. package/core/workers/php_worker.php +19 -0
  33. package/core/workers/python_worker.py +33 -0
  34. package/core/workers/ruby_worker.rb +21 -0
  35. package/core/yaml-loader.js +64 -0
  36. package/demo/chadstart.yaml +178 -0
  37. package/demo/docker-compose.yml +31 -0
  38. package/demo/functions/greet.go +39 -0
  39. package/demo/functions/hello.cpp +18 -0
  40. package/demo/functions/hello.py +13 -0
  41. package/demo/functions/hello.rb +10 -0
  42. package/demo/functions/onTodoCreated.js +13 -0
  43. package/demo/functions/ping.sh +13 -0
  44. package/demo/functions/stats.js +22 -0
  45. package/demo/public/index.html +522 -0
  46. package/docker-compose.yml +17 -0
  47. package/docs/access-policies.md +155 -0
  48. package/docs/admin-ui.md +29 -0
  49. package/docs/angular.md +69 -0
  50. package/docs/astro.md +71 -0
  51. package/docs/auth.md +160 -0
  52. package/docs/cli.md +56 -0
  53. package/docs/config.md +127 -0
  54. package/docs/crud.md +627 -0
  55. package/docs/deploy.md +113 -0
  56. package/docs/docker.md +59 -0
  57. package/docs/entities.md +385 -0
  58. package/docs/functions.md +196 -0
  59. package/docs/getting-started.md +79 -0
  60. package/docs/groups.md +85 -0
  61. package/docs/index.md +5 -0
  62. package/docs/llm-rules.md +81 -0
  63. package/docs/middlewares.md +78 -0
  64. package/docs/overrides/home.html +350 -0
  65. package/docs/plugins.md +59 -0
  66. package/docs/react.md +75 -0
  67. package/docs/realtime.md +43 -0
  68. package/docs/s3-storage.md +40 -0
  69. package/docs/security.md +23 -0
  70. package/docs/stylesheets/extra.css +375 -0
  71. package/docs/svelte.md +71 -0
  72. package/docs/telemetry.md +97 -0
  73. package/docs/upload.md +168 -0
  74. package/docs/validation.md +115 -0
  75. package/docs/vue.md +86 -0
  76. package/docs/webhooks.md +87 -0
  77. package/index.js +11 -0
  78. package/locales/en/admin.json +169 -0
  79. package/mkdocs.yml +82 -0
  80. package/package.json +65 -0
  81. package/playwright.config.js +24 -0
  82. package/public/.gitkeep +0 -0
  83. package/sdk/README.md +284 -0
  84. package/sdk/package.json +39 -0
  85. package/sdk/scripts/build.js +58 -0
  86. package/sdk/src/index.js +368 -0
  87. package/sdk/test/sdk.test.cjs +340 -0
  88. package/sdk/types/index.d.ts +217 -0
  89. package/server/express-server.js +734 -0
  90. package/test/access-policies.test.js +96 -0
  91. package/test/ai.test.js +81 -0
  92. package/test/api-keys.test.js +361 -0
  93. package/test/auth.test.js +122 -0
  94. package/test/browser/admin-ui.spec.js +127 -0
  95. package/test/browser/global-setup.js +71 -0
  96. package/test/browser/global-teardown.js +11 -0
  97. package/test/db.test.js +227 -0
  98. package/test/entity-engine.test.js +193 -0
  99. package/test/error-reporter.test.js +140 -0
  100. package/test/functions-engine.test.js +240 -0
  101. package/test/groups.test.js +212 -0
  102. package/test/hot-reload.test.js +153 -0
  103. package/test/i18n.test.js +173 -0
  104. package/test/middleware.test.js +76 -0
  105. package/test/openapi.test.js +67 -0
  106. package/test/schema-validator.test.js +83 -0
  107. package/test/sdk.test.js +90 -0
  108. package/test/seeder.test.js +279 -0
  109. package/test/settings.test.js +109 -0
  110. package/test/telemetry.test.js +254 -0
  111. package/test/test.js +17 -0
  112. package/test/upload.test.js +265 -0
  113. package/test/validation.test.js +96 -0
  114. package/test/yaml-loader.test.js +93 -0
  115. package/utils/logger.js +24 -0
@@ -0,0 +1,155 @@
1
+ ---
2
+ id: access
3
+ title: Access Policies & Authorization
4
+ description: Learn how to implement API policies to restrict resource access for CRUD operations and endpoints.
5
+ ---
6
+
7
+ # Access policies
8
+
9
+ Access Policies ensure that we provide specific access to resources for users. You may want to open publicly the **read** access for an entity while limiting **creation** to logged in users for example.
10
+
11
+ Access policies are a way to implement **Authorization** following the RBAC (Role-Based Access Control) method. Indeed it is possible to create different entities (ex: User, Manager...) with different access to resources. You also can limit access to a user own's records using [ownership-based access](#ownership-based-access).
12
+
13
+ Policies can be added to [entities](./entities.md) and [endpoints](./functions.md).
14
+
15
+ !!! info
16
+ By default, all CRUD rules access are set to **admin** and thus only available for logged-in admins. Custom endpoints are **public** by default.
17
+
18
+ ## Syntax
19
+
20
+ The policies for each rule can be added to each [entity description](./entities.md) as shown below:
21
+
22
+ ```yaml
23
+ entities:
24
+ Invoice 🧾:
25
+ properties:
26
+ - number
27
+ - { name: issueDate, type: date }
28
+ policies:
29
+ create:
30
+ - { access: restricted, allow: User } # Only logged in users can create.
31
+ read:
32
+ - access: public # All read endpoints are public.
33
+ update:
34
+ - access: admin # Only logged in admins can update.
35
+ delete:
36
+ - access: forbidden # No one can delete (even admins!)
37
+ ```
38
+
39
+ In this case, everyone can see the **Invoice** items, only logged-in **Users** can create new ones. Updating an Invoice is restricted to [Admins](./auth.md#admins) only and no one can delete them (not even Admins).
40
+
41
+ | Prop | Description | Type |
42
+ | ---------- | ------------------------------------------------------------------------- | ------------------ |
43
+ | **access** | The type of access: **public**, **restricted**, **admin**, **forbidden** | AccessType |
44
+ | **allow** | Only for **restricted** access: the entity (or entities) that have access | string \| string[] |
45
+
46
+ ### Access types
47
+
48
+ There are 4 possible access types:
49
+
50
+ | Access | Description | Short version (emoji) |
51
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------- |
52
+ | **public** | Everyone has access | 🌐 |
53
+ | **restricted** | Only logged-in users have access to it. The _allow_ key must be used to specify one or several [authenticable entities](./auth.md#authenticable-entities) that will have access to the content. If _condition_ is set to `self`, it limits access to the item owner. Admins always have access to restricted rules | 🔒 |
54
+ | **admin** | Only [admins](./auth.md#admins) have access | 👨🏻‍💻 |
55
+ | **forbidden** | No one has access, not even admins | 🚫 |
56
+
57
+ ### Entity rules
58
+
59
+ Each entity has **5 rules** where one or several access policies can be applied:
60
+
61
+ - **create**: create a new item
62
+ - **read**: see the detail and the list of items
63
+ - **update**: update an existing item
64
+ - **delete**: delete an existing item
65
+ - **signup**: sign up as a new user (only for [authenticable entities](./auth.md#authenticable-entities))
66
+
67
+ By default, all rules have the [admin access type](#access-types)
68
+
69
+ ## Ownership-based access
70
+
71
+ Above rules are based on predefined roles, but you many want to grant user access only to their own records. For example, a platform like _Craigslist_ allows its users to create and manage classified ads only for them, not letting users edit others' content.
72
+
73
+ In ChadStart, this is done simply by adding the `{condition: 'self'}` to a restricted policy:
74
+
75
+ ```yaml
76
+ User:
77
+ properties:
78
+ - name
79
+ authenticable: true
80
+
81
+ Project:
82
+ properties:
83
+ - name
84
+ belongsTo:
85
+ - User # Should belong to an authenticable entity.
86
+ policies:
87
+ create:
88
+ - { access: restricted, allow: User, condition: self }
89
+ ```
90
+
91
+ See? Just adding the `self` condition prevent creating projects for other users than themselves.
92
+
93
+ Even if it looks very simple, it has slightly different impact based on rule where it is added. See the following example:
94
+
95
+ ```yaml
96
+ policies:
97
+ create:
98
+ - { access: restricted, allow: User, condition: self }
99
+ read:
100
+ - { access: restricted, allow: User, condition: self }
101
+ update:
102
+ - { access: restricted, allow: User, condition: self }
103
+ delete:
104
+ - { access: restricted, allow: User, condition: self }
105
+ ```
106
+
107
+ This means:
108
+
109
+ - Create: Record creation is authorized only if owner is the logged in user
110
+ - Read: You can only fetch your own record: it forces a filter
111
+ - Update: You only can update your own records and cannot change the ownership of them
112
+ - Delete: You only can delete your own records
113
+
114
+ ## Additional examples
115
+
116
+ ```yaml
117
+ entities:
118
+ Project 🗂️:
119
+ properties:
120
+ - name
121
+ belongsTo:
122
+ - Manager
123
+ policies:
124
+ read:
125
+ - { access: restricted, allow: [Contributor, Manager] } # Only some entities (and admins).
126
+ create:
127
+ - { access: restricted, allow: Manager, condition: self } # Only managers for themselves (and admins).
128
+ update:
129
+ - access: 👨🏻‍💻 # Only admin.
130
+ delete:
131
+ - access: 🚫 # Forbidden (no one).
132
+
133
+ Contributor 👨‍💼:
134
+ authenticable: true
135
+ properties:
136
+ - name
137
+ policies:
138
+ signup:
139
+ - access: 🚫 # Forbidden (no one).
140
+ create:
141
+ - { access: 🔒, allow: Manager } # Managers can create contributors.
142
+ update:
143
+ - { access: 🔒, allow: Manager }
144
+ delete:
145
+ - { access: 🔒, allow: Manager } # Managers can create contributors.
146
+
147
+ functions:
148
+ basicEndpoint:
149
+ path: /basic
150
+ description: A basic endpoint that returns a simple message.
151
+ method: GET
152
+ function: basicEndpoint.js
153
+ policies:
154
+ - access: public # This endpoint is public.
155
+ ```
@@ -0,0 +1,29 @@
1
+ # Admin UI
2
+
3
+ ChadStart ships with a built-in dark-mode single-page Admin UI at `/admin`.
4
+
5
+ ## Features
6
+
7
+ - **Sidebar** with all entities and user collections
8
+ - **Data table** with CRUD (create, edit, delete) for every record
9
+ - **Login screen** — any user collection with `admin: true` (default) can sign in
10
+
11
+ ## Access
12
+
13
+ Navigate to `http://localhost:3000/admin` and log in with credentials from any user collection that has `admin: true`.
14
+
15
+ ## Excluding Collections from Admin
16
+
17
+ Set `admin: false` on a collection to prevent it from logging into the Admin UI:
18
+
19
+ ```yaml
20
+ userCollections:
21
+ Customer:
22
+ properties:
23
+ - name
24
+ admin: false # cannot log in to Admin UI
25
+ ```
26
+
27
+ ## Rate Limiting
28
+
29
+ Admin UI is rate-limited to **100 requests / minute per IP**.
@@ -0,0 +1,69 @@
1
+ ---
2
+ id: angular
3
+ title: Create a Full-Stack app with Angular and ChadStart
4
+ description: Quick start guide to create a full-stack app using Angular as a frontend and ChadStart as a backend.
5
+ ---
6
+
7
+ # Quick start with Angular
8
+
9
+ Give a proper backend to your Angular app.
10
+
11
+ !!! warning
12
+ This quick start guide focuses exclusively on the **frontend**. To ensure the functionality of this code, your ChadStart backend must be [up and running](./getting-started.md#install-chadstart) at `http://localhost:3000`.
13
+
14
+ ## 1. Create a Angular app
15
+
16
+ If you already have your Angular app up and running, skip this step.
17
+
18
+ We will use the [Angular CLI](https://angular.dev/tools/cli) to create a new Angular project. You can replace `my-client` by the name of your front-end app.
19
+
20
+ ```
21
+ ng new my-client
22
+ cd my-client
23
+ ng serve
24
+ ```
25
+
26
+ ## 2. Install ChadStart SDK
27
+
28
+ Install the JS SDK from the root of your Angular app.
29
+
30
+ ```
31
+ npm i @chadstart/sdk
32
+ ```
33
+
34
+ ## 3. Use it in your app
35
+
36
+ In that example we are using a Cat entity [created previously](entities.md). Replace it by your own entity.
37
+
38
+ ```js title="app.component.ts"
39
+ import { Component } from '@angular/core'
40
+ import ChadStart from '@chadstart/sdk'
41
+
42
+ @Component({
43
+ selector: 'app-root',
44
+ templateUrl: './app.component.html',
45
+ styleUrls: ['./app.component.css']
46
+ })
47
+ export class AppComponent {
48
+ cats: { id: string, name: string }[] = []
49
+
50
+ async ngOnInit() {
51
+ // Init SDK.
52
+ const chadstart = new ChadStart()
53
+
54
+ // Fetch the list of Cats.
55
+ const result = await chadstart.from('cats').find()
56
+ this.cats = result.data
57
+ }
58
+ }
59
+ ```
60
+
61
+ And in the template:
62
+
63
+ ```html
64
+ <ul>
65
+ <li *ngFor="let cat of cats">{{ cat.name }}</li>
66
+ </ul>
67
+ ```
68
+
69
+ Checkout the [SDK doc](./crud.md#using-the-javascript-sdk) to see more usages of the SDK: CRUD operations, file upload, authentication,
package/docs/astro.md ADDED
@@ -0,0 +1,71 @@
1
+ ---
2
+ id: astro
3
+ title: Create a Full-Stack app with Astro and ChadStart
4
+ description: Quick start guide to create a full-stack app using Astro as a frontend and ChadStart as a backend.
5
+ ---
6
+
7
+ # Quick start with Astro
8
+
9
+ Connect your ChadStart backend to your Astro app.
10
+
11
+ !!! warning
12
+ This quick start guide focuses exclusively on the **frontend**. To ensure the functionality of this code, your ChadStart backend must be [up and running](./getting-started.md#install-chadstart) at `http://localhost:3000`.
13
+
14
+ ## 1. Create a Astro app
15
+
16
+ If you already have your Astro app up and running, skip this step. Replace `my-astro-app` by the name of the Astro app created.
17
+
18
+ ```
19
+ npm create astro@latest
20
+ cd my-astro-app
21
+ npm run dev
22
+ ```
23
+
24
+ ## 2. Install ChadStart SDK
25
+
26
+ Install the JS SDK from the root of your Astro app.
27
+
28
+ ```
29
+ npm i @chadstart/sdk
30
+ ```
31
+
32
+ ## 3. Use it in your app
33
+
34
+ In that example we are using a Cat entity [created previously](entities.md). Replace it by your own entity.
35
+
36
+ ```js
37
+ ---
38
+
39
+ import ChadStart from '@chadstart/sdk'
40
+
41
+ // Init SDK.
42
+ const chadstart = new ChadStart()
43
+
44
+ // Fetch the cat list.
45
+ const result = await chadstart.from('cats').find()
46
+ const cats = result.data
47
+
48
+ ---
49
+
50
+ <html lang="en">
51
+ <head>
52
+ <meta charset="utf-8" />
53
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
54
+ <meta name="viewport" content="width=device-width" />
55
+ <meta name="generator" content={Astro.generator} />
56
+ <title>Astro</title>
57
+ </head>
58
+ <body>
59
+ <ul>
60
+ {
61
+ cats.map((cat) => (
62
+ <li>{cat.name}</li>
63
+ ))
64
+ }
65
+ </ul>
66
+
67
+ </body>
68
+ </html>
69
+ ```
70
+
71
+ Checkout the [SDK doc](./crud.md#using-the-javascript-sdk) to see more usages of the SDK: CRUD operations, file upload, authentication,
package/docs/auth.md ADDED
@@ -0,0 +1,160 @@
1
+ ---
2
+ id: authentication
3
+ title: Authentication
4
+ description: Implement Authentication quickly with ChadStart built-in Auth component. Manage log in, sign up and admin roles.
5
+ ---
6
+
7
+ # Authentication
8
+
9
+ ## Introduction
10
+
11
+ Authentication is the process of proving that people are who they say they are.
12
+
13
+ ChadStart uses **JSON Web Tokens (JWT)** to do that. When you log in, you basically create a new **token** that you use in your next requests to prove your identity. This allows us to use [Policies](./access-policies.md) to grant or deny the access to some resources based on the user characteristics.
14
+
15
+ !!! info
16
+ Notice the `TOKEN_SECRET_KEY` variable in your `.env` file ? This is the key that will encrypt your tokens, you can [generate one here](https://jwtsecrets.com/).
17
+
18
+ ## Admins
19
+
20
+ Admins are a built-in entity that are **the only ones with access to the admin panel** (located at http://localhost:3000 by default). The admins are usually the people who manage the application on a day-to-day basis. Only admins can see and manage other admins.
21
+
22
+ Even though they are the most powerful users of your application, you can still create some [policies](./access-policies.md) that will restrict the access even for them.
23
+
24
+ The [seed command](./entities.md#collections) will create an admin with the email `admin@chadstart.com` and the password `admin`. You can create more admins from the admin panel.
25
+
26
+ !!! tip
27
+ In ChadStart, the admin panel is **non-technical** 😺.
28
+
29
+ It means that you can give credentials to the administrators of your app without worrying that they will end up breaking the system!
30
+
31
+ ## Authenticable entities
32
+
33
+ You can convert any entity into an **authenticatable entity**, allowing users to log in with it.
34
+
35
+ ```yaml
36
+ entities:
37
+ Patient 🤒:
38
+ authenticable: true # Makes entity authenticable.
39
+ properties:
40
+ - name
41
+ ```
42
+
43
+ Authenticable entities have 2 extra properties that are used as credentials to log in: `email` and `password`. You do not need to specify them.The `email` property expects a unique valid emails and the `password` property is automatically hashed using _bcryt_ with 10 salt rounds.
44
+
45
+ ## Actions
46
+
47
+ ### Login
48
+
49
+ Log in your credentials as an **admin** or an **authenticable entity**.
50
+
51
+ === "REST API"
52
+ ```http title="Example HTTP Request"
53
+ POST /api/auth/admins/login
54
+ Content-Type: application/json
55
+ {
56
+ "email": "admin@chadstart.com",
57
+ "password": "password"
58
+ }
59
+ ```
60
+ ```json title="Example HTTP Response"
61
+ {
62
+ "token": "12345"
63
+ }
64
+ ```
65
+
66
+ Then you can add your token to your requests `Authorization` header using the **Bearer** prefix:
67
+
68
+ ```http
69
+ GET /api/dynamic/cats
70
+ Content-Type: application/json
71
+ Authorization: Bearer your-token-here
72
+ ```
73
+
74
+ === "JS SDK"
75
+ ```js
76
+ // Login as Admin.
77
+ await chadstart.login('admins', 'admin@chadstart.com', 'password')
78
+
79
+ // Login as User entity.
80
+ await chadstart.login('users', 'user@example.com', 'password')
81
+
82
+ // Then all following requests will have the authorization token in their header until logout.
83
+ const example = await chadstart.from('restricted-resource').find()
84
+ ```
85
+
86
+ ### Sign up
87
+
88
+ Any authenticable entity allows new users to sign up if the [policies](./access-policies.md) permit it.
89
+
90
+ === "REST API"
91
+ ```http title="Example HTTP Request"
92
+ POST /api/auth/users/signup
93
+ Content-Type: application/json
94
+ {
95
+ "email": "user@example.com",
96
+ "password": "password"
97
+ }
98
+ ```
99
+ ```json title="Example HTTP Response"
100
+ {
101
+ "token": "12345"
102
+ }
103
+ ```
104
+
105
+ Same as [login](#login), you can add your token to your requests `Authorization` header using the **Bearer** prefix:
106
+
107
+ ```http
108
+ GET /api/dynamic/cats
109
+ Content-Type: application/json
110
+ Authorization: Bearer your-token-here
111
+ ```
112
+
113
+ === "JS SDK"
114
+ ```js
115
+ // Sign up as a new user.
116
+ await chadstart.signup('users', 'user@example.com', 'password')
117
+
118
+ // Then all following requests will have the authorization token in its header until logout.
119
+ const example = await chadstart.from('restricted-resource').find()
120
+ ```
121
+
122
+ !!! info
123
+ It is not possible to sign up as an **admin**. If you want to create more admins, do it from the admin panel.
124
+
125
+ ### Get current user
126
+
127
+ Get the current logged-in user.
128
+
129
+ === "REST API"
130
+ ```http title="Example HTTP Request"
131
+ GET /api/auth/contributors/me
132
+ Content-Type: application/json
133
+ Authorization: Bearer your-token-here
134
+ ```
135
+
136
+ ```json title="Example HTTP Response"
137
+ {
138
+ id: 'a8f5f167-6d3b-4c8f-9e2a-7b4d8c9f1e3a',
139
+ email: 'contributor@test.com'
140
+ }
141
+ ```
142
+
143
+ === "JS SDK"
144
+ ```js
145
+ // Get the current user (logged as Contributor entity).
146
+ const me = await chadstart.from('contributors').me()
147
+ ```
148
+
149
+ ### Logout
150
+
151
+ Logout removes the token from future request headers.
152
+
153
+ === "REST API"
154
+ Reset the `Authorization` header as you usually do, and you are good to go!
155
+
156
+ === "JS SDK"
157
+ ```js
158
+ // Resets the "Authorization" header for all future calls.
159
+ await chadstart.logout()
160
+ ```
package/docs/cli.md ADDED
@@ -0,0 +1,56 @@
1
+ # CLI
2
+
3
+ ChadStart includes a CLI for common development and production tasks.
4
+
5
+ ## Commands
6
+
7
+ ```
8
+ npx chadstart create [path] # Create a new ChadStart project
9
+ npx chadstart dev [--config path] [--port N] # Hot-reload dev server
10
+ npx chadstart start [--config path] [--port N] # Production server
11
+ npx chadstart build [--config path] # Validate & summarize config
12
+ ```
13
+
14
+ ## `create`
15
+
16
+ Create a new ChadStart project
17
+
18
+ ```bash
19
+ npx chadstart create
20
+ npx chadstart create new-folder-name
21
+ ```
22
+
23
+ ## `dev`
24
+
25
+ Starts the server with hot-reload on config file changes:
26
+
27
+ ```bash
28
+ npx chadstart dev
29
+ npx chadstart dev --config ./my-config.yaml
30
+ npx chadstart dev --port 4000
31
+ ```
32
+
33
+ ## `start`
34
+
35
+ Starts the server in production mode (no hot-reload):
36
+
37
+ ```bash
38
+ npx chadstart start
39
+ npx chadstart start --config ./my-config.yaml --port 8080
40
+ ```
41
+
42
+ ## `build`
43
+
44
+ Validates the config file and prints a summary without starting the server:
45
+
46
+ ```bash
47
+ npx chadstart build
48
+ npx chadstart build --config ./my-config.yaml
49
+ ```
50
+
51
+ ## Options
52
+
53
+ | Option | Description |
54
+ |--------|-------------|
55
+ | `--config <path>` | Path to config file (default: `./chadstart.yaml`) |
56
+ | `--port <number>` | Override port from config (default: `3000`) |
package/docs/config.md ADDED
@@ -0,0 +1,127 @@
1
+ ---
2
+ id: config
3
+ title: ChadStart Configuration
4
+ description: Configure ChadStart Database (PostgreSQL, MySQL or SQLite), Port, OpenAPI and environments with a simple config.
5
+ ---
6
+
7
+ # Configuration
8
+
9
+ ## Introduction
10
+
11
+ ChadStart embraces the **convention over configuration** concept: it assumes several logical situations by default without showing you the setting to keep things as simple as possible.
12
+
13
+ Nevertheless there is still the possibility to adapt your ChadStart app to your needs, especially through the `.env` file. Here is the list of available environment variables:
14
+
15
+ ## General variables
16
+
17
+ General environment variables.
18
+
19
+ | Variable | Default | Description |
20
+ | ------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
21
+ | NODE_ENV | `development` | The app environment. For production and staging instances, it should be set to `production`, mostly to turn off live reload on file change. |
22
+ | PORT | `3000` | The port of your app. You can either adapt your server settings to listen to `3000` or change here to your server's default. |
23
+ | BASE_URL | `http://localhost:$PORT` | The base url of your backend. Change it when deploying if you use [file or image upload](./upload.md) |
24
+ | OPEN_API_DOCS | `true` unless `NODE_ENV=production` | Determines whether the OpenAPI doc is shown (formerly Swagger) for your REST API at `/api`. Make sure to set to `true` if you want to display on production |
25
+
26
+ ## Paths
27
+
28
+ Environment variables related to paths.
29
+
30
+ | Variable | Default | Description |
31
+ | ------------------------ | --------------- | --------------------------------------------------------------------------------------------------------------------------- |
32
+ | PUBLIC_FOLDER | `/public` | The public folder to show [static files](https://expressjs.com/en/starter/static-files.html) |
33
+ | CHADSTART_FUNCTIONS_FOLDER | `/functions` | The folder to put your functions for [custom endpoints](./functions.md) |
34
+ | CHADSTART_FILE_PATH | `/chadstart.yaml` | The relative or absolute path of your ChadStart YAML file |
35
+ | TOKEN_SECRET_KEY | `-` | The secret key behind the JWT authentication. Required on production, you can [generate one here](https://jwtsecrets.com/). |
36
+
37
+ ## Database
38
+
39
+ By default ChadStart runs with [SQLite](https://www.sqlite.org/) to enable instant launch with the `npx chadstart` command.
40
+
41
+ We recommend switching to [PostgreSQL](https://www.postgresql.org/) or [MySQL](https://www.mysql.com/) or its alternative [MariaDB](https://mariadb.org/) on production for more robustness and to choose from a large number of managed database providers.
42
+
43
+ | Variable | Default | Description | Applies To |
44
+ | ------------- | ---------------------- | ------------------------------------------------------------------------- | ------------------ |
45
+ | DB_CONNECTION | `sqlite` | Choose `postgres` switching to PostgreSQL or `mysql` for MySQL or MariaDB | All |
46
+ | DB_PATH | `/.chadstart/db.sqlite` | Path of the database. Your server should have access to this path locally | SQLite |
47
+ | DB_HOST | `localhost` | Database host | PostgreSQL / MySQL |
48
+ | DB_PORT | `5432` | Database port | PostgreSQL / MySQL |
49
+ | DB_USERNAME | `postgres` | Database username | PostgreSQL / MySQL |
50
+ | DB_PASSWORD | `postgres` | Database password | PostgreSQL / MySQL |
51
+ | DB_DATABASE | `chadstart` | Database name | PostgreSQL / MySQL |
52
+ | DB_SSL | `false` | Require SSL for DB connection. Set to true if using remote DB. | PostgreSQL / MySQL |
53
+
54
+ ### Example configurations
55
+
56
+ Here are examples of `.env` files for different database connections:
57
+
58
+ === "SQLite"
59
+ ```env
60
+
61
+ DB_CONNECTION=sqlite
62
+
63
+ DB_PATH=/.chadstart/db.sqlite
64
+
65
+ ```
66
+
67
+ === "PostgreSQL"
68
+ ```env
69
+
70
+ DB_CONNECTION=postgres
71
+
72
+ DB_HOST=my-host.com
73
+ DB_USERNAME=owner
74
+ DB_PASSWORD=xxxxx
75
+ DB_DATABASE=my_app
76
+ DB_SSL=true # Required for remote managed DBs, remove if local
77
+
78
+ ```
79
+
80
+ === "MySQL / MariaDB"
81
+ ```env
82
+
83
+ DB_CONNECTION=mysql
84
+
85
+ DB_USERNAME=xxxxx
86
+ DB_PASSWORD=xxxxx
87
+ DB_HOST=my-host.com
88
+ DB_PORT=25060
89
+ DB_DATABASE=my_app
90
+ DB_SSL=true # Required for remote managed DBs, remove if local
91
+
92
+ ```
93
+
94
+ ## Error Reporting
95
+
96
+ ChadStart integrates with [Sentry](https://sentry.io) for automatic exception tracking in production.
97
+
98
+ To enable, set **only** the `SENTRY_DSN` environment variable — the DSN is a secret and must never be placed in the YAML file.
99
+
100
+ ```env
101
+ SENTRY_DSN=https://xxxxx@oXXXXX.ingest.sentry.io/XXXXXXX
102
+ ```
103
+
104
+ Non-sensitive settings can be placed in `chadstart.yaml`:
105
+
106
+ ```yaml
107
+ sentry:
108
+ environment: production # optional — defaults to NODE_ENV
109
+ tracesSampleRate: 0.2 # optional — fraction 0.0–1.0, defaults to 1.0
110
+ debug: false # optional — enable Sentry SDK debug logging
111
+ ```
112
+
113
+ :::tip Self-hosted alternative: Bugsink
114
+ [Bugsink](https://www.bugsink.com) is a lightweight, privacy-first, self-hosted alternative to Sentry that is **fully compatible with the Sentry SDK**. To use it, simply set `SENTRY_DSN` to your Bugsink ingest URL — no other code changes are needed.
115
+ :::
116
+
117
+ ## Integrating ChadStart
118
+
119
+ **ChadStart has been designed to be easily integrated**, providing a simple yet complete backend to any tool. See how it runs on [Stackblitz](https://chadstart.new) for example.
120
+
121
+ The backend fits in an [NPM Package](https://www.npmjs.com/package/chadstart) that you can add to your dependencies simply by running `npm install chadstart`. By default, ChadStart uses [SQLite](https://www.sqlite.org/), the n°1 file-based database. This means it's portable and doesn't require any kind of server to run.
122
+
123
+ If you plan to run ChadStart on a **mounted drive** like most cloud editors do, add the `--mountedDrive` argument to the run command to prevent [watcher errors](https://github.com/remy/nodemon?tab=readme-ov-file#application-isnt-restarting):
124
+
125
+ ```
126
+ npm run start -- --mountedDrive
127
+ ```