2.7 KiB
2.7 KiB
LASUCA Shared Endpoint – AI Guide
Architecture
- Single PHP micro-endpoint; every request enters
public/index.php, loads config, callsLasuca\SharedEndpoint\fetchLatestItems()fromsrc/Database.php, then JSON-encodes the payload. - No frameworks or Composer setup; stick to core PHP 8+ features already in use (
strict_types, namespaced functions,mysqli). - Output contract is the canonical data feed for multiple dashboards; preserve field names (
status,metadata,items) and the nested keys consumed by clients.
Data access
fetchLatestItems()opens a short-livedmysqliconnection using the array returned byconfig.php; closes connections explicitly after the query.- Query targets the
itemstable ordered byID; schema is assumed to exposeID,Name,Value, andTimestamp. Add columns by extending both theSELECTstatement and the array mapping. - Values are normalised before returning:
tagId→ int,value/rounded1/rounded2→ float,timestampstays as the DB-provided string. Keep these conversions when expanding the payload.
Configuration & caching
config.phpreads environment variables (LASUCA_DB_*,LASUCA_CACHE_TTL) with sensible on-prem defaults; prefer overriding via env vars rather than editing the file.LASUCA_CACHE_TTLcontrols both the config cache and the HTTPCache-Controlheader (currently hard-coded to1second inpublic/index.php). Align these when making caching changes.
Response handling
- Success responses include
metadata.generatedAtas an ISO 8601 (UTC) timestamp viagmdate(DATE_ATOM)andmetadata.countfromcount($items). - Errors are caught in
public/index.php: respond with HTTP 500 and a JSON body{ "status": "error", "message": ... }. Preserve this shape so clients can detect failure without parsing HTML. - Use
JSON_PRETTY_PRINTwhen changing serialization to keep human-readable outputs during troubleshooting.
Local workflows
- Serve locally from the parent directory with
php -S localhost:8081 shared-endpoint/public/index.php; this mimics production routing without extra tooling. - Database connectivity is the only external dependency; mock or stub calls by swapping
fetchLatestItems()for a fixture in tests or by wrapping the function in a seam.
Extension tips
- When adding new endpoints, follow the same pattern: thin public script, shared logic in
src/under theLasuca\SharedEndpointnamespace, and configuration driven by env-aware arrays. - Keep new helpers free of side effects beyond DB reads so downstream caching remains predictable.
- Document any new environment variables in both
config.phpcomments and the top-levelREADME.mdso operators stay in sync.