Overview
The Cajas platform includes comprehensive logging and monitoring capabilities to track admin actions, maintain audit trails, and ensure platform integrity.Admin Logs System
Database Schema
All admin actions are recorded in theadmin_logs table:
/home/daytona/workspace/source/types/supabase.ts:102-124
Table Definition
/home/daytona/workspace/source/supabase/migrations/0000_create_cases_system.sql:25-32
Logged Actions
Case Creation
When an admin creates a case, a log entry is created:/home/daytona/workspace/source/app/actions/create-case.ts:128-132
Log Details:
- admin_id: UUID of the admin who created the case
- action:
'CREATE_CASE' - details: Object containing:
case_id: UUID of the newly created casename: Name of the case
- created_at: Automatic timestamp
Action Types
Current logged actions:| Action | Description | Details Schema |
|---|---|---|
CREATE_CASE | New case created | { case_id: string, name: string } |
UPDATE_CASE: Case properties modifiedDELETE_CASE: Case removedUPDATE_ITEM: Item properties changedGRANT_ADMIN: Admin role grantedREVOKE_ADMIN: Admin role revoked
Row Level Security
Access Policies
Only admins can access audit logs:/home/daytona/workspace/source/supabase/migrations/0000_create_cases_system.sql:64-70
Security Benefits
- Prevents unauthorized access: Regular users cannot view admin logs
- Audit integrity: Only admins can create log entries
- Accountability: Logs cannot be modified or deleted (no UPDATE/DELETE policies)
Querying Audit Logs
Get All Logs
Get Logs by Admin
Get Logs by Action Type
Get Logs with Admin Details
Filter by Date Range
Creating Log Entries
Manual Logging
When implementing new admin features, add logging:Best Practices for Logging
- Log after success: Only log after the action completes successfully
- Include context: Add relevant IDs and metadata to
details - Use consistent naming: Follow the
VERB_NOUNpattern (e.g.,CREATE_CASE,UPDATE_ITEM) - Keep details minimal: Only include necessary information
- Don’t log sensitive data: Avoid passwords, API keys, etc.
Example: Logging a Case Update
Monitoring Dashboard (Future Feature)
A dedicated admin dashboard could display:Recent Activity Feed
Statistics Panel
Action Breakdown Chart
Transaction Monitoring
While not currently implemented in the provided code, the database schema from the migrations includes atransactions table that could be used for monitoring:
/home/daytona/workspace/source/supabase/migrations/20240101000000_init.sql:94-108
Potential Monitoring Queries
Total Revenue Today
Most Popular Cases
User Activity
Provably Fair Game Logs
The platform includes aprovably_fair_games table for transparency:
/home/daytona/workspace/source/supabase/migrations/20240101000000_init.sql:110-127
Benefits for Monitoring
- Verify fairness: Admins can audit game results
- Detect anomalies: Unusual patterns may indicate issues
- User support: Look up specific game results for disputes
Example Queries
Get Game by ID
Verify Game Result
Best Practices
Logging Strategy
- Log all admin actions: Every create, update, delete operation
- Include actor information: Always log
admin_id - Add sufficient context: Resource IDs, names, changed fields
- Timestamp everything: Use automatic
created_attimestamps - Make logs immutable: No UPDATE or DELETE policies on logs
Privacy Considerations
-
Don’t log sensitive data:
- Passwords or password hashes
- API keys or tokens
- Personal user data (unless necessary)
- Financial details beyond amounts
-
Anonymize when possible:
- Use IDs instead of names where appropriate
- Aggregate data for statistics
-
Limit log retention:
- Consider archiving old logs (90+ days)
- Implement automated cleanup policies
Monitoring Access
- Restrict to admins: Use RLS policies
- Audit log access: Log who views audit logs
- Regular reviews: Schedule periodic log reviews
- Alert on suspicious activity: Set up notifications for unusual patterns
Example: Building an Audit Log Viewer
Common Monitoring Queries
Activity Summary
Most Active Admins
Daily Action Trend
Next Steps
- Admin Overview - Learn about admin roles and permissions
- Creating Cases - Understand what actions are logged
- Managing Items - See how item changes should be tracked
