# Getting started

An app lives in a Gradle project that takes Lithe **0.1.0** from Maven Central, or in the Lithe repository as a module of its build. This page runs an example
first, then walks you through an app of your own.

## Run an example

The wrappers of the [Kotlin toolchain](https://github.com/JetBrains/amper) are in the repository and provide the JDK, so all you need is a shell. Every
command goes through the wrapper at the root: `./kotlin` on Linux and macOS, `.\kotlin.bat` on Windows. The first run downloads the toolchain and a JDK
into the user cache, so grab a coffee.

```shell
git clone https://github.com/Ayfri/lithe.git
cd lithe

# Build the example once, which fetches its libraries
./kotlin build -m todo

# Serve it on http://127.0.0.1:8080 and rebuild on every save
./kotlin run -m devserver -- --module examples/todo

# Or write the production site to build/lithe/todo/dist
./kotlin run -m cli -- examples/todo
```

Which example to open:

- `examples/tasks` is a complete app.
- `examples/todo` is the page the [performance figures](/docs/reference/performance) measure.
- `examples/features/` holds one small app per feature.

`./kotlin test` runs every test, the end to end ones in a headless Chrome when one is installed.

## An app of your own

An app that renders to a static site is a module of the repository: a folder with a `module.yaml`, listed under `modules:` in `project.yaml`. It's a
`kmp/lib` module with the `jvm` and `js` platforms that depends on `runtime`:

```yaml
product:
  type: kmp/lib
  platforms: [jvm, js]

apply:
  - ../../kotlin.module-template.yaml

dependencies:
  - ../../runtime
```

It holds:

- `src/App.lithe`, the root component of the page, without required props. Other `.lithe` and `.kt` files sit anywhere under `src/`, and a file's folder
  under `src/` is its package.
- `resources/index.html`, the page. `{{lithe.app}}` is replaced by the rendered app, and its parent element needs `id="app"`. The other files of
  `resources/` are copied next to the page.

```html
<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>My app</title>
</head>
<body>
<main id="app">{{lithe.app}}</main>
</body>
</html>
```

Now a first component, in `src/App.lithe`:

```html
<script kotlin>
	var name by state("world")
</script>

<h1>Hello {name}</h1>
<input value={::name}>
```

Type in the input and the title follows. That's the whole reactivity story for now.

Build the module once with `./kotlin build -m <module>`, which downloads its libraries into the toolchain cache. Then either serve it with the
[dev server](/docs/sites/dev-server), or build the site with `./kotlin run -m cli -- <module dir>` (see [Static sites](/docs/sites/static-sites)).

## In a Gradle project

A Kotlin Multiplatform project that renders with Compose HTML in the browser, a [Kobweb](/docs/sites/kobweb) site included, compiles its `.lithe` files with
the Gradle plugin `io.github.ayfri.lithe`. The plugin and the libraries come from **Maven Central**. To try the code of the repository instead, this command puts
it in the local Maven repository, which the examples read first:

```shell
./kotlin publish mavenLocal
```

`examples/kobweb` and this site, `examples/website`, are such projects. [Kobweb](/docs/sites/kobweb) has the setup.

## Editors

The language server for `.lithe` files gives you errors as you type, completion, hover, rename and more, in VS Code and IntelliJ IDEA. [Editors](/docs/tooling/editors)
shows how to set it up: install the [VS Code extension](https://marketplace.visualstudio.com/items?itemName=Ayfri.lithe) or the
[IntelliJ plugin](https://plugins.jetbrains.com/plugin/36669-lithe), which bring the server along.
