> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trench.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-host Quickstart

> Get set up with Trench in less than 5 minutes

<Steps>
  <Step title="Deploy Trench">
    The only prerequisite for Trench is a system that has Docker and Docker Compose installed [see installation guide](https://docs.docker.com/compose/install/). We recommend having at least 4GB of RAM and 4 CPU cores for optimal performance if you're running a production environment.

    After installing Docker, you can start the local development server by running the following commands:

    ```sh theme={null}
    git clone https://github.com/frigadehq/trench.git
    cd trench/apps/trench
    cp .env.example .env
    docker-compose -f docker-compose.yml -f docker-compose.dev.yml up --build --force-recreate --renew-anon-volumes
    ```

    The above command will start the Trench server that includes a local ClickHouse and Kafka instance on `http://localhost:4000`. You can update the `.env` to change any of the configuration options.
  </Step>

  <Step title="Send a sample event">
    You can find and update the default public and private API key in the `.env` file. Using your public API key, you can send a sample event to Trench as such:

    ```bash theme={null}
    curl -i -X POST \
       -H "Authorization: Bearer public-d613be4e-di03-4b02-9058-70aa4j04ff28" \
       -H "Content-Type: application/json" \
       -d \
    '{
      "events": [
        {
          "userId": "550e8400-e29b-41d4-a716-446655440000",
          "type": "track",
          "event": "ConnectedAccount",
          "properties": {
            "totalAccounts": 4,
            "country": "Denmark"
          }
        }]
    }' \
     'http://localhost:4000/events'
    ```
  </Step>

  <Step title="Quering events">
    You can query events using the `/events` endpoint (see [API reference](/api-reference/events-get) for more details).

    You can also query events directly from your local Trench server. For example, to query events of type `ConnectedAccount`, you can use the following URL:

    ```bash theme={null}
    curl -i -X GET \
       -H "Authorization: Bearer private-d613be4e-di03-4b02-9058-70aa4j04ff28" \
       'http://localhost:4000/events?event=ConnectedAccount'
    ```

    This will return a JSON response with the event that was just sent:

    ```json theme={null}
    {
      "results": [
        {
          "uuid": "25f7c712-dd86-4db0-89a8-d07d11b73e57",
          "type": "track",
          "event": "ConnectedAccount",
          "userId": "550e8400-e29b-41d4-a716-446655440000",
          "properties": {
            "totalAccounts": 4,
            "country": "Denmark"
          },
          "timestamp": "2024-10-22T19:34:56.000Z",
          "parsedAt": "2024-10-22T19:34:59.530Z"
        }
      ],
      "limit": 1000,
      "offset": 0,
      "total": 1
    }
    ```
  </Step>

  <Step title="Execute raw SQL queries">
    Use the queries endpoint to analyze your data.  Example:

    ```bash theme={null}
    curl -i -X POST \
       -H "Authorization: Bearer private-d613be4e-di03-4b02-9058-70aa4j04ff28" \
       -H "Content-Type: application/json" \
       -d \
    '{
      "queries": [
        "SELECT COUNT(*) FROM events WHERE userId = '550e8400-e29b-41d4-a716-446655440000'"
      ]
    }' \
     'http://localhost:4000/queries'
    ```

    Sample query result:

    ```json theme={null}
    {
      "results": [
        {
          "count": 5
        }
      ],
      "limit": 0,
      "offset": 0,
      "total": 1
    }
    ```
  </Step>
</Steps>

## Going Further

While the above steps are a great starting point, the following video tutorial exemplifies the many things you can do with Trench. In this video, we build a mini version of Google Analytics using Trench and Grafana:

<video controls playsInline className="w-full" src="https://github.com/user-attachments/assets/e3f64590-6e7e-41b9-b425-7adb5a1e19b1" />

## Related Resources

<CardGroup cols={2}>
  <Card title="JavaScript Client →" href="/client" horizontal={true} />

  <Card title="Get Events API →" href="/api-reference/events-get" horizontal={true} />

  <Card title="Create Events API →" href="/api-reference/events-create" horizontal={true} />

  <Card title="Webhooks API →" href="/api-reference/webhooks-create" horizontal={true} />
</CardGroup>
