Create Your First Repo
This guide walks you through creating repositories in Devux.
Endpoint Repo
Use when data operations are specific to one endpoint.
Steps
- Run
pnpm devux - Select "Endpoints"
- Select "Manage dependencies"
- Choose the endpoint
- Select "Add endpoint repo"
- Enter repo name (kebab-case)
Result
apps/backend/src/domains/customers/endpoints/create-customer/repos/create-customer/
├── create-customer.repo.ts ← Your repo logic
└── tests/
└── create-customer.repo.test.tsDomain Repo
Use when multiple endpoints need the same data operations.
Steps
- Run
pnpm devux - Select "Domain Repos"
- Select "Create"
- Choose the target domain
- Enter repo name (kebab-case)
Result
apps/backend/src/domains/customers/repos/get-customer-by-email/
├── get-customer-by-email.repo.ts
└── tests/
└── get-customer-by-email.repo.test.tsUsing Kysely
All repos have access to the type-safe database client:
In transactional repos:
typescript
protected override async _execute(input: Input): Promise<Output> {
const customer = await this.trx // Transaction connection
.selectFrom('customers')
.where('id', '=', input.id)
.selectAll()
.executeTakeFirst();
return { success: true, data: customer };
}In non-transactional repos:
typescript
protected override async _execute(input: Input): Promise<Output> {
const customer = await this.db // Connection pool
.selectFrom('customers')
.where('id', '=', input.id)
.selectAll()
.executeTakeFirst();
return { success: true, data: customer };
}