Files
rplace/docs/code-standards.md
T
tiennm99andGitHub f59e55a852 refactor(rate-limit): 1 req/sec cooldown, batch up to 2048 (#3)
* refactor(rate-limit): switch to 1 req/sec cooldown, batch size up to 2048

Replace per-pixel credit/token-bucket model with a simple per-user cooldown
(SET NX EX 1). Batch size is now independent of the rate limit and capped
at MAX_BATCH_SIZE = 2048.

- rate-limiter: SET NX EX replaces Lua credit script
- worker: response shape { ok: true } (no credits field)
- client: drop credit state/timer/UserInfo; uploader paces by cooldown
- tests: mock checkRateLimit; integration test exercises SET NX EX
- docs: README, system-architecture, code-standards, deployment-guide

* chore(plans): remove implemented plan directories

rplace-implementation (base build), review-fixes, and
image-importer-enhancements are all shipped. Keep plans/reports/ as
historical code-review and research references.
2026-04-18 10:19:00 +07:00

51 lines
1.7 KiB
Markdown

# Code Standards
## Language & Style
- **JavaScript** (ES modules, no TypeScript)
- **Svelte 5** with runes ($state, $props, $derived, $effect)
- **kebab-case** for JS files, **PascalCase** for Svelte components
- Files under 200 lines
- No semicolons omission — use semicolons consistently
## Project Layout
```
src/
├── worker.js # Worker entry (Hono routes)
├── durable-objects/ # Cloudflare Durable Objects
├── lib/ # Shared libraries (worker + client)
├── client/ # Svelte SPA
│ ├── components/ # Svelte components (PascalCase)
│ ├── main.js # Mount entry
│ └── App.svelte # Root component
└── index.html # Vite entry
```
## Conventions
### Worker (src/worker.js, src/lib/*)
- Functions receive `env` parameter for Cloudflare bindings (Redis credentials, DO bindings)
- No global state — Workers are stateless between requests
- Use `@upstash/redis/cloudflare` (REST-based, not TCP)
- Bitfield operations use builder pattern: `redis.bitfield(key).set().exec()`
### Client (src/client/*)
- Svelte 5 runes only (`$state`, `$props`, `$derived`, `$effect`)
- No stores — pass state via props and callbacks
- Canvas rendering is imperative (OffscreenCanvas + putImageData)
- Touch and mouse handlers coexist on the same canvas element
### Shared (src/lib/constants.js, src/lib/canvas-decoder.js)
- Imported by both worker and client
- Vite tree-shakes worker-only code from client bundle
- Constants are the single source of truth for canvas dimensions, colors, limits
## API Response Format
Success: `{ ok: true }`
Error: `{ error: "error_code", ...details }` with appropriate HTTP status (e.g., `retryAfter` on 429)