Skip to content

MemberJunction CodeGen API

A lightweight Express API server that triggers MemberJunction code generation operations. Provides an HTTP endpoint to initiate the full CodeGen pipeline, generating TypeScript classes, SQL objects, and Angular UI components from database schema metadata.

graph TD
    subgraph "MJCodeGenAPI (This Package)"
        A[Express Server] --> B["/api/run" Endpoint]
        B --> C[RunCodeGenBase]
        A --> D[Server Init]
        D --> E[Config Init]
        D --> F[DataSource Setup]
        A --> G[Class Registration Manifests]
    end

    subgraph "CodeGen Pipeline"
        C --> H[Schema Analysis]
        H --> I[Entity Classes<br/>TypeScript]
        H --> J[SQL Objects<br/>Stored Procs/Views]
        H --> K[Angular Forms<br/>Components]
    end

    subgraph "Data Layer"
        L[SQL Server<br/>MJ Schema]
    end

    F --> L
    C --> L

    style A fill:#2d6a9f,stroke:#1a4971,color:#fff
    style B fill:#2d8659,stroke:#1a5c3a,color:#fff
    style C fill:#7c5295,stroke:#563a6b,color:#fff
    style H fill:#b8762f,stroke:#8a5722,color:#fff
    style I fill:#2d8659,stroke:#1a5c3a,color:#fff
    style J fill:#2d8659,stroke:#1a5c3a,color:#fff
    style K fill:#2d8659,stroke:#1a5c3a,color:#fff

MJCodeGenAPI wraps the @memberjunction/codegen-lib package in a simple Express HTTP server, enabling code generation to be triggered remotely. This is useful for automated workflows and CI/CD pipelines.

The server:

  1. Initializes the MemberJunction configuration and database connection on startup
  2. Loads class registration manifests (pre-built + supplemental)
  3. Exposes a single POST /api/run endpoint that triggers the full CodeGen pipeline
  4. Prevents concurrent execution with a promise-based lock
  • Node.js 18+
  • SQL Server with MemberJunction schema
  • mj.config.cjs configuration file in the repository root
  • Environment variables via .env (optional, loaded with dotenv)

Ensure mj.config.cjs exists in the repository root with database connection settings.

Terminal window
cd packages/MJCodeGenAPI && npm run build
Terminal window
# Production
npm start
# Development with hot reload
npm run dev
# Development with debug port
npm run dev:debug

The server starts on the port configured by ___codeGenAPIPort (default: 3999).

Triggers a full code generation run. Returns immediately if a run is already in progress (only one run at a time).

Request:

POST /api/run HTTP/1.1
Content-Type: application/json

Response: The endpoint runs code generation asynchronously. The server logs progress to stdout.

packages/MJCodeGenAPI/
src/
index.ts # Express server and /api/run handler
config.ts # Port configuration
util.ts # Server initialization and CodeGen setup
generated/ # Class registration manifest
package.json
tsconfig.json

Like MJAPI, MJCodeGenAPI uses dual manifests:

  1. Pre-built manifest (@memberjunction/server-bootstrap-lite/mj-class-registrations): Covers all @memberjunction/* packages
  2. Supplemental manifest (src/generated/class-registrations-manifest.ts): Generated at build time with --exclude-packages @memberjunction
PackagePurpose
@memberjunction/codegen-libCode generation engine
@memberjunction/coreCore MJ functionality
@memberjunction/core-entitiesEntity types
@memberjunction/server-bootstrap-liteLightweight server init with class manifests
@memberjunction/sqlserver-dataproviderDatabase connectivity
@memberjunction/globalClass factory
expressHTTP server framework
dotenvEnvironment variable loading
rxjsObservable patterns for init

ISC