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.
| Area | What is generated | Where in the project |
|---|---|---|
| REST API | Create, read, update and delete endpoints for each entity, under /api/<entity> | src/customer/customer.controller.ts |
| Authentication | Registration 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 |
| RBAC | Role and permission tables, and a permission check on the protected routes | src/auth/guards/rbac.guard.ts |
| Migrations | An initial migration for the schema | src/migrations/1700000000000-InitialSchema.ts, migrations/V1__initial_schema.sql |
| Tests | 18 test files in the example (unit and integration) | src/customer/customer.service.spec.ts |
| Dockerfile | Builds the image and runs the app as a non-root user (uid 10001) | Dockerfile |
| docker-compose | Runs the app with a PostgreSQL database beside it | docker-compose.yml |
| CI pipeline | A GitHub Actions workflow, when you choose it | .github/workflows/ci.yml |
| API description | An OpenAPI description of the API | src/main.ts |
| Health check | A health endpoint | src/health/health.controller.ts |
| Configuration | An .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.
.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 filesReal excerpts
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);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;migrations/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
);DockerfileFROM 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 ./src/customer/customer.service.spec.tsdescribe('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
- Backend generator How Auxen works across all stacks.
- Schema to REST API The example schema and the generated routes.
- Pricing Free to use, with paid plans for credits and the sandbox.
- User guide Step by step, from schema to download.
- Spring Boot generator Java output.
- Kotlin Spring Boot generator Kotlin output.
- FastAPI generator Python output.
- Django REST Framework generator Python output.
- Laravel generator PHP output.
- .NET (ASP.NET Core) generator C# output.
- Go Gin generator Go output.
- Express.js generator TypeScript or JavaScript output.
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.