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)
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
- npm-based Frontend
- Static Files
- No Frontend
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
- Parses all
// API_SOURCEfiles using Go AST - Extracts route handlers, request/response types, parameters
- Generates versioned OpenAPI 3.0 JSON files
- Writes to
core/server/api/specs/
Validation Process
- JSON syntax
- OpenAPI 3.0 schema compliance
- Route path conflicts
- Schema reference integrity
Output Structure
6. Server Execution
File:pkg/scripts/internal/server.go
Development Server
--dev: Enables developer mode (auto-reload, verbose logging)serve: Starts the HTTP server
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
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
- test-summary.txt
- test-report.json
- coverage.html
- coverage-summary.txt
Integration with CI/CD
GitHub Actions
GitLab CI
Programmatic Usage
Custom Build Script
Custom Production Pipeline
Performance Optimization
Build Time Benchmarks
Optimization Tips
Use --run-only for backend changes
Use --run-only for backend changes
When modifying only Go code:Saves ~12s by skipping frontend build.
Leverage npm ci in CI/CD
Leverage npm ci in CI/CD
Always commit Saves ~7s in CI environments.
package-lock.json to enable:Cache Go build artifacts
Cache Go build artifacts
In CI/CD, cache Go modules:Saves ~13s on cache hit.
Parallelize independent builds
Parallelize independent builds
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
npm run build fails
npm run build fails
Symptoms:Debug:Common causes:
- Missing dependencies (run
npm install) - TypeScript errors (check
tsc --noEmit) - Build script missing in
package.json
OpenAPI spec generation fails
OpenAPI spec generation fails
Symptoms:Debug:Common causes:
- Syntax errors in handler files
- Missing
// API_SOURCEdirective - Invalid route registration
Server compilation fails
Server compilation fails
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