# Creating a Kazana plugin

A kazana plugin is technically not different from an app. Both have a
[Kazana Manifest](../api/kazana-manifest.md) with the same options. In fact
an app can be loaded within another app, the UI then is accessible at
`/kazana/{other app name}`.

Usually plugins are used to bundle logic related to one data report.

## Example: Bookkeeping plugin

Let’s say we have an app that accepts bookkeeping reports from its users.
The reports then get transformed into movement indicators.

So in its simplest form, our bookkeeping plugin would define a transform
script for data reports with `sourceId: 'bookkeeping'`. The Manifest would
look something like this

```js
{
  name: 'bookkeeping',
  transform: {
    bookkeeping: function (server, dataReport, callback) {
      var lines = dataReport.data.split(/\n/)
      var indicators = []
      var matches

      for (var i = 0; i < lines.length; i++) {
        matches = lines[i].match(/^([+-]?[\d\.]+)\s*(.*)$/)
        if (!matches) return callback(new Error('Data could not be parsed'))
        indicators.push({
          type: 'movement',
          amount: parseFloat(matches[1]),
          category: matches[2] || 'not set'
        })
      }
      callback(null, indicators)
    }
  }
}
```

The plugin could then be loaded from my main app with a manifest like this

```js
{
  name: 'bookkeeping',
  plugins: [
    // given the bookkeeping plugin’s npm package name is "my-bookkeeping-plugin"
    require('my-bookkeeping-plugin')
  ]
}
```

That’s it.

Besides the transform script, you can define [schemas](../kazana-manifest.md#schema),
[auditing](../kazana-manifest.md#audit), [events](../kazana-manifest.md#events),
[indices](../kazana-manifest.md#indices), [bootstrapping](../kazana-manifest.md#bootstrap)
and more, what ever makes sense.

It could even define a generic UI for managing bookkeeping reports and to
visualise the indices using the [public](../kazana-manifest.md#public) option.
The UI would then be accessible at `/kazana/bookkeeping`.
