Skip to main content

Overview

The pb-cli build pipeline orchestrates the entire lifecycle from source code to production-ready artifacts. Understanding this pipeline helps you:
  • Debug build failures
  • Optimize build times
  • Customize the build process
  • Integrate with CI/CD systems
pb-cli is built on top of pkg/scripts, which provides programmatic access to all build operations.

Architecture


Pipeline Stages

1. Mode Selection

File: pkg/scripts/cli.go:51-62 Based on flags, pb-cli selects the appropriate mode:

2. System Validation

File: pkg/scripts/internal/system.go Before any operation, pb-cli validates:
  • Go toolchain: go version (requires 1.19+)
  • Node.js: node --version (requires 16+)
  • npm: npm --version (requires 8+)
  • Git: git --version (for version control)
Failure at this stage aborts the build immediately.

3. Dependency Installation

File: pkg/scripts/internal/deps.go

Go Dependencies

npm Dependencies

npm ci is preferred when package-lock.json exists because it ensures reproducible builds by strictly following the lock file.

4. Frontend Build Process

File: pkg/scripts/internal/build.go

Frontend Type Detection

Build strategy varies by type:

Build Output Detection

5. OpenAPI Spec Generation

File: pkg/scripts/internal/build.go:149-191 Only runs in --build-only and --production modes.

Generation Process

This command:
  1. Parses all // API_SOURCE files using Go AST
  2. Extracts route handlers, request/response types, parameters
  3. Generates versioned OpenAPI 3.0 JSON files
  4. Writes to core/server/api/specs/

Validation Process

Validates:
  • JSON syntax
  • OpenAPI 3.0 schema compliance
  • Route path conflicts
  • Schema reference integrity

Output Structure

In development mode, specs are generated at runtime via AST parsing. Pre-generation is only for production builds where disk files are embedded.

6. Server Execution

File: pkg/scripts/internal/server.go

Development Server

Flags:
  • --dev: Enables developer mode (auto-reload, verbose logging)
  • serve: Starts the HTTP server
Default port: 8090 (configurable via --http flag)

Environment Preparation

7. Production Build

File: pkg/scripts/internal/production.go The most complex pipeline mode.

Build Sequence

Binary Compilation

Optimization Flags:
Trade-off: Smaller binaries, but stack traces and debuggers won’t have symbol information.

Directory Structure

Production build creates:

8. Test Execution

File: pkg/scripts/internal/test.go

Test Discovery

Test Execution

Coverage Generation

Report Formats


Integration with CI/CD

GitHub Actions

GitLab CI


Programmatic Usage

Custom Build Script

Custom Production Pipeline


Performance Optimization

Build Time Benchmarks

Optimization Tips

When modifying only Go code:
Saves ~12s by skipping frontend build.
Always commit package-lock.json to enable:
Saves ~7s in CI environments.
In CI/CD, cache Go modules:
Saves ~13s on cache hit.
If your project has multiple independent frontends:

Debugging Build Failures

Enable Verbose Output

All build operations output to stdout/stderr. Capture for debugging:

Common Failure Points

Symptoms:
Debug:
Common causes:
  • Missing dependencies (run npm install)
  • TypeScript errors (check tsc --noEmit)
  • Build script missing in package.json
Symptoms:
Debug:
Common causes:
  • Syntax errors in handler files
  • Missing // API_SOURCE directive
  • Invalid route registration
Debug endpoint:
Symptoms:
Debug:
Common causes:
  • Missing Go dependencies (run go mod tidy)
  • Import cycle
  • Type mismatch errors

Next Steps

Command Reference

Explore all available commands

pb-cli Overview

Return to pb-cli overview

Deployment

Deploy your production build

CI/CD Integration

Automate builds in CI/CD pipelines