# Structuring a repository

How to lay out a monorepo so Axle finds the root, the package manager and every package.

Axle uses the same files as your package manager, so a monorepo that works with pnpm, npm, Yarn, Bun, nub or aube already works with Axle.

## A common layout

```text
my-monorepo/
├── apps/
│   ├── web/package.json
│   └── docs/package.json
├── packages/
│   └── ui/package.json
├── package.json
└── pnpm-workspace.yaml
```

## The root

Starting from the folder you run Axle in and walking up, the root is the first folder that has an `aube-workspace.yaml` or a `pnpm-workspace.yaml`, or a `package.json` with a `workspaces` field. If there is none, the nearest folder with a `package.json` is a repository with a single package, and every command works there too. A repository without JavaScript, whose projects come from [plugins](https://axlers.dev/docs/reference/plugins.md) or [`projects`](https://axlers.dev/docs/reference/configuration.md#projects), needs no `package.json`: the outermost folder with an `axle.toml`, up to the top of the Git repository, is its root, and it wins over a `package.json` in a folder below it.

## Which folders are packages

The workspace patterns say where packages live:

- **pnpm:** the `packages` list in `pnpm-workspace.yaml`.
- **aube:** the `packages` list in `aube-workspace.yaml`, or in `pnpm-workspace.yaml`.
- **npm, Yarn and Bun:** the `workspaces` field of the root `package.json`, either a list or an object with a `packages` list.
- **nub:** whichever of these the repository already has.

A folder is a package when it matches a pattern and contains a `package.json`. The [glob patterns](https://axlers.dev/docs/reference/globs.md) page explains `*`, `**` and `!`.

Axle skips `node_modules`, `.git` and everything listed in `.gitignore`. Other hidden folders, such as `.config`, are searched like any other folder.

## The package manager

Axle uses the first of these that it finds in the root `package.json` or folder:

1. the `devEngines.packageManager` field, for example `{ "name": "pnpm", "version": "^12.0.0" }`, or a list of them;
2. the `packageManager` field, for example `"pnpm@12.26.0"`;
3. a lockfile: `aube-lock.yaml`, then `nub.lock`, then `pnpm-lock.yaml`, then `bun.lock` or `bun.lockb`, then `yarn.lock`, then `package-lock.json`;
4. otherwise aube for an `aube-workspace.yaml`, pnpm for a `pnpm-workspace.yaml`, and npm for a `package.json` workspace.

Keep only the lockfile of the package manager you use; Axle [warns](https://axlers.dev/docs/messages/several-lockfiles.md) when it finds more than one.

nub and aube can keep the lockfile of the package manager a repository used before, so name them in `packageManager` or `devEngines.packageManager`, for example `"aube@2.11.3"`: Axle then runs scripts with `nub run` or `aube run` and reads whichever lockfile is there. They write `nub.lock` and `aube-lock.yaml`, which have the shape of `pnpm-lock.yaml`, only in a repository that has no lockfile yet.
