Overview
Campus uses PocketBase with an embedded SQLite database. The schema is version-controlled through migration files inpb_migrations/, with each migration defining collections, fields, indexes, and API access rules.
Entity Relationship Diagram
Core Collections
users (Built-in PocketBase Auth Collection)
Purpose: Authenticated user accounts Custom Fields Added:| Field | Type | Description | Migration |
|---|---|---|---|
is_admin | bool | Admin flag for moderation | 1758649100 |
prefersDarkMode | bool | UI theme preference | 1759885001 |
locale | text | User language/locale | 1760800000 |
id,email,username,avatar,verified,created,updated
- Managed by PocketBase authentication system
- Public view allowed for basic profile info (1764200000)
spaces
Collection ID:pbc_3929545014Migration:
1758629337_created_spaces.js
Purpose: Top-level community organizations (e.g., departments, faculties)
Schema:
- List/View: Authenticated users
- Create: Authenticated users (become owner)
- Update/Delete: Space owners only
groups
Collection ID:pbc_3346940990Migration:
1758629345_created_groups.js
Purpose: Sub-communities within spaces (e.g., study groups, courses)
Schema:
- List/View: Authenticated users
- Create: Authenticated users
- Update/Delete: Space owners only
Space → Groups
posts
Collection ID:pbc_1125843985Migration:
1758629354_created_posts.js + updates
Purpose: User-generated content (feed posts)
Schema:
- Create: Author must be authenticated user
- Update: Author only
- Delete: Author OR space/group owners/moderators (1758630000)
global- Visible to all usersspace- Visible to space membersgroup- Visible to group members
1758671000_extend_posts_for_media.js added attachments field
comments
Collection ID:pbc_533777971Migration:
1758629362_created_comments.js
Purpose: Replies to posts
Schema:
- Create: Author must be authenticated
- Update: Author only
- Delete: Author OR post’s space/group moderators
- Threaded comments via
parentfield (1758629400) - Cascading delete when post is deleted
likes
Collection ID:pbc_2190274710Migration:
1758629368_created_likes.js
Purpose: Track post likes/reactions
Schema:
- Create: User can like as themselves
- Delete: User can unlike their own
- Unique per user+post (enforced by database logic)
Membership Collections
space_members
Collection ID:pbc_540001234Migration:
1758629500_created_space_members.js
Purpose: Track user membership and roles in spaces
Schema:
idx_space_user_unique- Prevents duplicate memberships
- Create: User joins public spaces OR invited by owner
- Update: Space owners/moderators (for role changes)
- Delete: User leaves OR removed by owners/moderators
group_members
Collection ID:pbc_640001234Migration:
1758629600_created_group_members.js
Purpose: Track user membership and roles in groups
Schema:
idx_group_user_unique- Prevents duplicate memberships
- Create: User joins public groups OR space owner invites
- Update: Group moderators OR space owners
- Delete: User leaves OR removed by moderators
Academic Collections
profiles
Collection ID:pbc_profiles_001Migration:
1758674000_create_profiles.js
Purpose: Extended academic profiles for users
Schema:
idx_profiles_user- Unique per useridx_profiles_department_role- Search by department/role
- View: All authenticated users
- Update: Profile owner OR admin
1764108182_make_profile_fields_optional.js
publication_records
Collection ID:pbc_publication_records_001Migration:
1758674000_create_profiles.js
Purpose: Research publications and papers
Schema:
idx_publications_slug- Unique slugidx_publications_doi- Unique DOI (if provided)
profile_publications (Join Table)
Collection ID:pbc_profile_publications_001Migration:
1758674000_create_profiles.js
Purpose: Link profiles to publications with contribution role
Schema:
idx_profile_publications_unique- Prevent duplicate links
events
Collection ID:pbc_events_001Migration:
1758673000_create_events.js
Purpose: Calendar events (deadlines, meetings, seminars)
Schema:
idx_events_scope_window- Query by scope and date rangeidx_events_createdBy- User’s created events
event_participants
Collection ID:pbc_event_participants_001Migration:
1758673000_create_events.js
Purpose: RSVP status for events
Schema:
idx_event_participants_unique- One RSVP per user per eventidx_event_participants_user- User’s RSVPs
materials
Collection ID:pbc_4282183725Migration:
1759878990_created_materials.js
Purpose: Educational resources and files
Schema:
- Create: Authenticated uploader
- View: Based on visibility level
- Update/Delete: Uploader only
material_access_logs
Collection ID: Not specifiedMigration:
1759878997_created_material_access_logs.js
Purpose: Track material downloads/views for analytics
Moderation Collections
reports
Collection ID:pbc_reports_001Migration:
1758630000_created_reports_and_moderation.js
Purpose: User-submitted content reports
Schema:
idx_reports_target- Query by target type/ID
moderation_logs
Collection ID:pbc_modlogs_001Migration:
1758630000_created_reports_and_moderation.js
Purpose: Audit log of moderation actions
Schema:
- Create: Moderators/admins
- Update/Delete: Immutable (empty rules)
notifications
Collection ID: Not specifiedMigration:
1758645000_created_notifications.js
Purpose: User notifications (likes, comments, mentions)
Schema:
idx_notifications_user_read- Unread notifications queryidx_notifications_user_created- Recent notifications
- View/Update/Delete: Notification owner only
- Create: System only (null rule)
analytics_events
Collection ID: Not specifiedMigration:
1758649000_created_analytics_events.js
Purpose: Track user actions for analytics
Performance Indexes
Migration:1758635000_add_performance_indexes.js
Additional indexes added for query optimization:
- Post queries by scope
- Comment queries by post
- User activity timelines
- Membership lookups
Database File Location
Migration Management
Apply Migrations:Access Rule Syntax
PocketBase uses a SQL-like syntax for access rules:=,!=- Equality?=- Array contains&&,||- Logical AND/OR@request.auth- Current user@request.body- Request payload
Data Integrity
Cascade Deletes:- Deleting a user cascades to their posts, comments, likes
- Deleting a space cascades to groups and memberships
- Deleting a post cascades to comments and likes
- User profiles (one per user)
- Space members (one membership per user per space)
- Group members (one membership per user per group)
- Publication DOIs
Backup Strategy
Recommended:pb_data/data.db- Databasepb_data/storage/- Uploaded filespb_migrations/- Version controlled