# Development Environment Setup

> Set up a local LearnHouse development environment with one CLI command that starts PostgreSQL, Redis, the API, the web app and the collab server.

The LearnHouse CLI sets up and runs the entire development environment with a single command.

## Prerequisites

Make sure you have the following installed before proceeding:

- **Docker** (with Docker Compose v2)
- **Node.js 22+** (to run the CLI with `npx`)
- **[Bun](https://bun.sh/)**: used to install and run the web and collab workspaces
- **[uv](https://docs.astral.sh/uv/)**: used to manage and run the Python API

> Make sure Docker has at least **4GB of RAM** allocated. You can check and adjust this in Docker Desktop under Settings &gt; Resources.

> `npx learnhouse dev` runs `bun install` and `uv sync` to install project dependencies, but it does **not** install `bun` or `uv` themselves. It checks for both and stops with an install link if either is missing.

## Setup Steps

### 1. Clone the Repository and Start Development

```bash
git clone https://github.com/learnhouse/learnhouse && cd learnhouse && npx learnhouse dev
```

That single command handles everything:

- **Checks env files**: if `apps/api/.env`, `apps/web/.env.local` or `apps/collab/.env` lack a required variable, it offers to write development defaults (including matching secrets for the API and the collaboration server).
- **Starts backing services**: PostgreSQL and Redis are launched via Docker Compose. On the first run it asks for the admin email and password.
- **Installs dependencies**: Python dependencies via `uv` and JavaScript dependencies via `bun`, when they are not installed yet.
- **Starts the API**: The FastAPI backend starts on port 1338 with hot reload.
- **Starts the frontend**: The Next.js development server starts with `--turbopack` and hot reload.
- **Starts the collaboration server**: The Hocuspocus collaboration server starts via `tsx watch` on port 4000.

See [Dev Mode](https://docs.learnhouse.app/cli/dev-mode) for the full startup flow, the keyboard controls, and how to run with Enterprise code (`--ee`).

All services are coordinated automatically so you do not need to manage them individually.

## Accessing the Application

Once `npx learnhouse dev` is running, you can access:

| Service | URL |
| --- | --- |
| Frontend | [http://localhost:3000](http://localhost:3000) |
| API | [http://localhost:1338](http://localhost:1338) |
| API Documentation (Swagger) | [http://localhost:1338/docs](http://localhost:1338/docs) |

> The Swagger UI at `/docs` is only available in development mode. Production instances do not expose the interactive API documentation.

## Stopping the Environment

Press `q` or `Ctrl+C` in the terminal where `npx learnhouse dev` is running to stop the API, web and collab servers. The PostgreSQL and Redis containers keep running for the next session. To stop them:

```bash
docker compose -f .learnhouse/docker-compose.dev.yml -p learnhouse-dev down
```

## Troubleshooting

- **Port conflicts**: Make sure ports 3000 (web), 1338 (API), 4000 (collab), 5432 (Postgres), and 6379 (Redis) are not in use by other applications.
- **Docker not running**: Ensure the Docker daemon is started before running `npx learnhouse dev`.
- **Dependency issues**: The CLI only installs dependencies when `node_modules` (web, collab) or `.venv` (API) is missing. After pulling changes that touch dependencies, run `bun install` or `uv sync` yourself, or delete those directories and re-run `npx learnhouse dev`.
- **Lockfile errors in CI**: after changing a `package.json` or `apps/api/pyproject.toml`, run `scripts/lockfiles.sh` to regenerate every lockfile. CI runs `scripts/lockfiles.sh --check`.
