> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Get started with the Moose Stack - a code-first approach to building on top of ClickHouse with type-safe schemas and local development

# Developing on ClickHouse with Moose OLAP

export const CommunityMaintainedBadge = () => {
  return <div className="CommunityMaintainedBadge">
            <div className="CommunityMaintainedIcon">
            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 256 256">
                <path d="M244.8,150.4a8,8,0,0,1-11.2-1.6A51.6,51.6,0,0,0,192,128a8,8,0,0,1-7.37-4.89,8,8,0,0,1,0-6.22A8,8,0,0,1,192,112a24,24,0,1,0-23.24-30,8,8,0,1,1-15.5-4A40,40,0,1,1,219,117.51a67.94,67.94,0,0,1,27.43,21.68A8,8,0,0,1,244.8,150.4ZM190.92,212a8,8,0,1,1-13.84,8,57,57,0,0,0-98.16,0,8,8,0,1,1-13.84-8,72.06,72.06,0,0,1,33.74-29.92,48,48,0,1,1,58.36,0A72.06,72.06,0,0,1,190.92,212ZM128,176a32,32,0,1,0-32-32A32,32,0,0,0,128,176ZM72,120a8,8,0,0,0-8-8A24,24,0,1,1,87.24,82a8,8,0,1,0,15.5-4A40,40,0,1,0,37,117.51,67.94,67.94,0,0,0,9.6,139.19a8,8,0,1,0,12.8,9.61A51.6,51.6,0,0,1,64,128,8,8,0,0,0,72,120Z"></path>
            </svg>
        </div>
            Community Maintained
        </div>;
};

