import { Callout } from "nextra-theme-docs";
import { Steps } from "nextra-theme-docs";

# Setting up a Dev environment

This is a guide to set up a dev environment for LearnHouse, it will guide you through the installation of the backend and the frontend.

## Prerequisites

- [Docker](https://docs.docker.com/get-docker/)
- [Node.js 21.x](https://nodejs.org/en/download/)
- [pnpm](https://pnpm.io/installation)
- [Python 3.12.x](https://www.python.org/downloads/)
- [Poetry](https://python-poetry.org/docs/)
- macOS, Linux or Windows

## Backend configuration

<Steps>

### Get the repository

```bash copy
git clone https://github.com/learnhouse/learnhouse
```

```shell copy
cd learnhouse
```

### Build & install LearnHouse

<Callout type="warning">
  Make sure your container runtime has at least 4GB of RAM allocated, as default
  settings may vary by tool
</Callout>

This will build & run the backend and the database docker images

```shell copy
docker-compose up -d
```

This will install all the dependencies needed for the backend

- A **Postgres** database
- A **Redis** server
- A **Collaboration** nodejs server
- _A built LearnHouse App\* (Frontend & Backend)_

<Callout type='info'>
You should **ignore** the Built LearnHouse App as it's not needed for the dev environment, in this case it will be useful only for installing learnhouse contents (Roles, Organization, Users in the database)

</Callout>

### Run the backend in dev mode

You'll need to modify the config file to enable the install mode

#### Go to the backend folder

```shell copy
cd apps/api
```

#### Install python dependencies

```shell copy
poetry install
```

#### Run the Backend in Dev mode

```shell copy
poetry run python app.py
```

<Callout type="info">
  To learn more about Configuration options, please refer to the
  [Configuration](/self-hosting/configuration) documentation
</Callout>

#### Check the API

Go to [http://localhost:1338/docs/](http://localhost:1338/docs/)

</Steps>

## Frontend configuration

<Steps>
 
### Init the frontend

Go to the frontend folder

```shell copy
cd apps/web
```

This will install all the dependencies needed for the frontend, and for this you will need [pnpm](https://pnpm.io/).

```shell copy
pnpm i
```

Add an .env file in the frontend folder with the following content

<Callout type="warning">
  Setting MultiOrg to true won't work locally for now, please keep it false
</Callout>

```env filename="apps/web/.env" {1-2} copy
NEXT_PUBLIC_LEARNHOUSE_MULTI_ORG=false
NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG=default
NEXT_PUBLIC_LEARNHOUSE_API_URL=http://localhost:1338/api/v1/
NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL=http://localhost:1338/
NEXT_PUBLIC_LEARNHOUSE_DOMAIN=localhost:3000
NEXT_PUBLIC_LEARNHOUSE_TOP_DOMAIN=localhost
NEXT_PUBLIC_LEARNHOUSE_COLLABORATION_WS_URL=wss://localhost:1998
NEXTAUTH_SECRET="my-very-secret-key" 
NEXTAUTH_URL=http://localhost:3000/
```

<Callout type="info">
  For details on organization hosting, see [Organization
  Hosting Modes](/self-hosting/organization-hosting-modes)
</Callout>

Run the dev environment

```shell copy
pnpm run dev
```

### Congratulations, you're done! 🎉

Visit the app at [http://localhost:3000/](http://localhost:3000/)

</Steps>

## Next Steps

Thanks for contributing to LearnHouse 💟

You'll find here some issues/ features we need help with, feel free to contribute to any of them

- [Help Wanted Issues](https://github.com/learnhouse/learnhouse/labels/help%20wanted)
