# Code Conventions

Match the local style before introducing new patterns.

## Core rules

- No autoloading; include files manually with `require_once` or `include`.
- Controllers are procedural files, not classes.
- Models are static classes.
- Prefer small, local changes over refactors.

## Formatting

- 2-space indentation
- LF line endings
- Final newline required
- Single quotes by default in PHP
- Opening brace on the same line

Run `make pretty` after touching PHP files. Keep any formatter or hook changes.

## Naming

| Item | Convention | Example |
|---|---|---|
| Files | kebab-case with suffix | `account.model.php` |
| Directories | kebab-case | `account-panel/` |
| Classes | PascalCase | `EntitiesModel` |
| Methods/functions | camelCase | `getByUID`, `onlinePlayers`, `sanitizePlainText` |
| Constants | UPPER_SNAKE_CASE | `SOURCE_TYPE` |

## File layout

- Pages: `src/pages/{public|private|admin}/<route>/`
- Models: `src/model/{base|cms|source}/`
- Stream file readers: `src/model/<source>/filesReader/`

Each page is a folder under `src/pages/{public|private|admin}/`:

```
src/pages/{public|private|admin}/{page}/
├── {page}.controller.php   # Logic (loaded first)
├── {page}.view.php        # HTML rendering
└── {page}.js             # Optional client-side JS
```

## Common patterns

- Controllers read request data, call models, and set variables for views.
- Views render directly and may use template helpers.
- Errors are often accumulated as strings and shown by the view.
- Keep new code compatible with the surrounding PHP style instead of forcing modern conventions into older files.

## JavaScript

- Page scripts are usually simple jQuery files with no modules.
- Tooling scripts may use ES modules; match the style already used in that tool.
