supabase-backend

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Supabase & Backend Architecture Skill

Supabase 与后端架构技能

This skill enables the assistant to provide high-level architectural advice and implementation details for the iTaxiBcn backend.
本技能可帮助助手为iTaxiBcn后端提供高阶架构建议和实现细节。

Knowledge Areas

知识领域

1. Database Schema Optimization

1. 数据库Schema优化

  • Time-Series Data: Guidelines for handling high-frequency location updates in
    registros_reten
    and
    geofence_logs
    .
  • Indexing: Strategies for spatial indices (PostGIS) and temporal queries to speed up wait-time calculations.
  • Materialized Views: Recommendation for replacing heavy queries on
    registros_reten
    with materialized views for zone aggregations.
  • 时序数据: 处理
    registros_reten
    geofence_logs
    中高频位置更新的指南。
  • 索引: 空间索引(PostGIS)和时序查询的优化策略,用于加快等待时间计算速度。
  • 物化视图: 建议使用物化视图替换对
    registros_reten
    的重查询,用于区域聚合统计。

2. Row Level Security (RLS)

2. 行级安全(RLS)

  • Device-Based Access: Ensuring
    device_id
    based security since the app currently uses device identifiers instead of full user auth (until Phase 2).
  • Audit Logs: Best practices for
    geofence_logs
    and
    location_debug_logs
    security.
  • 基于设备的访问: 确保基于
    device_id
    的安全策略,因为当前应用在第二阶段之前使用设备标识符而非完整的用户认证体系。
  • 审计日志:
    geofence_logs
    location_debug_logs
    的安全最佳实践。

3. Edge Functions (Deno/TypeScript)

3. Edge Functions(Deno/TypeScript)

  • Geofencing Logic: Optimization of the Ray-casting algorithm in
    check-geofence
    .
  • Performance: Minimizing startup time and memory footprint of edge functions.
  • Error Handling: Robust try-catch patterns and standard JSON responses.
  • 地理围栏逻辑: 优化
    check-geofence
    中的光线投射算法。
  • 性能: 最小化边缘函数的启动时间和内存占用。
  • 错误处理: 健壮的try-catch模式和标准JSON响应。

4. SQL Scripting

4. SQL 脚本编写

  • Migrations: Following the
    supabase/migrations/
    structure.
  • Stored Procedures: Writing efficient PL/pgSQL for complex logic like
    useWhereNext
    score calculation on the server side.
  • 数据迁移: 遵循
    supabase/migrations/
    目录结构。
  • 存储过程: 编写高效的PL/pgSQL代码,在服务端实现诸如
    useWhereNext
    分数计算这类复杂逻辑。

Guidelines for Responses

响应指南

  • Always suggest Materialized Views for dashboard metrics that don't need second-by-second accuracy.
  • When writing SQL, ensure idempotency (use
    CREATE OR REPLACE
    or
    IF NOT EXISTS
    ).
  • Prioritize PostGIS functions for distance and polygon math.
  • 对于不需要秒级精度的看板指标,始终建议使用物化视图
  • 编写SQL时要确保幂等性(使用
    CREATE OR REPLACE
    或者
    IF NOT EXISTS
    语法)。
  • 距离和多边形计算优先使用PostGIS函数。