# What Is the Main Entry Point for the OpenWork Server?

> Discover the main entry point for the OpenWork server. Learn how the CLI script at apps/server/src/bin/openwork-server.ts initializes the HTTP service and starts the server.

- Repository: [Different AI/openwork](https://github.com/different-ai/openwork)
- Tags: how-to-guide
- Published: 2026-08-21

---

**The main entry point for the OpenWork server is the CLI script located at [`apps/server/src/bin/openwork-server.ts`](https://github.com/different-ai/openwork/blob/main/apps/server/src/bin/openwork-server.ts), which imports the core server logic from [`apps/server/src/server.ts`](https://github.com/different-ai/openwork/blob/main/apps/server/src/server.ts) and invokes the `startServer()` function to initialize the HTTP service.**

The `different-ai/openwork` repository organizes its server application as a standalone package within the `apps/server` directory. Understanding this entry point is critical for debugging startup failures, injecting custom middleware, or deploying the server in containerized environments.

## Locating the Entry Point in the Repository

In the monorepo structure, the server components reside under `apps/server`. The **bin** field inside [`apps/server/package.json`](https://github.com/different-ai/openwork/blob/main/apps/server/package.json) registers the executable command:

```json
{
  "name": "@openwork/server",
  "bin": {
    "openwork-server": "dist/bin/openwork-server"
  }
}

```

During development, the **source** file [`apps/server/src/bin/openwork-server.ts`](https://github.com/different-ai/openwork/blob/main/apps/server/src/bin/openwork-server.ts) serves as the actual entry point. This TypeScript file is the first code executed when you run `pnpm dev` or invoke the CLI directly. After compilation, the build pipeline outputs the JavaScript equivalent to `apps/server/dist/bin/openwork-server`, which production installations reference.

## Architectural Flow From CLI to HTTP Service

### The CLI Wrapper ([`openwork-server.ts`](https://github.com/different-ai/openwork/blob/main/openwork-server.ts))

The [`openwork-server.ts`](https://github.com/different-ai/openwork/blob/main/openwork-server.ts) file acts as a lightweight **CLI wrapper**. Its primary responsibilities include parsing command-line arguments, loading the runtime configuration, and bootstrapping the core engine. According to the source code, the script reads a JSON configuration file and passes the parsed object to the initialization routine.

```typescript
// apps/server/src/bin/openwork-server.ts
import { readFile } from "node:fs/promises";
import { startServer } from "../server.js";

async function main() {
  const configPath = process.argv[2] || "./config.json";
  const config = await readFile(configPath, "utf8").then(JSON.parse);
  
  await startServer(config);
}

main().catch((err) => {
  console.error("[openwork-server] fatal startup error:", err);
  process.exit(1);
});

```

This separation of concerns keeps the entry point focused on I/O and process management while delegating server logic to the core module.

### The Core Server Logic ([`server.ts`](https://github.com/different-ai/openwork/blob/main/server.ts))

The heavy lifting occurs in [`apps/server/src/server.ts`](https://github.com/different-ai/openwork/blob/main/apps/server/src/server.ts). The **`startServer(config)`** function defined here creates the HTTP listener, initializes the logger, registers API routes, and attaches any middleware or plugin systems (such as MCP handlers or telemetry). By isolating this logic from the entry point, the codebase remains testable and modular.

## Development and Production Execution Patterns

### Local Development

During development, the package manager executes the TypeScript source directly through `ts-node` or a similar loader. Running the following command from the repository root invokes the entry point:

```bash
pnpm dev

```

This command maps to the `dev` script in [`apps/server/package.json`](https://github.com/different-ai/openwork/blob/main/apps/server/package.json), which targets [`src/bin/openwork-server.ts`](https://github.com/different-ai/openwork/blob/main/src/bin/openwork-server.ts) and enables hot-reloading for rapid iteration.

### Production Deployment

After building the project with `pnpm build`, the entry point is transpiled into JavaScript and emitted to:

```

apps/server/dist/bin/openwork-server

```

In production environments, the `openwork-server` command resolves to this compiled artifact. You can execute it directly or via `npx`:

```bash

# Direct execution

./apps/server/dist/bin/openwork-server --config /etc/openwork/config.json

# Via npx

npx openwork-server --port 8778

```

## Summary

- The **main entry point** is [`apps/server/src/bin/openwork-server.ts`](https://github.com/different-ai/openwork/blob/main/apps/server/src/bin/openwork-server.ts), which serves as the CLI bootstrapper.
- This script loads configuration and delegates to **`startServer()`** in [`apps/server/src/server.ts`](https://github.com/different-ai/openwork/blob/main/apps/server/src/server.ts) to create the HTTP service.
- During development, `pnpm dev` runs the TypeScript source; in production, Node.js executes the compiled file at `apps/server/dist/bin/openwork-server`.
- This architecture decouples process initialization from server logic, facilitating easier testing and deployment.

## Frequently Asked Questions

### What file actually starts the OpenWork server process?

The executable entry point is [`apps/server/src/bin/openwork-server.ts`](https://github.com/different-ai/openwork/blob/main/apps/server/src/bin/openwork-server.ts). When you run the `openwork-server` command, Node.js executes this file, which then initializes the server runtime.

### How does the entry point handle configuration?

The entry point asynchronously reads a JSON configuration file (defaulting to [`./config.json`](https://github.com/different-ai/openwork/blob/main/./config.json)) using `node:fs/promises`. It parses the contents and passes the resulting configuration object to the **`startServer(config)`** function defined in [`apps/server/src/server.ts`](https://github.com/different-ai/openwork/blob/main/apps/server/src/server.ts).

### Can I customize the server startup behavior?

Yes. To modify pre-startup logic—such as adding environment variable validation or custom logging—edit [`apps/server/src/bin/openwork-server.ts`](https://github.com/different-ai/openwork/blob/main/apps/server/src/bin/openwork-server.ts). To change how the server itself initializes routes or middleware, modify [`apps/server/src/server.ts`](https://github.com/different-ai/openwork/blob/main/apps/server/src/server.ts) before the `startServer` function begins listening for connections.

### Where is the compiled binary located after building?

After running `pnpm build`, the compiled entry point is output to `apps/server/dist/bin/openwork-server`. This path is referenced by the `bin` field in [`apps/server/package.json`](https://github.com/different-ai/openwork/blob/main/apps/server/package.json), ensuring that global installations and `npx` calls resolve to the correct production artifact.