> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reasonos.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples

> Complete, runnable project examples for common use cases with RBS

## Spring Boot application

A complete Java Spring Boot application with tests, linting, and container packaging.

<Tabs>
  <Tab title="WORKSPACE.rbs">
    ```python theme={null}
    load("@rbs//java/toolchain.rbs", "java_toolchain", "java_test_deps")
    load("@rbs//java/dependencies.rbs", "java_repository")

    # Auto-download JDK 17
    java_toolchain(name = "java", version = "17.0.11")

    # Auto-install JUnit 5 for tests
    java_test_deps()

    # Spring Boot dependency
    java_repository(
        name = "spring_boot_web",
        package = "org.springframework.boot:spring-boot-starter-web",
        version = "3.2.2",
    )
    ```
  </Tab>

  <Tab title="BUILD.rbs">
    ```python theme={null}
    load("@rbs//java/rules.rbs", "java_binary", "java_library", "java_test", "java_lint")
    load("@rbs//oci/rules.rbs", "oci_image")

    # Business logic library
    java_library(
        name = "springboot_lib",
        srcs = [
            "src/main/java/com/example/springboot/Application.java",
            "src/main/java/com/example/springboot/GreetingService.java",
            "src/main/java/com/example/springboot/Calculator.java",
        ],
        deps = [
            "@external://org_springframework_boot_spring_boot_starter_web:3.2.2",
        ],
    )

    # Spring Boot application
    java_binary(
        name = "app",
        srcs = [
            "src/main/java/com/example/springboot/Application.java",
            "src/main/java/com/example/springboot/GreetingService.java",
            "src/main/java/com/example/springboot/Calculator.java",
        ],
        main = "com.example.springboot.Application",
        resources = ["src/main/resources/application.properties"],
        deps = [
            "@external://org_springframework_boot_spring_boot_starter_web:3.2.2",
        ],
    )

    # Unit tests — JUnit 5 is auto-included
    java_test(
        name = "greeting_service_test",
        srcs = [
            "src/main/java/com/example/springboot/GreetingService.java",
            "src/test/java/com/example/springboot/GreetingServiceTest.java",
        ],
        deps = [
            "@external://org_springframework_boot_spring_boot_starter_web:3.2.2",
        ],
        args = ["--select-class=com.example.springboot.GreetingServiceTest"],
    )

    # Lint
    java_lint(
        name = "app_lint",
        srcs = glob(["src/main/java/**/*.java"]),
    )

    # Container image
    oci_image(
        name = "image",
        binary = ":app",
        base = "ubuntu:22.04",
        env = {"JAVA_OPTS": "-Djava.awt.headless=true"},
        tag = "springboot-example:latest",
    )
    ```
  </Tab>

  <Tab title="Commands">
    ```bash theme={null}
    rbs build app                # Build the application
    rbs run app                  # Run Spring Boot server
    rbs test greeting_service_test  # Run tests
    rbs build image              # Build container image
    ```
  </Tab>
</Tabs>

***

## Node.js Express API

A Node.js Express server with libraries, development/production configs, and dependencies.

<Tabs>
  <Tab title="WORKSPACE.rbs">
    ```python theme={null}
    load("@rbs//nodejs/toolchain.rbs", "nodejs_toolchain")
    load("@rbs//nodejs/dependencies.rbs", "nodejs_repository")

    nodejs_toolchain(name = "nodejs", version = "20.11.0")

    nodejs_repository(name = "express_repo", package = "express", version = "4.18.2")
    nodejs_repository(name = "cors_repo", package = "cors", version = "2.8.5")
    nodejs_repository(name = "helmet_repo", package = "helmet", version = "7.1.0")
    nodejs_repository(name = "morgan_repo", package = "morgan", version = "1.10.0")
    ```
  </Tab>

  <Tab title="BUILD.rbs">
    ```python theme={null}
    load("@rbs//nodejs/rules.rbs", "nodejs_binary", "nodejs_library")

    nodejs_library(
        name = "routes",
        srcs = ["lib/routes.js", "lib/middleware.js"],
        deps = [":express_repo"],
    )

    nodejs_binary(
        name = "dev_server",
        srcs = ["server.js"],
        main = "server.js",
        deps = [":routes", ":express_repo", ":cors_repo", ":morgan_repo"],
        env = {"NODE_ENV": "development", "PORT": "3000"},
    )

    nodejs_binary(
        name = "prod_server",
        srcs = ["server.js"],
        main = "server.js",
        deps = [":routes", ":express_repo", ":cors_repo", ":helmet_repo", ":morgan_repo"],
        env = {"NODE_ENV": "production", "PORT": "8080"},
    )
    ```
  </Tab>

  <Tab title="Commands">
    ```bash theme={null}
    rbs build dev_server     # Build dev server
    rbs run dev_server       # Start development server
    rbs build prod_server    # Build production server
    ```
  </Tab>
</Tabs>

***

## TypeScript application

TypeScript compilation with Express, OCI container images, and linting.

