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

# Project file

> Save a project as JSON text and open it again.

A project file is JSON text. It holds the building, the saved views and the sheets. `saveProject` writes the text and `openProject` reads it.

## Import

```typescript theme={null}
import { saveProject, openProject, ProjectFileError } from '@opengeometry/floorkit';
```

## Example

```typescript theme={null}
import {
  openProject,
  saveProject,
  ProjectFileError,
  type BuildingSession,
  type ProjectFile,
} from '@opengeometry/floorkit';

export function saveCurrent(project: ProjectFile, session: BuildingSession): string {
  return saveProject({ ...project, buildingModel: session.snapshot() });
}

export function readProject(text: string): ProjectFile | undefined {
  try {
    return openProject(text);
  } catch (error) {
    if (error instanceof ProjectFileError) {
      console.error(error.code, error.path, error.message);
      return undefined;
    }
    throw error;
  }
}
```

## Notes

* These functions do not use the disk or the network. Your app stores the text.
* Put `session.snapshot()` into `buildingModel` before you save.
* `openProject` checks the text. A problem throws `ProjectFileError` with a `code` and a `path`.
* The file does not hold geometry, images or undo history. Floorkit builds them again after you open the file.
* Files from earlier versions open.

## saveProject

Validate and serialize one project, upgrading older BuildingModels without changing the input.

```typescript theme={null}
function saveProject(project: ProjectFile): string;
```

## openProject

Parse and validate project JSON without reading from disk or compiling the building.

```typescript theme={null}
function openProject(jsonText: string): ProjectFile;
```

## ProjectFileError

A storage-boundary error with a stable code and a path into the project JSON.

```typescript theme={null}
class ProjectFileError extends Error {
  readonly code: string;
  readonly path: string;
  readonly reason?: unknown;
  constructor(code: string, path: string, message: string, reason?: unknown);
}
```

## Types

### ProjectFile

The durable project envelope.

```typescript theme={null}
interface ProjectFile {
  schema: 'floorkit.project';
  version: 1 | 2 | 3;
  buildingModel: BuildingModel;
  views: SavedDrawingView[];
  paper: PaperDocument;
  markers?: readonly ProjectViewMarker[];
}
```

<ResponseField name="schema" type="'floorkit.project'" required />

<ResponseField name="version" type="1 | 2 | 3" required />

<ResponseField name="buildingModel" type="BuildingModel" required />

<ResponseField name="views" type="SavedDrawingView[]" required>
  Named drawing definitions; each can later be placed on one or more sheets.
</ResponseField>

<ResponseField name="paper" type="PaperDocument" required />

<ResponseField name="markers" type="readonly ProjectViewMarker[]">
  Plan markers refer to saved views; source geometry remains derived. Schema 3.
</ResponseField>

### ProjectViewMarker

Markers belong to a saved plan.

```typescript theme={null}
type ProjectViewMarker =
  | (ViewMarkerBase & {
      kind: 'source';
    })
  | (ViewMarkerBase & {
      kind: 'reference';
      position: [number, number];
      rotationDeg: number;
    });
```

### ViewMarkerBase

The package does not export this type by name.

```typescript theme={null}
interface ViewMarkerBase {
  id: string;
  parentViewId: string;
  target: ViewMarkerTarget;
}
```

### ViewMarkerTarget

A durable saved-view reference.

```typescript theme={null}
interface ViewMarkerTarget {
  viewId: string;
  sheetId?: string;
  viewportId?: string;
}
```

## Related

* [`BuildingModel`](/floorkit/api/architecture/validate-building-model#buildingmodel)
* [`PaperDocument`](/floorkit/api/drawings/sheet-documents#paperdocument)
* [`SavedDrawingView`](/floorkit/api/drawings/sheet-documents#saveddrawingview)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.