# PostXL Project Template

This document only provides quick setup instructions for the project.

A detailed documentation can be found in the [docs](./docs) folder!

## Quick Setup

```sh
# Install dependencies, copy `.env.example` files, ...
pnpm run setup

# Overwrite `.env` files.
pnpm run setup -f

# Start the Postgres DB and Keycloak server
docker compose up -d db keycloak

# Create initial migration (required)!
pnpm prisma migrate dev

# Start backend
pnpm run --dir backend/ dev

# Start frontend
pnpm run --dir frontend/ dev
```

### Workspace Set Up

- (Visual Studio Code)[https://code.visualstudio.com/download]
- (Cursor)[https://cursor.sh/]

Prerequisites/software needed:

- (Git)[https://git-scm.com/download/win]
- (Docker)[https://docs.docker.com/docker-for-windows/install/]

#### Installing NodeJS

Use Node Version Manager to download the appropriate NodeJS version.

- (MacOS) [Homebrew](https://formulae.brew.sh/formula/nvm)
- (Windows) [Guide](https://www.freecodecamp.org/news/nvm-for-windows-how-to-download-and-install-node-version-manager-in-windows-10/)

Once you've installed `nvm`, navigate to the root of the repository and run.

```sh
# NVM will automatically detect the Node version from `.nvmrc` file in the root.
nvm install
nvm use
```

> You should run `nvm use` whenever you start developing the product, to make sure the whole team is on the same NodeJS version.

#### Installing pnpm

We are using [pnpm](https://pnpm.io/installation#using-npm) for dependency management. To install all dependencies, navigate to the project root and run the following command:

```sh
npm install -g pnpm
```

```sh
pnpm i
```

#### Setting Up Environment Variables

Create a copy of `.env.example` file called `.env` for every `.env.example` file in the project! If you already ran `pnpm run setup -f` before, this step was included.

#### Migrating the Database

MSM uses Prisma and Prisma ships with a database migration utility. To run and create migrations, use the following command or check the migration [docs](https://www.prisma.io/docs/reference/api-reference/command-reference#prisma-migrate).

```sh
# Apply local migrations or Create a new migration
pnpm prisma migrate dev
```

Note: For E2E tests, we set up a separate database - which you need also need to migrate. Check `/.env` which database is configured for the database migration!

#### Running the project

To start the project run `pnpm dev` in the `backend` folder to start the server, and `pnpm dev` in the `web` folder to start the frontend.

```bash
# backend
pnpm dev

# web
pnpm dev
pnpm storybook:start
```

---

## E2E Testing

See the [E2E Testing](./e2e/README.md) documentation.

---

## Miscellaneous

#### I am getting a Prisma error when starting server

```
Invalid `prisma.config.findFirst()` invocation:


The table `PXL.Config` does not exist in the current database.
```

You need to run `pnpm prisma migrate dev` first to create an initial migration and tables in the database.