<Tabs>
  <Tab title="BUILD.rbs">
    ```python theme={null}
    load("@rbs//nodejs/rules.rbs", "nodejs_binary", "nodejs_library")
    load("@rbs//oci/rules.rbs", "oci_image")
    load("@rbs//nodejs/lint.rbs", "nodejs_lint")

    # TypeScript library with compiler options
    nodejs_library(
        name = "utils",
        srcs = ["src/utils/math.ts", "src/utils/string.ts"],
        deps = [":lodash_repo", ":types_lodash_repo"],
        ts_compiler_options = {
            "target": "ES2020",
            "strict": True,
            "declaration": True,
        },
    )

    # TypeScript Express server
    nodejs_binary(
        name = "server",
        srcs = ["src/server.ts"],
        main = "src/server.ts",
        deps = [":utils", ":express_repo", ":types_express_repo"],
        env = {"NODE_ENV": "development", "PORT": "4000"},
        ts_compiler_options = {
            "target": "ES2020",
            "module": "commonjs",
            "strict": True,
        },
    )

    # Container image
    oci_image(
        name = "server_image",
        binary = ":server",
        base = "ubuntu:22.04",
        env = {"NODE_ENV": "production", "PORT": "8080"},
        ports = ["8080/tcp"],
        tag = "ts-server:latest",
    )

    # Lint with Prettier
    nodejs_lint(
        name = "lint",
        srcs = glob(["src/**/*.ts"]),
        linters = ["prettier"],
    )
    ```
  </Tab>

  <Tab title="Commands">
    ```bash theme={null}
    rbs build server         # Compile TypeScript and build
    rbs run server           # Start the Express server
    rbs build server_image   # Build container image
    rbs build lint           # Run linter
    ```
  </Tab>
</Tabs>

***

## Python with test coverage

Python project with library, binary, tests, and enforced coverage thresholds.

<Tabs>
  <Tab title="BUILD.rbs">
    ```python theme={null}
    load("@rbs//python/rules.rbs", "py_binary", "py_library", "py_test")

    py_library(
        name = "calculator",
        srcs = ["src/calculator.py"],
    )

    py_library(
        name = "string_utils",
        srcs = ["src/string_utils.py"],
    )

    py_binary(
        name = "app",
        srcs = ["src/main.py"],
        deps = [":calculator", ":string_utils"],
        main = "src/main.py",
    )

    # Basic test
    py_test(
        name = "calculator_test",
        srcs = ["tests/test_calculator.py"],
        deps = [":calculator"],
    )

    # Test with coverage thresholds — fails if below threshold
    py_test(
        name = "calculator_coverage_test",
        srcs = ["tests/test_calculator.py"],
        deps = [":calculator"],
        min_line_coverage = 85,
        min_branch_coverage = 75,
        min_function_coverage = 80,
    )
    ```
  </Tab>

  <Tab title="Commands">
    ```bash theme={null}
    rbs test calculator_test            # Run tests
    rbs test calculator_coverage_test   # Run with coverage enforcement
    rbs coverage calculator_test        # Generate coverage report
    ```
  </Tab>
</Tabs>

***

## Multi-package workspace

Organize a large project with multiple packages and cross-package dependencies.

```
my-app/
├── WORKSPACE.rbs
├── BUILD.rbs                    # Root orchestration
├── services/
│   ├── api/BUILD.rbs            # API service
│   └── worker/BUILD.rbs         # Background worker
└── libs/
    └── common/BUILD.rbs         # Shared library
```

### Root BUILD.rbs

```python theme={null}
# Orchestrate all services
native.task(
    name = "build_all",
    command = ["echo", "All services built!"],
    deps = ["//services/api:build", "//services/worker:build"],
)

native.task(
    name = "test_all",
    command = ["echo", "All tests passed!"],
    deps = ["//services/api:test", "//services/worker:test"],
)
```

### Build individual packages

```bash theme={null}
# Traditional syntax
rbs build //services/api:build
rbs test //services/worker:test
rbs build //...                   # Build everything

# Natural syntax
rbs build services/api build
rbs test services/worker test
```

***

## CI/CD pipeline

Define a complete CI/CD workflow directly in RBS:

```python theme={null}
# WORKSPACE.rbs
native.ci_workflow(
    name = "main",
    on = {
        "push": {"branches": ["main"]},
        "pull_request": {"branches": ["main"]},
    },
    jobs = {
        "lint": {
            "steps": [{"name": "Lint", "run": "rbs build //...:lint"}],
        },
        "build": {
            "needs": ["lint"],
            "steps": [{"name": "Build", "run": "rbs build //..."}],
        },
        "test": {
            "needs": ["build"],
            "steps": [{"name": "Test", "run": "rbs test //..."}],
        },
        "deploy": {
            "needs": ["test"],
            "if": "github.ref == 'refs/heads/main'",
            "steps": [{"name": "Deploy", "run": "rbs run //deploy:production"}],
        },
    },
)
```

```bash theme={null}
rbs ci run                 # Run all matching workflows
rbs ci run --affected      # Run only on changed packages
rbs ci list                # List defined workflows
```

***

## Infrastructure as Code

Provision cloud resources alongside your application code:

```python theme={null}
# infra.rbs
infra.register_provider(
    name = "aws",
    source = "hashicorp/aws",
    version = "5.31.0",
)

infra.provider_config(
    provider = "aws",
    config = {"region": "us-west-2"},
)

infra.resource(
    name = "web_server",
    type = "aws_instance",
    inputs = {
        "ami": "ami-0c55b159cbfafe1f0",
        "instance_type": "t3.micro",
        "tags": {"Name": "web-server"},
    },
)
```

```bash theme={null}
rbs infra plan //...       # Preview changes
rbs infra apply            # Apply changes
rbs infra show             # Show current state
```
