> For the complete documentation index, see [llms.txt](https://docs.xenoraa.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.xenoraa.com/xenoraa-changelog-and-architecture/key-coding-patterns-and-rules.md).

# Key Coding Patterns & Rules

## Key Coding Patterns & Rules

These rules are enforced across all Xenoraa development.

### Main Controllers

| Controller              | Responsibility                        |
| ----------------------- | ------------------------------------- |
| CrmModuleController.php | ALL CRM2 + Inventory + POS + Settings |
| AccountsController.php  | Finance module                        |
| PosController.php       | POS terminal, sessions, receipts      |
| DashboardController.php | Main tenant dashboard                 |
| EcommerceController.php | Online store, orders, coupons         |
| XenaController.php      | Xena AI chat, streaming SSE           |
| XenaApiController.php   | ChatGPT Actions API                   |

### PostgreSQL Rules

* Use EXTRACT(MONTH FROM col) not MONTH(col)
* Use ::text ILIKE for case-insensitive search
* Use STRING\_AGG not GROUP\_CONCAT
* All queries scoped by user\_id

### PDF Export Rules

* No flexbox or CSS Grid — table-based HTML only
* Font: DejaVu Sans
* Currency: Rs. (not the Unicode symbol)

### Post-Deploy Checklist

```
php artisan view:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
systemctl restart php8.3-fpm
```

### Xena AI Architecture

| Component           | File                                     |
| ------------------- | ---------------------------------------- |
| Tool definitions    | XenaController::getTools()               |
| Tool dispatch       | XenaActionService::dispatch()            |
| Memory system       | XenaMemoryService + xena\_tenant\_memory |
| Daily snapshot      | xena:daily-snapshot Artisan command      |
| ChatGPT Actions API | XenaApiController + xena\_api\_tokens    |
| Credits             | XenaCredit model + xena\_credits table   |

Total Xena AI tools: 166 tools across CRM, Accounts, POS, E-Commerce, Projects, General.


---

# 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://docs.xenoraa.com/xenoraa-changelog-and-architecture/key-coding-patterns-and-rules.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.
