# Where to Find the Core Components of the OfficeCLI Codebase

> Discover the core components of the OfficeCLI codebase. Explore the src/officecli/, sdk/node/, npm/, and src/officecli/Resources/ directories to find server, SDK, distribution, and preview viewer assets.

- Repository: [OfficeAI/OfficeCLI](https://github.com/iofficeai/OfficeCLI)
- Tags: getting-started
- Published: 2026-07-14

---

**The core components of the OfficeCLI codebase are organized into four primary directories: `src/officecli/` for the CLI server and entry points, `sdk/node/` for the programmatic JavaScript SDK, `npm/` for the distribution wrapper, and `src/officecli/Resources/` for the client-side preview viewer.**

The iOfficeAI/OfficeCLI repository separates its architecture into distinct modules that handle command-line execution, programmatic SDK access, and live-preview rendering. Understanding where to find the core components of the OfficeCLI codebase helps developers navigate the server bootstrap logic, integrate the Node SDK, and customize the browser-based viewer.

## CLI Entry Point and Command Handling

The **command-line interface** and server bootstrap logic reside in the `src/officecli/` directory. This folder contains the executable scripts that initialize the application and manage real-time communication channels.

The primary files include:

- **[`src/officecli/index.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/index.js)** – Parses command-line arguments and starts the CLI server
- **[`src/officecli/watch-overlay.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/watch-overlay.js)** – Manages the overlay system for UI decorations
- **[`src/officecli/watch-sse-core.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/watch-sse-core.js)** – Handles Server-Sent Events (SSE) connections for live updates
- **[`src/officecli/preview.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/preview.js)** – Initializes the preview mode and viewer state

When you execute the `officecli` command, the runtime invokes [`src/officecli/index.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/index.js) to bootstrap the server and establish the SSE endpoints that stream document updates to the browser.

## Node SDK and TypeScript Definitions

For developers integrating OfficeCLI programmatically, the **Node SDK** is located in `sdk/node/`. This module exposes a public API that allows external applications to control the CLI without spawning shell processes.

Key files in this directory:

- **[`sdk/node/index.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/sdk/node/index.js)** – Exports the `OfficeCLI` class and main SDK methods
- **[`sdk/node/index.d.ts`](https://github.com/iOfficeAI/OfficeCLI/blob/main/sdk/node/index.d.ts)** – Provides TypeScript type definitions for compile-time safety and IntelliSense
- **[`sdk/node/demo.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/sdk/node/demo.js)** and **[`sdk/node/smoke.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/sdk/node/smoke.js)** – Test and demonstration scripts

The SDK entry point exports a class-based interface that handles server lifecycle management:

```javascript
// Using the Node SDK (imported from sdk/node)
import { OfficeCLI } from "officecli";

const cli = new OfficeCLI();
await cli.start();                     // launches the local server
await cli.open("my-document.docx");    // opens a doc for live preview

```

## NPM Distribution Wrapper

The **`npm/`** directory contains the distribution logic that makes OfficeCLI installable via the npm registry. This wrapper handles platform-specific binary downloads and exposes the CLI as a JavaScript-based binary.

Critical files include:

- **[`npm/officecli.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/npm/officecli.js)** – The npm-exposed binary wrapper that delegates to the native executable
- **[`npm/install.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/npm/install.js)** – Installation script triggered during package setup
- **[`npm/lib/install-binary.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/npm/lib/install-binary.js)** – Logic for downloading the platform-specific binary during installation

When you run `npm install officecli`, the [`install-binary.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/install-binary.js) script detects your operating system and architecture, then downloads the appropriate native binary to your local `node_modules` directory.

## Client-Side Viewer Resources

The **live-preview viewer** resources are stored in `src/officecli/Resources/`. These scripts execute in the browser context to handle real-time document updates, UI overlays, and viewer interactions.

The resource files include:

- **[`src/officecli/Resources/watch-sse-core.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Resources/watch-sse-core.js)** – Core SSE listener that applies DOM patches, manages pagination, and handles scroll synchronization
- **[`src/officecli/Resources/watch-overlay.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Resources/watch-overlay.js)** – UI overlay system that adds decorations, selections, and annotation handling
- **[`src/officecli/Resources/preview.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Resources/preview.js)** – Initializes the preview page and sets up the viewer environment

The client-side code establishes an EventSource connection to receive server updates:

```javascript
// Client-side: how the preview page receives updates
(function () {
  const es = new EventSource("/events");   // watch-sse-core.js creates this
  es.addEventListener("update", e => {
    const msg = JSON.parse(e.data);
    // …DOM patching logic lives in watch-sse-core.js
  });
})();

```

## Summary

- **[`src/officecli/index.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/index.js)** launches the server and parses CLI arguments
- **[`sdk/node/index.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/sdk/node/index.js)** provides the public `OfficeCLI` class for programmatic control
- **[`npm/lib/install-binary.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/npm/lib/install-binary.js)** handles platform-specific binary distribution
- **[`src/officecli/Resources/watch-sse-core.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Resources/watch-sse-core.js)** manages browser-side live updates via SSE
- **[`sdk/node/index.d.ts`](https://github.com/iOfficeAI/OfficeCLI/blob/main/sdk/node/index.d.ts)** supplies TypeScript definitions for the SDK

## Frequently Asked Questions

### Where is the main server entry point located in the OfficeCLI codebase?

The main server entry point is **[`src/officecli/index.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/index.js)**, which parses command-line arguments, initializes the HTTP server, and sets up the SSE endpoints required for live preview functionality.

### How do I programmatically control OfficeCLI from my Node.js application?

Import the SDK from **[`sdk/node/index.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/sdk/node/index.js)**, which exports the `OfficeCLI` class. This allows you to start the server and open documents using `await cli.start()` and `await cli.open("filename.docx")` without spawning shell commands.

### Where can I find the TypeScript definitions for the OfficeCLI SDK?

The TypeScript definitions are located at **[`sdk/node/index.d.ts`](https://github.com/iOfficeAI/OfficeCLI/blob/main/sdk/node/index.d.ts)** in the repository root, providing type safety and IntelliSense support for the `OfficeCLI` class and its methods.

### Which file handles the live preview updates in the browser?

**[`src/officecli/Resources/watch-sse-core.js`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Resources/watch-sse-core.js)** contains the core logic for browser-side updates, establishing the EventSource connection to `/events` and applying DOM patches, pagination adjustments, and scroll management as the document changes on the server.