> For the complete documentation index, see [llms.txt](https://azlicense.gitbook.io/azlicense-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://azlicense.gitbook.io/azlicense-docs/setup.md).

# SETUP

## Prerequisites

* Python 3.12+
* Java 21+ (for plugin development)
* Discord Bot Token

## Quick Start (1 command)

```bash
cd azlicense
pip install -r requirements.txt
cp .env.example .env
# Edit .env — set BOT_TOKEN and ADMIN_DISCORD_IDS, generate signing keys
python run.py
```

That's it. SQLite database (`azlicense.db`) and all tables are auto-created on first run.

## Step by Step

{% stepper %}
{% step %}

## Install Dependencies

```bash
pip install -r requirements.txt
```

{% endstep %}

{% step %}

## Configure Environment

```bash
cp .env.example .env
```

Edit `.env`:

* **`BOT_TOKEN`** — your Discord bot token
* **`ADMIN_DISCORD_IDS`** — your Discord user ID (comma-separated for multiple)
* **`LICENSE_ROLE_ID`** — role ID to auto-assign when a license is created (optional)
* **`SUPPORT_ROLE_ID`** — role ID(s) for support staff who can view but not modify (optional, comma-separated)
* **`SIGNING_PRIVATE_KEY`** / **`SIGNING_PUBLIC_KEY`** — generate below

> PEM keys can be single-line (no newlines) or multi-line. Both formats are handled automatically.
> {% endstep %}

{% step %}

## Generate Signing Keys

```bash
python gen_keys.py
```

Copy the output into `.env` replacing the placeholder `SIGNING_PRIVATE_KEY` and `SIGNING_PUBLIC_KEY` values.
{% endstep %}

{% step %}

## Start

```bash
# Both API + Bot:
python run.py

# Or separately:
python run.py --api-only
python run.py --bot-only

# Or directly:
uvicorn api.main:app --host 0.0.0.0 --port 8000
python -m bot.main
```

The API is at `http://localhost:8000`. Interactive docs at `http://localhost:8000/docs`.
{% endstep %}
{% endstepper %}

## Discord Bot Setup

1. Go to <https://discord.com/developers/applications>
2. Create a new application → Bot section → Reset Token → Copy
3. Set `BOT_TOKEN` in `.env`
4. Invite bot with `applications.commands` scope (OAuth2 → URL Generator)
5. Run the bot — slash commands sync automatically
6. Use `/setup avatar` to set the bot's profile picture from `assets/logo.png`
7. Use `/setup username` to rename the bot to AzLicense

## Roles

* **Admin** — set via `ADMIN_DISCORD_IDS` in `.env`. Full access to all commands.
* **Support** — set via `SUPPORT_ROLE_ID` in `.env`. Can view license/product info and list servers, but cannot create, edit, suspend, or delete anything.
* **License Holder** — automatically receives `LICENSE_ROLE_ID` when a license is created via `/license create`.

## Key Management

The EC SECP256R1 key pair signs offline verification tokens. Generate once, keep the private key secure on your server, and distribute the public key with your plugin's SDK.

## PostgreSQL (Production)

For production, set `DATABASE_URL` in `.env` to a PostgreSQL connection string:

```env
DATABASE_URL=postgresql+asyncpg://user:pass@host:5432/azlicense
```

Then run migrations:

```bash
alembic -c database/alembic.ini upgrade head
```

## Docker

```bash
cd docker
docker-compose up -d
```

## Obfuscation

To obfuscate the source before distribution:

```bash
pip install pyarmor
python build_obfuscated.py
```

Output goes to `obfuscated/`. The `.env` and `.env.example` files are copied as-is (not obfuscated). Ship the entire `obfuscated/` folder alongside `assets/`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://azlicense.gitbook.io/azlicense-docs/setup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
