Generate a REST API from a database schema
Give Auxen a schema and it generates the REST API for it: one set of endpoints per entity, the database migration, authentication and tests, as a project you download. This page walks through one real example and shows the generated code.
What you give it
- A plain-English description. Auxen infers entities, fields and relationships, and you review them before any code is written.
- An existing schema in DBML or an Excel file.
- A schema you draw or edit on the visual canvas.
| Entity | Field | Type | Notes |
|---|---|---|---|
| Customer | customerId | UUID | primary key |
| Customer | customerName | String | required |
| Customer | customerEmail | String | unique, required |
| Customer | customerBirthday | Date | optional |
| Customer | customerActive | Boolean | required, default true |
| Customer | customerGender | String | required, default unspecified |
| Customer | customerNotes | Text | optional |
| Customer | customerCreatedAt | DateTime | required, default NOW() |
| Invoice | invoiceId | UUID | primary key |
| Invoice | invoiceAmount | Decimal | required |
| Invoice | invoiceTax | Float | optional |
| Invoice | invoiceQuantity | Integer | required, default 1 |
| Invoice | invoiceStatus | Enum | required, default DRAFT, DRAFT | SENT | PAID |
| Invoice | invoiceDueDate | Date | optional |
| Invoice | invoiceCustomerId | UUID | references Customer.customerId, required |
| Invoice | invoiceCreatedAt | DateTime | required, default NOW() |
Invoice has a required foreign key to Customer, so the relationship is Invoice many-to-one Customer.
The routes it generates
In every stack the example's Customer entity is served under /api/customer, and Invoice under /api/invoice:
| Method | Path | Does |
|---|---|---|
| GET | /api/customer | List customers |
| GET | /api/customer/{id} | Get one customer |
| POST | /api/customer | Create a customer |
| PUT | /api/customer/{id} | Update a customer |
| DELETE | /api/customer/{id} | Delete a customer |
Each route is protected by the authentication the project generates, and by a permission check such as CUSTOMER_READ or CUSTOMER_CREATE. Frameworks write the id placeholder their own way, for example {id} in Spring Boot and :id in Express.
src/customer/customer.controller.ts@Controller('customer')
@UseGuards(JwtAuthGuard, PermissionsGuard)
export class CustomerController {
constructor(private readonly customerService: CustomerService) {}
@Get()
@RequirePermissions('CUSTOMER_READ')
async findAll(
@Query('page') page: number = 1,
@Query('limit') limit: number = 20,
@Query('sortBy') sortBy: string = 'customerId',
@Query('sortOrder') sortOrder: 'ASC' | 'DESC' = 'ASC',
): Promise<PaginatedResult<CustomerEntity>> {
return this.customerService.findAllPaginated(+page, +limit, sortBy, sortOrder);The migration it writes
The schema becomes an initial migration in each project. On PostgreSQL the Customer table starts like this:
src/main/resources/db/migration/V1__initial_schema.sqlCREATE TABLE IF NOT EXISTS "customer" (
customer_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
customer_name VARCHAR(255) NOT NULL,
customer_email VARCHAR(255) UNIQUE NOT NULL,
customer_birthday DATE,
customer_active BOOLEAN NOT NULL,
customer_gender VARCHAR(255) NOT NULL,
customer_notes TEXT,
customer_created_at TIMESTAMP NOT NULL
);Databases
Which stack supports which database is defined once in the generator and read here:
| Database | Stacks that generate for it |
|---|---|
| PostgreSQL | Spring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, Laravel, .NET (ASP.NET Core), Go Gin and Express.js |
| MySQL | Spring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, Laravel, .NET (ASP.NET Core), Go Gin and Express.js |
| MongoDB | FastAPI and Express.js |
| SQLite | Spring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, Laravel, .NET (ASP.NET Core), Go Gin and Express.js |
| MariaDB | Spring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, Laravel, .NET (ASP.NET Core), Go Gin and Express.js |
| Oracle | Spring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, .NET (ASP.NET Core) and Express.js |
| SQL Server | Spring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, .NET (ASP.NET Core), Go Gin and Express.js |
| Amazon Redshift | Spring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, Laravel, .NET (ASP.NET Core), Go Gin and Express.js |
Pick a stack
- Spring Boot generator Java. Real output for this example.
- Kotlin Spring Boot generator Kotlin. Real output for this example.
- NestJS generator TypeScript. Real output for this example.
- FastAPI generator Python. Real output for this example.
- Django REST Framework generator Python. Real output for this example.
- Laravel generator PHP. Real output for this example.
- .NET (ASP.NET Core) generator C#. Real output for this example.
- Go Gin generator Go. Real output for this example.
- Express.js generator TypeScript or JavaScript. Real output for this example.
You download the project and deploy it wherever you run software. Auxen does not deploy the generated backend for you yet. It has a hosted sandbox where you can run the code and try its API before you download it.
How the generator is tested
These checks live in the Auxen repository and run against the generators themselves. They are listed here as what they do, not as a guarantee about every schema you might write.
- Generation test (npm run test:gen): generates this stack for several example schemas, then checks the syntax of the result with Maven, Gradle, the TypeScript compiler, Python, PHP, the dotnet CLI, the Go toolchain and Node.js.
- Runtime test (npm run test:runtime): starts the generated application, connects it to a real database, registers a user, logs in, then creates and lists records over HTTP.
- Security scan: the generated project, including its Dockerfile and CI files, is scanned with Trivy for vulnerabilities, secrets and misconfiguration. The check fails on any secret, and on any high or critical finding that has a fix.
- Docker build test (npm run test:docker, run on demand): builds each stack's own Dockerfile.
About Auxen Prime
Auxen is made by Auxen Prime Technologies Limited and lives at auxenprime.com. It is not affiliated with other companies that use the name Auxen.