# Coding Standards ## PHP - **Version:** PHP 7.4 (server standard) - **Autoloading:** PSR-4 via Composer - **Namespaces:** Use project-level namespaces (e.g., `DMCall\Core\`, `EmailIntelligence\`) - **Database access:** Always use wrapper classes (`Database.php`, `QueryAdapter.php`), never raw `$db` queries - **MongoDB upserts:** Use `insertOrUpdate()` method, not raw `upsert()` - **Error handling:** Log to file via `error_log()` or `file_put_contents()` to logs directory - **Configuration:** Constants via `define()` in `config.php`, never hardcode credentials - **Timezone:** `Europe/Bucharest` for all date operations ### PHP Patterns Used ```php // Singleton database connections $db = Database::getInstance(); // Config as constants define('MONGODB_HOST', '127.0.0.1'); // Error logging ini_set('error_log', __DIR__ . '/../logs/php_errors.log'); // Fatal error handler register_shutdown_function(function() { ... }); ``` ## JavaScript - **No build step.** Vanilla JS, no frameworks, no npm for frontend - **Libraries via CDN:** marked.js, highlight.js, Chart.js as needed - **DOM manipulation:** Native `document.querySelector()`, no jQuery - **API calls:** Native `fetch()` API - **Module pattern:** Single app object (e.g., `DMCall`, `App`) with methods ## File Organization - Entry points in `public/` - Classes in `src/` - Config in `config/` - Logs in `logs/` (gitignored) - Vendor dependencies via Composer in `vendor/` ## Node.js - Server runs Node.js v10.19 — do not use modern syntax - Do not use `node -c` for JS syntax checks - Puppeteer used for scraping tasks ## Documentation - Every project must have a `PROJECT_OVERVIEW.md` at root - AI-facing context docs should use `CLAUDE.md` or `__databaseDescriptionAI.md` naming - Include calling maps in file headers for complex scripts - Document API endpoints with examples