[Moose OLAP](https://docs.fiveonefour.com/moosestack/olap) is a core module of the [Moose Stack](https://docs.fiveonefour.com/moosestack), an open source developer toolkit for building real-time analytical backends in Typescript and Python.

Moose OLAP offers developer-friendly abstractions and ORM-like functionality, built natively for ClickHouse.

<h2 id="key-features">
  Key features of Moose OLAP
</h2>

* **Schemas as code**: Define your ClickHouse tables in TypeScript or Python with type safety and IDE autocompletion
* **Type-safe queries**: Write SQL queries with type checking and autocompletion support
* **Local development**: Develop and test against local ClickHouse instances without affecting production
* **Migration management**: Version control your schema changes and manage migrations through code
* **Real-time streaming**: Built-in support for pairing ClickHouse with Kafka or Redpanda for streaming ingest
* **REST APIs**: Easily generate fully documented REST APIs on top of your ClickHouse tables and views

<h2 id="getting-started">
  Getting started in under 5 minutes
</h2>

For the latest and greatest Installation and Getting Started guides, see the [Moose Stack documentation](https://docs.fiveonefour.com/moosestack/getting-started/from-clickhouse).

Or follow this guide to get up and running with Moose OLAP on an existing ClickHouse or ClickHouse Cloud deployment in under 5 minutes.

<h3 id="prerequisites">
  Prerequisites
</h3>

* **Node.js 20+** OR **Python 3.12+** - Required for TypeScript or Python development
* **Docker Desktop** - For local development environment
* **macOS/Linux** - Windows works via WSL2

<Steps>
  <Step>
    <h3 id="step-1-install-moose">
      Install Moose
    </h3>

    Install the Moose CLI globally to your system:

    ```bash theme={null}
    bash -i <(curl -fsSL https://fiveonefour.com/install.sh) moose
    ```
  </Step>

  <Step>
    <h3 id="step-2-set-up-project">
      Set up your project
    </h3>

    <h4 id="option-a-use-own-clickhouse">
      Option A: Use your own existing ClickHouse deployment
    </h4>

    **Important**: Your production ClickHouse will remain untouched. This will just initialize a new Moose OLAP project with data models derived from your ClickHouse tables.

    ```bash theme={null}
    # TypeScript
    moose init my-project --from-remote <YOUR_CLICKHOUSE_CONNECTION_STRING> --language typescript

    # Python
    moose init my-project --from-remote <YOUR_CLICKHOUSE_CONNECTION_STRING> --language python
    ```

    Your ClickHouse connection string should be in this format:

    ```bash theme={null}
    https://username:password@host:port/?database=database_name
    ```

    <h4 id="option-b-use-clickhouse-playground">
      Option B: use ClickHouse playground
    </h4>

    Don't have ClickHouse up and running yet? Use the ClickHouse Playground to try out Moose OLAP!

    ```bash theme={null}
    # TypeScript
    moose init my-project --from-remote https://explorer:@play.clickhouse.com:443/?database=default --language typescript

    # Python
    moose init my-project --from-remote https://explorer:@play.clickhouse.com:443/?database=default --language python
    ```
  </Step>

  <Step>
    <h3 id="step-3-install-dependencies">
      Install dependencies
    </h3>

    ```bash theme={null}
    # TypeScript
    cd my-project
    npm install

    # Python
    cd my-project
    python3 -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt
    ```

    You should see: `Successfully generated X models from ClickHouse tables`
  </Step>

  <Step>
    <h3 id="step-4-explore-models">
      Explore your generated models
    </h3>

    The Moose CLI automatically generates TypeScript interfaces or Python Pydantic models from your existing ClickHouse tables.

    Check out your new data models in the `app/index.ts` file.
  </Step>

  <Step>
    <h3 id="step-5-start-development">
      Start development
    </h3>

    Start your dev server to spin up a local ClickHouse instance with all your production tables automatically reproduced from your code definitions:

    ```bash theme={null}
    moose dev
    ```

    **Important**: Your production ClickHouse will remain untouched. This creates a local development environment.
  </Step>

  <Step>
    <h3 id="step-6-seed-database">
      Seed your local database
    </h3>

    Seed your data into your local ClickHouse instance:

    <h4 id="from-own-clickhouse">
      From your own ClickHouse
    </h4>

    ```bash theme={null}
    moose seed --connection-string <YOUR_CLICKHOUSE_CONNECTION_STRING> --limit 100
    ```

    <h4 id="from-clickhouse-playground">
      From ClickHouse playground
    </h4>

    ```bash theme={null}
    moose seed --connection-string https://explorer:@play.clickhouse.com:443/?database=default --limit 100
    ```
  </Step>

  <Step>
    <h3 id="step-7-building-with-moose-olap">
      Building with Moose OLAP
    </h3>

    Now that you have your Tables defined in code, you get the same benefits as ORM data models in web apps - type safety and autocomplete when building APIs and Materialized Views on top of your analytical data. As a next step, you could try:

    * Building a REST API with [Moose API](https://docs.fiveonefour.com/moosestack/apis)
    * Ingesting or transforming data with [Moose Workflows](https://docs.fiveonefour.com/moosestack/workflows) or [Moose Streaming](https://docs.fiveonefour.com/moosestack/workflows)
    * Explore going to production with [Moose Build](https://docs.fiveonefour.com/moosestack/deploying) and [Moose Migrate](https://docs.fiveonefour.com/moosestack/migrate)
  </Step>
</Steps>

<h2 id="get-help-stay-connected">
  Get help and stay connected
</h2>

* **Reference Application**: Check out the open source reference application, [Area Code](https://github.com/514-labs/area-code): a starter repo with all the necessary building blocks for a feature-rich, enterprise-ready application that requires specialized infrastructure. There are two sample applications: User Facing Analytics and Operational Data Warehouse.
* **Slack Community**: Connect with the Moose Stack maintainers [on Slack](https://join.slack.com/t/moose-community/shared_invite/zt-2fjh5n3wz-cnOmM9Xe9DYAgQrNu8xKxg) for support and feedback
* **Watch Tutorials**: Video tutorials, demos, and deep-dives into Moose Stack features [on Youtube](https://www.youtube.com/channel/UCmIj6NoAAP7kOSNYk77u4Zw)
* **Contribute**: Check out the code, contribute to the Moose Stack, and report issues [on GitHub](https://github.com/514-labs/moose)
