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

# Architecture

> How it all works under the hood

## Components

* `ldev`: runs the services, stores telemetry in memory, serves the UI and the API.
* `localdevcollector`: an OpenTelemetry Collector built for Localdev. Receives telemetry from the services
  and forwards it to Localdev.
* Guard process: a second copy of `ldev` that stops the services if Localdev dies.

## Data flow

```
your service ---OTLP---> localdevcollector ---[OTLP gRPC]---> ldev (in-memory store) --> UI / API
              :4998 gRPC                    :50000                                  :2345
              :4999 HTTP
```

The collector pipeline for logs, metrics and traces: OTLP receiver → batch processor → OTLP exporter to Localdev.

## Ports

All ports are on localhost.

| Port | Used by | Change it with |
| - | - | - |
| 2345 | The UI and the MCP server (`/mcp`) | `-server` |
| 4998 | The collector, OTLP gRPC | [`collector.receivers.grpc`](https://docs.localdev.build/configuration/introduction#collector) |
| 4999 | The collector, OTLP HTTP | [`collector.receivers.http`](https://docs.localdev.build/configuration/introduction#collector) |
| 50000 | The collector sending to Localdev | `-collector-address` |

To run two instances of Localdev at once, change all four (see [Two instances at once](https://docs.localdev.build/CLI-reference.md#two-instances-at-once)).

## Start-up order

1. Read and validate the Projectfile. Any error stops here.
2. Allocate the store.
3. Bind ports 50000 and 2345 (`-collector-address`, `-server`).
4. Start the guard process.
5. Check that 4998 and 4999 (`collector.receivers`) are free, then start the collector.
6. Start all services.

Services start together. There is no start order, `depends_on` or health check.

## Running services

* Working directory: the directory of the Projectfile.
* Each service gets its own process group, so Localdev can stop everything it spawned (`npm`, `go run`, shells).
* Environment: see [Environment variables](https://docs.localdev.build/configuration/environment-variables.md).
* stdout and stderr go straight to files.
* A service that exits stays down. There is no automatic restart. Restart it from the UI.
* A service that exits on its own shows as **Crashed**, with the reason (`exit status 3`, `signal: killed`). Its **Output** opens on stderr, where a panic or stack trace usually is.

## Files

Localdev writes nothing into your project, except when you save changes from the [environment editor](https://docs.localdev.build/configuration/environment-variables.md#change-variables-while-localdev-runs) to the Projectfile.

Everything else goes to the system's temporary directory (`$TMPDIR`; on macOS, under `/var/folders/…`):

| Path | Contents |
| - | - |
| `$TMPDIR/localdev<random>/<service>-out.log` | The service's stdout |
| `$TMPDIR/localdev<random>/<service>-err.log` | The service's stderr |
| `$TMPDIR/localdev<random>/localdevcollector-out.log` | The collector's log |
| `$TMPDIR/localdevcollector-config<random>` | The generated collector configuration |

* Each run of `ldev` gets a new directory. Localdev prints it at start-up as `Service output:`.
* Only your user can read the files.
* A restarted service appends to its existing files.
* **The files aren't deleted when Localdev exits.** Delete old directories yourself if they pile up.

The UI shows the end of each service's output under **Project → Services → Output**.

## Stopping

* Ctrl-C or SIGTERM: every service's process group gets SIGTERM.
* After 5 seconds, whatever is left gets SIGKILL.
* A second Ctrl-C kills immediately.
* The collector stops last, so telemetry flushed during shutdown still arrives.

## If Localdev is killed

Localdev holds a pipe to the guard. The kernel closes it no matter how Localdev dies (SIGKILL, crash, panic). The
guard then sends SIGTERM to every process group, and SIGKILL after 5 seconds.

## Storage

Telemetry is kept in memory only, and is gone when Localdev stops.

* It's held in three fixed-size ring buffers: logs, metric points and trace spans.
* When a buffer is full, new records overwrite the oldest.
* A trace is dropped whole when its oldest span is overwritten, so traces never show random gaps. A link to a dropped trace shows "This trace has been dropped to make room for newer traces". If that happens often, raise `store.trace_spans`.

| Buffer | Default size | Maximum | Memory |
| - | - | - | - |
| Logs | 30,000 records | 10,000,000 | 128 bytes per record, plus the message and attributes |
| Metric points | 1,000,000 | 100,000,000 | 48 bytes per point: 48 MB, allocated at start-up |
| Trace spans | 50,000 | 10,000,000 | About 1.25 KB per span with 13 attributes: about 60 MB when full |

The defaults hold, for example:

* A 10-hour day of metrics for about 275 series exported every 10 seconds, or about 1,650 series at the SDKs' default of 60 seconds.
* 5,000 requests of 10 spans each.

To change the sizes, use [`store`](https://docs.localdev.build/configuration/introduction#store) in the Projectfile, or the flags and variables in the [CLI reference](https://docs.localdev.build/CLI-reference.md#flags).


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