agentleFS
mikezamayiasmikezamayias/agent-skills/skills/cross-language-safety/SKILL.md

cross-language-safety

Skill1 starsChanged 28 days agoBSD-3-ClauseView on GitHub

Prevents cross-language type mismatches in full-stack apps (Dart/Flutter ↔ JSON ↔ PostgreSQL/PostgREST/Deno). Use when building or auditing APIs, DTOs, sync engines, or any server↔client data flow. Also use when setting up observability (logging, Sentry, analytics) for API communication layers.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never use as Type on server data: Always use safe parsers:

    line 40
  2. Distinctive:

    Add transaction tracing for API calls (request and response parsing as spans)

    line 61
  3. Distinctive:

    When auditing an existing codebase, see references/audit-checklist.md

    line 72

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Cross-Language Type Safety

The Problem

PostgreSQL, PostgREST, Deno, and Dart each serialize types differently:

  • bigint -> deno-postgres returns a JS bigint, which JSON.stringify cannot serialize.
  • bigint -> PostgREST returns a JSON number, which loses precision past 2^53 in JS and on Flutter web.
  • numeric -> deno-postgres returns a string.
  • numeric -> PostgREST returns a JSON number, which Dart decodes as int when it has no fractional digits.
  • boolean → some drivers return 0/1
  • timestamp → format varies by driver config
  • jsonb → may be string or parsed object

Dart's as int? throws TypeError on strings. These bugs are silent — no server error, no 4xx/5xx, just a client-side crash.

Rules

Server Side (API)

  1. Explicitly cast all types before JSON response. Wrap every numeric DB field with Number() in Deno/JS. Never trust the driver's default serialization.
  2. Structured JSON logging on every endpoint:
    • Request: method, path, user_id (from JWT), duration_ms, status_code
    • Error: full stack trace, sanitized request body (no tokens/passwords), user context
    • Propagate X-Request-ID header through the chain
  3. Health endpoint: GET /health that checks DB connection, returns service versions.

Client Side (Flutter/Dart)

  1. Never use as Type on server data. Always use safe parsers:

    // BAD
    final version = json['version'] as int?;
    
    // GOOD
    final version = SafeJson.parseInt(json['version']);
  2. Build a SafeJson utility class:
    • parseInt(dynamic) — handles int, string, double, null
    • parseDouble(dynamic) — handles double, string, int, null
    • parseString(dynamic) — handles string, num, null
    • parseBool(dynamic) — handles bool, int, string, null
    • parseDateTime(dynamic) — handles ISO string, int (epoch), null
  3. Every DTO/model fromJson must use SafeJson, never raw casts.
  4. Sentry integration for API layer:
    • Capture all deserialization failures with full context (endpoint, raw response, expected type)
    • Add transaction tracing for API calls (request and response parsing as spans)
    • Log type coercions as breadcrumbs (when SafeJson converts string→int, etc.)
  5. PostHog events: Track API call success/failure with timing, auth refresh events.

PostgREST Specifics

  1. Know PostgREST type mappings: See references/postgrest-types.md

Audit Checklist

When auditing an existing codebase, see references/audit-checklist.md

For Sub-Agents

Include this in every Flutter task prompt that touches API code:

"Use SafeJson for all server response parsing. Never use as Type on JSON data. Log deserialization anomalies to Sentry."

Sources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.