Server
Recogito Server is the Supabase-based backend that powers the Recogito platform, providing authentication, data storage, and business logic.
Architecture Overview
Section titled “Architecture Overview”- Supabase PostgreSQL - Primary database
- Row-Level Security (RLS) - Multi-tenant access control
- Database triggers - Automated data management
- Stored procedures - 90+ SQL functions for business logic
- Jest tests - Database operation testing
Database Schema
Section titled “Database Schema”Core Entities
Section titled “Core Entities”Projects
Section titled “Projects”Top-level organizational unit (projects table):
- UUID-based identification
- Creator and updater tracking
- Archive support
- Join/edit permissions (
is_open_join,is_open_edit) - Lock state (
is_locked) - Document view rights configuration
Documents
Section titled “Documents”Files and content (documents table):
- Name and content type
- Bucket-based storage
- IIIF protocol support with metadata
- Privacy controls
- Collection organization
- Revision tracking
Contexts
Section titled “Contexts”Document groupings within projects (contexts table):
- Named organizational units
- Project associations
- Default context support
- Layer context relationships
Layers
Section titled “Layers”Annotation organization (layers table):
- Document-specific layers
- Read-only capability
- Collaborative annotation support
- Group-based access control
- Archive support
Annotations
Section titled “Annotations”Actual annotation data (annotations table):
- UUID identification
- Version tracking (auto-incrementing)
- Layer associations with cascade deletion
- Privacy controls (
is_private) - Archive support
- Creator/updater tracking
Bodies
Section titled “Bodies”Annotation content and payloads (bodies table):
- Linked to annotations
- Stores actual annotation data
- Version tracking
Tagging system (tags table):
- Tag definitions
- Target associations
- Archive support
Organization & Access Control
Section titled “Organization & Access Control”Profiles
Section titled “Profiles”User profiles (profiles table):
- User information
- EULA acceptance tracking
- Organization membership
Organization Groups
Section titled “Organization Groups”Multi-tenant organization structure (organization_groups table):
- Organization-level grouping
- Admin role assignments
Default Groups
Section titled “Default Groups”Role templates (default_groups table):
- Predefined roles: org admin, professor, student, tutor, reader
- Template-based group creation
Groups
Section titled “Groups”Project-specific groups (groups table):
- Project associations
- Admin flags
- Default group indicators
- Member management
Group Users
Section titled “Group Users”Group membership (group_users table):
- User-group relationships
- Membership timestamps
Collaboration Features
Section titled “Collaboration Features”Invites
Section titled “Invites”User invitations (invites table):
- Email-based invitations
- Project associations
- Group assignments
- Acceptance tracking
Join Requests
Section titled “Join Requests”Project join requests (join_requests table):
- User request tracking
- Approval workflow
Notifications
Section titled “Notifications”User notifications (notifications table):
- Event-based notifications
- Read/unread tracking
Advanced Features
Section titled “Advanced Features”Collections
Section titled “Collections”Document collections (collections table):
- Collection organization
- Metadata storage
Policies
Section titled “Policies”Configurable access policies (policies table):
- Fine-grained access control
- Action-based permissions
- Policy assignment to entities
Installed Plugins
Section titled “Installed Plugins”Plugin system (installed_plugins table):
- Plugin management
- Configuration storage
Layer Contexts & Groups
Section titled “Layer Contexts & Groups”Advanced layer organization:
layer_contexts- Layer-context relationshipslayer_groups- Layer-group access control
Security & Permissions
Section titled “Security & Permissions”Row-Level Security (RLS)
Section titled “Row-Level Security (RLS)”All tables protected by RLS policies:
- Multi-tenant data isolation
- User-specific data access
- Group-based permissions
- Policy-driven authorization
Policy System
Section titled “Policy System”Configurable via config.json:
- Table-level policies
- Operation-based access (SELECT, INSERT, UPDATE, DELETE)
- UUID-based policy identification
- Hierarchical permission structure
Permission Check Functions
Section titled “Permission Check Functions”90+ stored procedures including:
check_action_policy_layer_from_contextcheck_action_policy_layer_from_document- Layer, context, and document permission validation
- User role verification
User Role Hierarchy
Section titled “User Role Hierarchy”- Organization Admin - Highest level access
- Group Admin - Project-level administration
- Group Members - Assigned permissions within projects
Database Functions (RPC)
Section titled “Database Functions (RPC)”Project Management
Section titled “Project Management”add_documents_to_project_rpcarchive_project_documents_rpcaccept_join_request_rpc
Context Management
Section titled “Context Management”add_documents_to_context_rpcadd_users_to_context_rpcarchive_context_rpcarchive_context_documents_rpc
Document Management
Section titled “Document Management”archive_document_rpc- Document upload handling
- Collection management
Layer Management
Section titled “Layer Management”add_read_only_layer_rpc- Layer group assignments
- Layer context associations
User Management
Section titled “User Management”add_user_to_org_defaultchange_org_group_membershipanonymize_profileaccept_project_invite
Tag Management
Section titled “Tag Management”archive_tag_definition_rpcarchive_tags_for_target- Tag assignment operations
Database Triggers
Section titled “Database Triggers”Automated data management for:
annotations- Versioning, archivingbodies- Related data updatescollections- Metadata updatescontexts- Cascade operationsdocuments- File operationsgroup_users- Membership changeslayers- Access control updatesnotifications- Event creationprofiles- User onboarding- And more…
Infrastructure
Section titled “Infrastructure”Local Development
Section titled “Local Development”Supabase Stack:
- API server:
localhost:54321 - Database:
localhost:54322 - Studio UI:
localhost:54323 - Email testing (Inbucket):
localhost:54324
Configuration: supabase/config.toml
Docker Compose
Section titled “Docker Compose”Local development environment:
- PostgreSQL database
- Supabase services
- Nginx reverse proxy
- Volume management
Migrations
Section titled “Migrations”150+ database migrations tracking schema evolution:
- Timestamped migration files
- Version-controlled schema changes
- Incremental updates from May 2023 onwards
Seed Data
Section titled “Seed Data”- Default groups and roles
- Test user creation scripts
- Policy population
- Sample data for development
Integration
Section titled “Integration”Client Connection
Section titled “Client Connection”Via Supabase JS client:
- Browser client for client-side operations
- Server client for SSR operations
- Real-time subscriptions
- Storage bucket access
External Services
Section titled “External Services”- IIIF Server - Image serving and manifest handling
- Email - Transactional emails (invites, password resets)
- JWT Authentication - 1-hour token expiry
API Endpoints
Section titled “API Endpoints”Server-side API routes in client:
- User acceptance
- Invitations
- Image handling
- Project operations
Testing
Section titled “Testing”Jest Test Suite
Section titled “Jest Test Suite”Located in jest/ directory:
- Database operation tests
- RLS policy verification
- Function testing
- TypeScript-based test files
Test Configuration
Section titled “Test Configuration”jest.config.ts- Test runner configurationdatabase.types.ts- Type definitions- Test users with different role levels
- Isolated test environment
Configuration
Section titled “Configuration”Environment Variables
Section titled “Environment Variables”SUPABASE_SERVICE_KEY=<service_key>SUPABASE_HOST=http://localhost:54321
# Test usersORG_ADMIN_PW=<password>ORG_ADMIN_GROUP_ID=<uuid>PROFESSOR_PW=<password>PROFESSOR_GROUP_ID=<uuid>STUDENT_PW=<password>STUDENT_GROUP_ID=<uuid>TUTOR_PW=<password>READER_PW=<password>INVITE_PW=<password>Policy Configuration
Section titled “Policy Configuration”config.json - Centralized policy definitions:
- Table-level policies
- Operation permissions
- UUIDs for policy identification
- Version tracking
Development Tools
Section titled “Development Tools”Utility Scripts
Section titled “Utility Scripts”create-default-groups.js- Initialize role groupscreate-test-users.js- Generate test accountstest-email-signup.js- Email verification testingrun_tests.sh- Test runner script
Documentation
Section titled “Documentation”Documentation/local_development.md- Local setup guideDocumentation/manually-updating-recogito-server.md- Update proceduresdocker/useful-commands.md- Docker operationsdocker/nginx-install.md- Nginx configuration
OpenAPI Specification
Section titled “OpenAPI Specification”docker/openapi.yaml - API documentation
Database Design Patterns
Section titled “Database Design Patterns”Soft Deletes
Section titled “Soft Deletes”Archive columns instead of hard deletes:
is_archivedboolean on most tables- Archive RPC functions
- Maintains data integrity
- Enables data recovery
Audit Trails
Section titled “Audit Trails”Comprehensive tracking:
created_at/created_byupdated_at/updated_by- Version columns with auto-increment
- Timestamp with timezone
Cascade Deletes
Section titled “Cascade Deletes”Proper foreign key constraints:
- Annotations cascade from layers
- Maintain referential integrity
- Prevent orphaned records
UUID Primary Keys
Section titled “UUID Primary Keys”All tables use UUIDs:
uuid_generate_v4()default- Globally unique identifiers
- Security through obscurity
- Distribution-friendly