How stoffl6781/perfex-api works
Project Type and Purpose
• This is a PHP-based module for Perfex CRM that exposes a REST-style HTTP API endpoint for creating and updating Leads via POST.
• It hooks into the Perfex CRM core as an installable module—no core code changes are required.
File Structure
• api.php: the module’s entry point for external HTTP calls.
• install.php: handles module installation (registering hooks/routes in Perfex CRM).
• controllers/
• Api.php – processes incoming API requests, delegates to CRM models.
• Settings.php – renders and saves module-level configuration in the CRM admin UI.
• views/settings.php: the HTML/PHP form for configuration in Perfex CRM’s backend.
• language/: locale files (english, german) for internationalizing UI and API responses.
• README.md & LICENSE: project overview and license.
README for Additional Insights
• Describes required POST fields, update vs. create logic, and special “block” and “return” query flags.
• Mentions token authentication.
• Explains how custom fields, statuses, sources and assignments are fetched or modified.
Main Components
a. External Client(s)
• Any web application or service sending HTTP POSTs (with token and lead data).
b. Perfex CRM Module Loader
• install.php registers hooks; routes requests under /modules/perfex-api/api.php -> controllers/Api.
c. API Controller Layer
• Api.php: Authentication check (token), “blockcreatelead” / “blockupdatelead” rules, CRUD logic.
d. Settings Controller & UI
• Settings.php + views/settings.php: Admin user configures API token, defaults, languages.
e. Perfex CRM Core & Models
• Uses existing CRM models (Leads, Staff, Sources, Status, Custom Fields).
f. Database
• MySQL (Perfex CRM schema): leads, staff, sources, statuses, custom_fields, etc.
g. Language Service
• Loads fapi_lang.php and api_lang.php based on CRM locale to localize messages/responses.
Relationships and Data Flows
• External Client → HTTP POST → api.php
• api.php invokes Api controller.
• Api controller authenticates (token), validates payload, decides “create” or “update.”
• Interacts with CRM core models to read/write the leads table and related lookup tables (status, source, staff).
• Returns JSON with success/error codes, optionally data from returnactivefields or returncustomfields calls.
• CRM Admin UI → Settings Controller
• Admin submits API token & module settings via views/settings.php.
• Settings controller persists settings (CRM’s options table).
• Controllers → Language Service
• On each request, loads appropriate fapi_lang.php or api_lang.php for messages.
Architectural Patterns and Principles
• MVC: controllers (Api, Settings), views (settings.php), models (CRM core).
• Single module boundary: api.php & controllers are encapsulated in module folder.
• Hook/Plugin pattern: install.php registers the module with Perfex CRM.
• Separation of concerns: API logic isolated from CRM UI logic.