Skip to main content

Overview

@xond/api is the backend engine of the Xond framework. It codifies the patterns we use across Nufaza projects for building secure, type-safe REST services on top of Prisma and Express.

Key capabilities

  • Reverse engineering: point the generator at an existing database to capture tables, relations and views as Prisma models.
  • Code generation: scaffold controllers, repositories, DTO validators and service layers that respect Nufaza coding standards.
  • Authentication & authorization: JWT middleware, role-based helpers and audit logging built in.
  • Data helpers: pagination, sorting, filter builders and query normalization used by our React UI.
  • Extensibility hooks: override lifecycle events (beforeCreate, afterUpdate, etc.) so generated code can stay intact while your domain logic evolves.

What lives here

  • /src/core – shared utilities for repositories, Prisma helpers, error formatting, logging and request contexts.
  • /src/modules – generated modules (controllers, services, DTOs). Custom logic lives alongside generated files, and can be re-generated without overwriting overrides.
  • /prisma – schema files, migrations and seed data that drive both Prisma and the code generation pipeline.

Common tasks

  • Check environment and database
    pnpm --filter your-api-app xond-api check
  • Create database structure
    pnpm --filter your-api-app xond-api create
  • Generate code from Prisma schema
    pnpm --filter your-api-app xond-api generate
  • Insert dummy data from Excel
    pnpm --filter your-api-app xond-api insert
  • Apply database updates
    pnpm --filter your-api-app xond-api update

Documentation Structure

Database Naming Convention

@xond/api follows a strict naming convention:

  • Database Standard: All database tables and columns use snake_case (lowercase with underscores)
    • Example: user_table, first_name, created_at
  • Reverse Engineering: When reverse engineering from an existing database, Prisma schema will be generated in snake_case format
  • Code Generation: During xond-api generate, field names are automatically converted from snake_case to CamelCase for:
    • Model names (e.g., user_tableUserTable)
    • Field labels and headers (e.g., first_nameFirst Name)
    • TypeScript interfaces and types
  • Relation Names: The xond-api shorten command shortens long relation names that may cause Prisma errors

This convention ensures:

  • Database consistency – All databases follow the same naming standard
  • Developer-friendly code – Generated code uses familiar CamelCase conventions
  • Type safety – Full TypeScript types from database to frontend

Architecture

@xond/api follows a code generation approach:

  1. Design your database schema in snake_case (SQL DDL or visual design tool)
  2. Create the database structure using xond-api create
  3. Reverse engineer Prisma schema from database (yields snake_case)
  4. Shorten relation names if needed using xond-api shorten
  5. Generate REST services and frontend models using xond-api generate (converts to CamelCase)
  6. Customize generated code by adding business logic in separate files

This approach ensures:

  • Type safety – Full TypeScript types from database to frontend
  • Consistency – Same patterns across all projects
  • Maintainability – Regenerate code without losing customizations
  • Speed – Rapid development with minimal boilerplate