# {{name}}

Welcome to the project generated by Kalix code generation tools! The tools have generated a project,
an example Kalix service, and tests. You can modify the project with your own logic. When you
rebuild, the tools will generate implementation and test stubs to accelerate development.

## Prerequisites

No additional tooling is required to develop locally. To package and deploy to Kalix, you will need
the following:

- Docker; see https://docs.docker.com/engine/install/
- Kalix CLI (`kalix`); see https://docs.kalix.io/kalix/install-kalix.html

## Project overview

Take a look at what the tools generated for you:

- The top level directory, `{{name}}`, contains build and packaging configuration, which are
  described in more detail below.
- The `proto` folder contains `protobuf` descriptors written in the
  [Proto3](https://developers.google.com/protocol-buffers/docs/proto3) Protocol Buffers Language.
  The `.proto` files in this folder specify messages describing the external APIs for your service
  as well as the internal data structures.

To understand Kalix services, `protobuf` descriptors, and Entities, see the documentation on
[designing services](https://docs.kalix.io/designing/index.html).

## Developing

This project has a bare-bones service ready for you to adapt and extend. To see the range of
functionality available for you to use with the Kalix JavaScript SDK, see the documentation
[JavaScript section](https://docs.kalix.io/javascript/index.html). After you have modified any
source files, build and the tools will preserve your changes as well as generate stubs for you to
implement.

## Building

To build your project, including generating sources from protobuf, first install dependencies and
then run the provided `build` script:

```
npm install
npm run build
```

## Testing

Running `build` generates basic skeleton unit tests for each method in each service. You will need
to flesh them out with assertions as behavior is implemented. The testing framework used by the
tools is Mocha. You should use Chai for assertions. To execute the tests:

```
npm test
```

These tests leverage the mock entity classes provided by `@kalix-io/testkit`. These classes mimic
the minimal required machinery to execute commands and handle events against a single entity for
simple unit testing. Integration tests, which run a local Kalix development environment, can also be
written using the testkit.

## Running Locally

To run your application locally, you must run the Kalix proxy. The included `docker-compose` file
contains the configuration required to run the proxy for a locally running application. It also
contains the configuration to start a local Google Pub/Sub emulator that the Kalix proxy will
connect to.

To start the proxy, run the following command from this directory:

```
docker-compose up
```

To start the application locally, use the following commands:

> Be sure to have performed `npm install` for the first time!

```
npm run build && npm start
```

With both the proxy and your application running, any defined endpoints should be available at
`http://localhost:9000`. In addition to the defined gRPC interface, each method has a corresponding
HTTP endpoint. Unless configured otherwise (see [Transcoding
HTTP](https://docs.kalix.io/javascript/proto.html#_transcoding_http)), this endpoint accepts POST
requests at the path `/[package].[service name]/[method]`.

For example, using `curl`:

```
> curl -XPOST -H "Content-Type: application/json" localhost:9000/com.example.CounterService/GetCurrentCounter -d '{"counterId": "foo"}'
The command handler for `GetCurrentCounter` is not implemented, yet
```

For example, given [`grpcurl`](https://github.com/fullstorydev/grpcurl):

```
> grpcurl -plaintext -d '{"counterId": "foo"}' localhost:9000 com.example.CounterService/GetCurrentCounter
ERROR:
  Code: Unknown
  Message: The command handler for `GetCurrentCounter` is not implemented, yet
```

> Note: The failure is to be expected if you have not yet provided an implementation of
> `GetCurrentCounter` in your entity.

## Deploying to Kalix

To deploy your service, install the `kalix` CLI as documented in [Setting up a local development
environment](https://docs.kalix.io/getting-started/set-up-development-env.html) and configure a
Docker Registry to upload your docker image to.

You will need to update the `config.dockerImage` property in the `package.json` and refer to
[Configuring registries](https://docs.kalix.io/projects/container-registries.html) for more
information on how to make your docker image available to Kalix.

Finally, you can use the [Kalix Console](https://console.kalix.io) to create a project and then
deploy your service into the project either by using `npm run deploy`, through the `kalix` CLI or
via the web interface. When using `npm run deploy`, npm will also conveniently package and publish
your docker image prior to deployment.
