api-backend

A set of rules for handling APIs, n8n workflows, Google Sheets, stored data, and user accounts in Keymoji.

In plain words
What is it for?
It is for adding login and account flows, reading or updating Google Sheets, calling webhooks, preparing API data, and showing loading or error states.
Why use it?
It reduces duplicate requests, unsafe account operations, hardcoded service addresses, and unclear error handling.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/chooomedia/keymoji/api-backend
Clone the repo
git clone --depth 1 https://github.com/chooomedia/keymoji

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 660 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00660
Opus 5 $0.00000 $0.00330
Sonnet 5 $0.00000 $0.00132
Haiku 4.5 $0.00000 $0.00066

Measured yesterday against content hash 489d4c988db7, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

api-backend scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/api-backend.mdc · 66 lines

How it starts

The opening of the file, as written. The whole thing — 66 lines — stays where its author put it; the contents beside it link to each section on GitHub.

API, Backend & Storage Patterns

API Calls — Pflichtregeln

  • IMMER cachedFetch / cachedFetchAccount aus utils/apiCache.js
  • KEINE direkten fetch() Calls außer in apiCache.js
  • KEINE doppelten API-Calls — Daten zwischen Komponenten weitergeben
  • IMMER try/catch mit user-freundlichen Error Messages
  • IMMER Loading States
  • secureLoginWithMagicLink() — Login initiieren
  • secureVerifyOTP() / secureVerifyMagicLink() — Code verifizieren
  • Session Validation vor jeder Account-Operation
  • Cross-Tab Communication via BroadcastChannel

Account Management

  • accountStore.js — einziger Ort für Account-Operationen
  • syncAccountData() nach Login/Update aufrufen
  • currentAccount Store = Single Source of Truth
  • Vor jedem API-Call: prepareMetadataForAPI() aus metadataCleaner.ts

n8n / Google Sheets

  • WEBHOOKS aus config/api.js verwenden — nie URLs hardcoden
  • Actions: "get" / "read" = read-only (kein Sheets-Write), "update" / "create" = Upsert
  • Google Sheets Spalten (Top-Level, NICHT in metadata):
    • userId, email, tier, createdAt, lastLogin, profile, dailyUsage, metadata, status
  • metadata JSON enthält: settings, updatedAt, updatedVia, lastSettingsSave
  • profile JSON enthält: name, avatar
  • dailyUsage JSON: { date, used, storyUsed, limit, lastReset }

localStorage / Storage

  • IMMER storageHelpers aus config/storage.js
  • IMMER STORAGE_KEYS Konstanten — nie String-Literals
  • DAILY_USAGE_HISTORY = lokale Chart-History (kein API-Feld!)
  • Quota-Exceeded-Errors immer abfangen

Daily Usage / Chart

  • dailyUsageStore.js — Zähler für heute, API-Sync
  • userDataStore.jspersistDailyUsageToHistory() nach jedem Increment
  • Chart liest aus localStorage.DAILY_USAGE_HISTORY — kein metadata.usageHistory
  • action: "update" sendet dailyUsage als Top-Level Feld, NICHT in metadata

Performance

  • cachedFetch mit TTL für alle API-Calls
  • Debouncing für User Input
  • Lazy Loading für große Komponenten
  • $derived für abgeleitete Werte, $effect für Side Effects

Read the full file on GitHub · 66 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 66 lines · 0 tokens per session scan A 489d4c988db7

Subscribe to this mod's changes

api-backend is a cursor rule published in the GitHub repository chooomedia/keymoji (2 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 660 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.