Supabase Edge Functions
Relevant source files
The following files were used as context for generating this wiki page:
Supabase Edge Functions within the Comply-Quick ecosystem serve as the backend execution layer for time-sensitive, scheduled, and automated compliance tasks. These functions handle the "Autopilot" and "Intelligence" features of the platform, such as daily regulation monitoring, weekly intelligence gathering, and automated regeneration of compliance packages when regulatory environments change.
The system leverages the @supabase/supabase-js and @supabase/ssr libraries to interact with the database, utilizing RLS-scoped clients or service-role clients depending on the required data access level for automated background processes.
Sources: package.json:34-36, src/lib/calendar/service.ts:16-24, src/lib/autopilot/pipeline.ts:5-10
Architecture and Integration
The functions integrate with several core subsystems: the ClauseEngine for document generation, the AI Client for human-readable summaries, and the Calendar Service for task surfacing. While specific implementation files for autopilot-daily and intelligence-weekly were referenced as triggers, the logic they execute is heavily defined in the application's library services.
Logic Flow for Automated Compliance Updates
The following diagram illustrates how the Autopilot pipeline (triggered by Edge Functions) processes regulatory changes to notify users.
The pipeline ensures that nothing is mutated on the live project until the user approves the proposal surfaced in the dashboard.
Sources: src/lib/autopilot/pipeline.ts:63-108, src/app/dashboard/home/CommandCenterView.tsx:210-230
Core Service Components
Calendar and Task Aggregation
The collectPersonalEvents function acts as a primary aggregator for events derived from different data sources. This is essential for Edge Functions that need to populate the user's compliance timeline with scheduled scans or renewal alerts.
| Source Data | Derived Event Type | Logic Description |
|---|---|---|
compliance_tasks | task | Persisted manual or automated tasks. |
subscriptions | renewal | Based on current_period_end from Stripe data. |
scan_monitors | scan | Based on last_scanned_at and weekly intervals. |
compliance_alerts | risk | Unresolved risk alerts raised in the window. |
notifications | regulation | Derived from Autopilot regulation-change alerts. |
Sources: src/lib/calendar/service.ts:143-238
Autopilot Regeneration Pipeline
The buildRegenerationProposal function is a critical component used by background functions to handle regulatory updates. It takes a project snapshot and compares it against current legal requirements.
Sources: src/lib/autopilot/pipeline.ts:63-100
Monitoring and Intelligence Panels
The Supabase Edge Functions provide the data backing for the Intelligence and Autopilot panels found in the Command Center. These panels display status updates and regulatory alerts derived from automated background processes.
Regulatory Alert Severity
Alerts generated by the background functions are categorized by severity to help users prioritize actions:
- Critical: High-priority updates (e.g., GDPR Cookie Consent enforcement).
- Warning: Important amendments (e.g., CCPA consumer rights changes).
- Info: General updates (e.g., LGPD notification rules).
Sources: src/app/dashboard/home/CommandCenterView.tsx:43-70, src/lib/calendar/service.ts:54-57
Data Interaction and Security
Functions typically utilize the createClient helper from @supabase/ssr or supabase-js.
- RLS-Scoped Client: Used when a function is triggered by a user action (e.g., manually starting a scan) to ensure they only see their own data.
- Service-Role Client: Used for automated background tasks (like
autopilot-daily) to query across multiple user accounts for regulatory matches.
Sources: src/lib/calendar/service.ts:59-65, src/lib/calendar/service.ts:162-167
Summary
Supabase Edge Functions in Comply-Quick are the backbone of the "Autopilot" and "Intelligence" features. They facilitate the transition from static document generation to a proactive compliance monitoring system by bridging the ClauseEngine with scheduled background execution and AI-driven summary generation.