NestJS backend generator: schema to REST API

Auxen, by Auxen Prime, generates a NestJS (TypeScript) backend from your database schema or a plain-English description. The output is an ordinary NestJS project that you download and own. Install with npm and start it with the Nest CLI scripts.

What you get

The table is read from a real generated project (134 files for the example schema). The last column is the file in that project.

AreaWhat is generatedWhere in the project
REST APICreate, read, update and delete endpoints for each entity, under /api/<entity>src/customer/customer.controller.ts
AuthenticationRegistration and login with JWT in this example. The builder also offers OAuth2, Session, API Key, Basic Auth and OpenID Connect.src/auth/auth.controller.ts
RBACRole and permission tables, and a permission check on the protected routessrc/auth/guards/rbac.guard.ts
MigrationsAn initial migration for the schemasrc/migrations/1700000000000-InitialSchema.ts, migrations/V1__initial_schema.sql
Tests18 test files in the example (unit and integration)src/customer/customer.service.spec.ts
DockerfileBuilds the image and runs the app as a non-root user (uid 10001)Dockerfile
docker-composeRuns the app with a PostgreSQL database beside itdocker-compose.yml
CI pipelineA GitHub Actions workflow, when you choose it.github/workflows/ci.yml
API descriptionAn OpenAPI description of the APIsrc/main.ts
Health checkA health endpointsrc/health/health.controller.ts
ConfigurationAn .env.example listing the settings.env.example

The example it was generated from

Entities Customer and Invoice, with Invoice many-to-one Customer, on PostgreSQL, JWT with RBAC. Options: unit tests, integration tests, Docker, GitHub Actions pipeline and migrations. Auxen adds the authentication tables (users, roles, permissions, sessions and others) around them.

Folder layout, with file counts
.github/workflows/  1 file
docs/  2 files
migrations/  1 file
src/  117 files
src/auditLog/  3 files
src/auth/  15 files
src/common/  2 files
src/customer/  11 files
src/health/  2 files
src/invoice/  11 files
src/migrations/  1 file
src/otp/  3 files
src/passwordReset/  3 files
src/permission/  11 files
src/refreshToken/  3 files
src/role/  11 files
src/rolePermission/  11 files
src/session/  3 files
src/user/  11 files
src/userInvite/  3 files
src/userRole/  11 files
test/  4 files
(project root)  9 files

Real excerpts

A generated controller 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 RBAC check src/auth/guards/rbac.guard.ts
@Injectable()
export class RbacGuard implements CanActivate {
  constructor(private reflector: Reflector) {}

  canActivate(context: ExecutionContext): boolean {
    const requiredPermissions = this.reflector.getAllAndOverride<string[]>(PERMISSIONS_KEY, [
      context.getHandler(),
      context.getClass(),
    ]);

    if (!requiredPermissions || requiredPermissions.length === 0) {
      return true;
The first migration, for Customer migrations/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
);
The Dockerfile Dockerfile
FROM node:22-alpine AS build
WORKDIR /app
RUN apk add --no-cache python3 make g++
COPY package*.json .npmrc* ./
RUN npm install
COPY . .
RUN npm run build

FROM node:22-alpine
WORKDIR /app
# Production mode: TypeORM applies the app's migrations at start instead of
# synchronizing the schema from the entities, and errors don't show internals.
ENV NODE_ENV=production
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package.json ./
A generated test src/customer/customer.service.spec.ts
describe('CustomerService', () => {
  let service: CustomerService;
  const repository = {
    findAndCount: jest.fn(),
    findOne: jest.fn(),
    create: jest.fn(),
    save: jest.fn(),
    remove: jest.fn(),
  };
  const id = '00000000-0000-4000-8000-000000000001';
  const row = { customerId: id } as unknown as Customer;

What it is built on

Read from the generated manifest: NestJS (package.json), TypeORM (package.json), Passport JWT (package.json), class-validator (package.json), Swagger (OpenAPI) (package.json), Jest and supertest (package.json).

Databases

NestJS generates for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle and Amazon Redshift. It does not generate for MongoDB.

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 compiles the result with the TypeScript compiler.
  • 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.

Running and deploying it

Install with npm and start it with the Nest CLI scripts. 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.

Review the code before it carries real traffic, as you would any code you did not write. The terms of service say the same: generated code is provided as is, and you are responsible for reviewing, testing and securing it.

More

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.