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.
The example schema (entities Customer and Invoice)
EntityFieldTypeNotes
CustomercustomerIdUUIDprimary key
CustomercustomerNameStringrequired
CustomercustomerEmailStringunique, required
CustomercustomerBirthdayDateoptional
CustomercustomerActiveBooleanrequired, default true
CustomercustomerGenderStringrequired, default unspecified
CustomercustomerNotesTextoptional
CustomercustomerCreatedAtDateTimerequired, default NOW()
InvoiceinvoiceIdUUIDprimary key
InvoiceinvoiceAmountDecimalrequired
InvoiceinvoiceTaxFloatoptional
InvoiceinvoiceQuantityIntegerrequired, default 1
InvoiceinvoiceStatusEnumrequired, default DRAFT, DRAFT | SENT | PAID
InvoiceinvoiceDueDateDateoptional
InvoiceinvoiceCustomerIdUUIDreferences Customer.customerId, required
InvoiceinvoiceCreatedAtDateTimerequired, 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:

MethodPathDoes
GET/api/customerList customers
GET/api/customer/{id}Get one customer
POST/api/customerCreate 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.

The start of the generated NestJS controller for Customer 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:

Generated by the Spring Boot generator src/main/resources/db/migration/V1__initial_schema.sql
CREATE 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:

DatabaseStacks that generate for it
PostgreSQLSpring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, Laravel, .NET (ASP.NET Core), Go Gin and Express.js
MySQLSpring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, Laravel, .NET (ASP.NET Core), Go Gin and Express.js
MongoDBFastAPI and Express.js
SQLiteSpring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, Laravel, .NET (ASP.NET Core), Go Gin and Express.js
MariaDBSpring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, Laravel, .NET (ASP.NET Core), Go Gin and Express.js
OracleSpring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, .NET (ASP.NET Core) and Express.js
SQL ServerSpring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, .NET (ASP.NET Core), Go Gin and Express.js
Amazon RedshiftSpring Boot, Kotlin Spring Boot, NestJS, FastAPI, Django REST Framework, Laravel, .NET (ASP.NET Core), Go Gin and Express.js

Pick a stack

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.