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

# Code style

> The rules GAIA code follows, the tools that enforce them, and where the full rules live.

Most style is enforced by tools, so you rarely need to remember it: the commit hooks and CI run them for you. This page is the summary. The full rules live in the `CLAUDE.md` file of each area, and those files win if anything here disagrees:

| Area | Full rules |
| - | - |
| Everywhere | `CLAUDE.md` and `.claude/rules/general.md` at the repository root |
| API (Python) | `apps/api/CLAUDE.md` |
| Web (TypeScript, React) | `apps/web/CLAUDE.md`, plus the [design system](https://docs.heygaia.io/design-system.md) |
| Bots | `apps/bots/CLAUDE.md` |
| Tests | `apps/api/tests/CLAUDE.md` |

## Across the codebase

* **Search before you build.** Before writing a helper, type, hook or service, look for one that already exists. Shared code goes in `libs/shared/py` or `libs/shared/ts`, never copied between apps.
* **Fail loudly.** Don't swallow errors with a broad `except` or a silent default. Let them reach a place that can handle them.
* **No magic values.** A literal that means something becomes a named constant, grouped by domain (for example `app/constants/` in the API).
* **Organise by feature.** A feature keeps its components, hooks, types and API calls together.
* **Delete what you replace.** No commented-out code, no unused imports, no old versions left "just in case".
* **Comments say why, not what.** Names explain what the code does. A comment is one line of reasoning at the point of surprise.

## Python

* [Ruff](https://docs.astral.sh/ruff/) lints and formats, [mypy](https://mypy-lang.org) checks types. Run `mise run lint:py` and `mise run type-check`.
* Every function has full type annotations. Don't add `Any` or bare `dict`/`list` to a file that has none.
* Imports go at the top of the file, never inside a function.
* A docstring is one imperative summary line, plus only what the signature doesn't already say. No `Args:` entry that repeats a parameter's name or type.
* **Routes are thin**: record what the request is about with `log.set(...)`, call a service, return a Pydantic model. **Services** are plain async functions, not classes, and reach MongoDB only through a repository in `app/db/repositories/`.

```python theme={null}
async def get_todo(todo_id: str, user_id: str) -> TodoDocument | None:
    """Return the user's todo, or None when it doesn't exist."""
    return await todo_repository.get(todo_id, user_id=user_id)
```

## TypeScript

* [Biome](https://biomejs.dev) lints and formats instead of ESLint and Prettier. Run `mise run lint`, or `mise run lint:fix` to fix and sort imports.
* Never use `any`. Imports go at the top of the file.
* API request and response types come from `@gaia/shared/api/generated`, which is generated from the API. Never write a type that copies an API model by hand. After changing an API route or model, run `mise run api:types`.
* UI primitives come from [HeroUI](https://www.heroui.com): `<Button>`, `<Input>`, `<Modal>` and so on, never a raw `<button>` or a home-made spinner. Icons come from `@icons`, never Unicode symbols such as arrows or check marks.
* Global state uses [Zustand](https://zustand.docs.pmnd.rs) stores.

## Commits

Commit messages and pull request titles follow [Conventional Commits](https://docs.heygaia.io/configuration/conventional-commits.md).

## Next

> [card] [Commit messages](https://docs.heygaia.io/configuration/conventional-commits.md)
>
> The format, the allowed types and examples.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.