Skip to content

Commit 7fe451c

Browse files
authored
refactor: use drizzle-typebox for validation schemas (#14)
1 parent 1c2e6c7 commit 7fe451c

File tree

5 files changed

+98
-67
lines changed

5 files changed

+98
-67
lines changed

README.md

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,25 @@ Below are the main routes exposed by the template. See `/docs` for full request/
279279

280280
> Full API documentation available at `/docs` when running.
281281
282+
---
283+
284+
### Adding New Modules
285+
286+
The `posts` module is included as a reference CRUD implementation. Feel free to remove or replace it with your own modules.
287+
288+
To add a new module:
289+
290+
1. Create folder: `src/modules/your-module/`
291+
2. Add `index.ts` (routes), `service.ts` (business logic), and optionally `schema.ts`
292+
3. Register in `src/app.ts`:
293+
294+
```typescript
295+
import { yourModule } from "@modules/your-module";
296+
app.use(yourModule);
297+
```
298+
299+
---
300+
282301
## Customization
283302

284303
This template is designed to be configurable without hiding behavior. Below are common customization points.
@@ -360,6 +379,27 @@ Use the `auth` route option to mark endpoints as protected:
360379
.post("/", async ({ user }) => { ... }, { auth: true })
361380
```
362381

382+
### Validation & Schemas
383+
384+
Uses **drizzle-typebox** to generate validation schemas from Drizzle ORM:
385+
386+
```typescript
387+
// Auto-generated from Drizzle + override validation
388+
export const createPostSchema = createInsertSchema(posts, {
389+
title: t.String({ minLength: 5, maxLength: 50 }),
390+
content: t.String({ minLength: 10 }),
391+
});
392+
393+
// Use in routes (omit auto-generated fields)
394+
body: t.Omit(createPostSchema, ['id', 'authorId', 'createdAt', 'updatedAt'])
395+
```
396+
397+
When you add fields in Drizzle, they auto-include in validation. Only validation rules need manual override.
398+
399+
[Docs](https://elysiajs.com/integrations/drizzle)
400+
401+
---
402+
363403
### Custom Authorization
364404

365405
For additional checks beyond login (e.g., ownership, roles, permissions), add logic in the route handler. The `posts` module shows an ownership check example:
@@ -377,21 +417,6 @@ For additional checks beyond login (e.g., ownership, roles, permissions), add lo
377417
}, { auth: true })
378418
```
379419

380-
### Adding New Modules
381-
382-
The `posts` module is included as a reference CRUD implementation. Feel free to remove or replace it with your own modules.
383-
384-
To add a new module:
385-
386-
1. Create folder: `src/modules/your-module/`
387-
2. Add `index.ts` (routes), `service.ts` (business logic), and optionally `schema.ts`
388-
3. Register in `src/app.ts`:
389-
390-
```typescript
391-
import { yourModule } from "@modules/your-module";
392-
app.use(yourModule);
393-
```
394-
395420
---
396421

397422
## Deployment

0 commit comments

Comments
 (0)