# Saturne Framework — Claude Code Reference
Saturne is a shared Dolibarr ERP framework. All modules (Digirisk, DigiQuali, Saturne, etc.) live under `htdocs/custom/{module}/` and inherit from saturne.
---
## 1. Architecture Philosophy
Saturne follows a strict separation of concerns:
- PHP controllers prepare data only
- TPL files render HTML only
- Business logic belongs to `class/`
- Reusable UI belongs to `core/tpl/`
- JavaScript is modular and event-driven
- Styling is component-scoped through `.mod-{module}`
The framework prioritizes:
- maintainability over cleverness
- consistency over flexibility
- backward compatibility with Dolibarr
- reusable patterns shared across all modules
---
## 2. AI Assistant Instructions
When generating code:
- Always reuse existing Saturne patterns before creating new ones
- Prefer extending generic Saturne components over module-specific implementations
- Keep generated diffs minimal
- Preserve existing comments and spacing
- Never reformat unrelated code
- Follow the surrounding file style first
- When uncertain, mimic the nearest reference file
---
## 3. Project Architecture
```
htdocs/custom/saturne/
├── admin/ # Admin config pages
├── class/ # PHP CRUD classes (SaturneObject, ActionsSaturne, …)
├── core/
│ ├── ajax/ # AJAX endpoints
│ ├── tpl/ # Reusable TPL fragments (banner_actions, medias, …)
│ └── triggers/ # Dolibarr event triggers
├── css/scss/ # SCSS source → compiled to css/saturne.min.css
├── js/modules/ # JS feature modules → compiled to js/saturne.min.js
├── lib/ # snake_case PHP utility functions
├── view/ # Generic views (saturne_list.php, saturne_document.php, …)
└── gulpfile.js # Build config (child modules reference gulpfile-shared.js)
```
**Child module entry point** (`{module}.main.inc.php`):
```php
$moduleName = 'DigiQuali';
$moduleNameLowerCase = strtolower($moduleName);
require_once __DIR__ . '/../saturne/saturne.main.inc.php';
```
**Class inheritance**:
```php
class MyObject extends SaturneObject {
public function __construct(DoliDB $db) {
parent::__construct($db, 'mymodule', 'mymodule_object');
}
}
```
---
## 4. Anti-Patterns
Never:
- Put SQL in views
- Put HTML in classes
- Put business logic in TPL
- Use inline CSS or JS
- Call Dolibarr globals directly inside JS
- Duplicate generic components already existing in `saturne/`
- Create module-specific patterns when a shared Saturne pattern exists
### Bad vs Good Examples
**PHP Rendering**
```php
// BAD
echo '';
// GOOD
saturne_header();
```
**JavaScript Event Binding**
```javascript
// BAD
$('.btn').click(function(){});
// GOOD
$(document).on('click', '.btn', handler);
```
---
## 5. PHP Conventions
**Style** — follow [PSR-12](https://www.php-fig.org/psr/psr-12/) for all PHP code (indentation, spacing, naming, braces, etc.).
PSR-12 is enforced via PHPCS — run `phpcs --standard=PSR12`. Config in `.phpcs.xml` at the module root.
**Comments** — place comments on the line **above** the code they document, never inline after it.
Remove obvious comments that only restate what the code does — a good comment explains **why**, not **what**.
**Blank lines** — keep blank lines between logical code sections; they are intentional and improve readability.
**Asset loading** — never use `` or `