# Cookie-cutter template app

Quickest way to get started with Luxonis ecosystem is to use the template app. This app is a starting point for your own
applications and includes all the necessary components to get you up and running. Apps range from very simple pipelines (e.g.
camera stream) to complex and wide-encompassing (e.g using custom AI models and nodes).

### Install

Get up and running in under 5 minutes:

```bash
# Install core packages
pip install depthai --force-reinstall
# Clone the template app
git clone https://github.com/luxonis/oak-template.git
# Change directory to the template app
cd oak-template
# Install requirements
pip install -r requirements.txt
```

This will download the template / cookie-cutter app to your current directory.

```text
template-app/
├── main.py
├── oakapp.toml
├── requirements.txt
├── media/ # Optional media files
└── utils/ # Optional helper functions
```

### main.py

This is where your main logic resides. The downloaded script will use "Camera + NN + Hub" as a default pipeline. Feel free to swap
it with any of the other examples below if you don't need the NN or Hub functionality.

### DepthAI Examples

If you wish to use a different pipeline, you can find a list of available nodes and their examples

[DepthAI Examples](https://docs.luxonis.com/software-v3/depthai/examples.md)

### oakapp.toml

This is where you define the build process for your container. For template apps, we recommend using the Luxonis base image and
installing Python dependencies from requirements.txt. You can find more information
[here](https://docs.luxonis.com/software-v3/oak-apps/oakctl.md).

```toml
identifier = "custom.oakapp"
app_version = "1.0.0"

prepare_container = [
    { type = "RUN", command = "apt-get update" },
    { type = "RUN", command = "apt-get install -y python3 python3-pip wget git" },
]

prepare_build_container = []

build_steps = ["pip3 install -r /app/requirements.txt --break-system-packages"]

entrypoint = ["bash", "-c", "python3 /app/main.py"]

[base_image]
api_url = "https://registry-1.docker.io"
service = "registry.docker.io"
oauth_url = "https://auth.docker.io/token"
auth_type = "repository"
auth_name = "luxonis/oakapp-base"
image_name = "luxonis/oakapp-base"
image_tag = "1.2.6"
```

### Hub authentication (optional)

If you are working with Luxonis Hub as is the case in the "Camera + NN + HUB (default)" example you will need to authenticate with
Hub API Key. The simplest way to do that safely is to create an .env file in the root folder of the app and insert:

```bash
# content of .env file
DEPTHAI_HUB_API_KEY=<INSERT_YOUR_HUB_APIKEY_HERE>
```

To get the API Key you will first need to create a Luxonis Hub account and then [navigate to team
settings](https://hub.luxonis.com/team-settings?view=page) and click Create API Key button.

This is safe because .env files are automatically ignored by git so there is no danger of uploading your private API Key to a
public repo where everybody can see it. Variables in .env files are set up by the dotenv library, and authentication is then
automatically done with the key stored in the DEPTHAI_HUB_API_KEY environment variable. Please check our [API Key Security - Good
Practices](https://docs.luxonis.com/software-v3/oak-apps/apikey-good-practices.md) page to get to know other examples for safely
passing API Keys to apps.

### Deploy

Now that you have your main.py and oakapp.toml, you can deploy your application in one of these ways:

### Standalone

This is the simplest option. Just run the following command in the same directory as your main.py and oakapp.toml files:

```bash
oakctl app run .
```

This command builds your app into a container and runs it directly on the OAK device, with no host-side app process required.
Results can be viewed with the visualizer webapp at http://<device-ip>:8082.

### Peripheral

This option is for when you want to run your application from your host machine. No containerization is needed in this mode, but
you need a steady connection to the device. To run your application in peripheral mode, run the following command:

```bash
python3 main.py
```

Results can be viewed with the visualizer webapp at http://<host-ip>:8082.

### Next steps

### Continue developing

Follow the tutorials and guides in OAK Apps section to continue developing your app.

[Open OAK Apps overview](https://docs.luxonis.com/software-v3/oak-apps.md)

### Publish the app to Luxonis Hub

Build and publish the app so your team can install it from Hub.

[Go to app publishing](https://docs.luxonis.com/cloud/features/application-management/uploading-applications.md)
