Skip to main content

Mongo DB

Database Schema Documentation

This document provides a comprehensive overview of the MongoDB database schema used in the Vibra application. The schema is organized by domain categories, with detailed descriptions of each collection, its fields, data types, and relationships with other collections.

Table of Contents

Preview

Collection diagram

User Management

Users

The Users collection stores information about system users, including personal details, authentication information, and system access settings.

FieldTypeDescription
_idObjectIdPrimary key
nameStringUser's full name
documentTypeObjectIdReference to document type
documentNumberStringUser's identification number
addressStringUser's physical address
phoneNumberStringUser's contact number
emailStringUser's email address
usernameStringUser's login username
passwordStringEncrypted password
createdAtDateTimeCreation timestamp
createdByStringCreator reference
editedAtDateTimeLast edit timestamp
editedByStringLast editor reference
deletedBooleanSoft deletion flag
deletedAtDateTimeDeletion timestamp
isActiveBooleanAccount status
roleObjectIdReference to Roles collection
companyObjectIdReference to Companies collection
genderStringUser's gender
isLoggedBooleanCurrent login status
avatarStringProfile image reference
birthDateDateTimeUser's date of birth
updatedAtDateTimeLast update timestamp
__vIntVersion number

Relationships:

  • Users → Roles (Many-to-One): Each user has one role
  • Users → Companies (Many-to-One): Each user belongs to one company

UserPolicies

Tracks user acceptance of system policies and terms.

FieldTypeDescription
_idObjectIdPrimary key
userIdObjectIdReference to Users collection
policyIdObjectIdReference to Policies collection
userPolicyKeyStringUnique identifier for user-policy pair
versionStringPolicy version accepted
isAcceptedBooleanAcceptance status
ipAddressStringIP address during acceptance
userAgentStringBrowser/device information
acceptedAtDateTimeAcceptance timestamp
createdAtDateTimeCreation timestamp
updatedAtDateTimeLast update timestamp
__vIntVersion number

Relationships:

  • UserPolicies → Users (Many-to-One): Each policy acceptance belongs to one user
  • UserPolicies → Policies (Many-to-One): Each policy acceptance refers to one policy

Roles

Defines user roles and their administrative capabilities.

FieldTypeDescription
_idObjectIdPrimary key
serialStringUnique identifier
nameStringRole name
descriptionStringRole description
isSuperAdminBooleanSuper admin privileges flag
isActiveBooleanRole status
createdAtDateTimeCreation timestamp
createdByStringCreator reference
__vIntVersion number
deletedBooleanSoft deletion flag
deletedAtDateTimeDeletion timestamp
editedAtDateTimeLast edit timestamp
permissionTemplateStringTemplate for role permissions

Relationships:

  • Roles → Users (One-to-Many): Each role can be assigned to multiple users

Activities and Learning

Activities

Stores educational activities and their associated resources and questions.

FieldTypeDescription
_idObjectIdPrimary key
idStringActivity identifier
emotionsStringAssociated emotions
titleStringActivity title
resourcesResources[]Array of learning resources
questionsQuestions[]Array of assessment questions
difficultyIntDifficulty level
isActiveBooleanActivity status
scheduleScheduleScheduling information
createdAtDateTimeCreation timestamp

Relationships:

  • Activities → Emotions (Many-to-One): Activities are associated with emotions
  • Activities → UserResponses (One-to-Many): Each activity can have multiple user responses

Resources

Embedded document within Activities that defines learning materials.

FieldTypeDescription
typeStringResource type (video, article, etc.)
urlStringResource location
durationIntLength in seconds/minutes
metadataMetadatasAdditional resource information

Metadatas

Embedded document within Resources that provides additional context.

FieldTypeDescription
authorStringContent creator
languageStringContent language

Questions

Embedded document within Activities that defines assessment questions.

FieldTypeDescription
idStringQuestion identifier
questionTextStringThe question itself
typeStringQuestion type (multiple choice, etc.)
optionsString[]Possible answers
correctAnswerStringThe correct answer
pointsIntPoint value

Schedule

Embedded document within Activities that defines when activities should be available.

FieldTypeDescription
dateDateTimeScheduled date
weekNumberIntWeek number
yearIntYear

Emotions

Defines emotional categories used in activities.

FieldTypeDescription
_idObjectIdPrimary key
idStringEmotion identifier
nameStringEmotion name
orientationNoteStringGuidance note
descriptionStringDetailed description
iconoStringIcon reference
percentNoteIntPercentage indicator

Relationships:

  • Emotions → Activities (One-to-Many): Each emotion can be associated with multiple activities

UserResponses

Stores user answers to activity questions and performance metrics.

FieldTypeDescription
_idObjectIdPrimary key
userStringReference to user
activityStringReference to activity
responsesUserResponse[]Array of individual responses
scoreIntTotal score achieved
startTimeDateTimeWhen user started the activity
endTimeDateTimeWhen user completed the activity
timeSpentIntDuration in seconds
createdAtDateTimeCreation timestamp
updatedAtDateTimeLast update timestamp
__vIntVersion number

Relationships:

  • UserResponses → Users (Many-to-One): Each response set belongs to one user
  • UserResponses → Activities (Many-to-One): Each response set is for one activity

UserResponse

Embedded document within UserResponses that stores individual question responses.

FieldTypeDescription
_idObjectIdPrimary key
questionIdStringReference to question
answerStringUser's answer
isCorrectBooleanCorrectness flag
responseTimeIntTime taken to answer

Pretest

Stores preliminary assessment results.

FieldTypeDescription
_idObjectIdPrimary key
testIdStringTest identifier
userIdStringUser reference
responsesPretestResponse[]Array of responses
__vIntVersion number

Relationships:

  • Pretest → Users (Many-to-One): Each pretest belongs to one user

PretestResponse

Embedded document within Pretest that stores individual question responses.

FieldTypeDescription
questionIdStringReference to question
answerStringUser's answer

Notifications

Notifications

Stores system notifications sent to users.

FieldTypeDescription
_idObjectIdPrimary key
IDStringNotification identifier
titleStringNotification title
messageStringNotification content
isReadBooleanRead status
clientStringTarget client
notificationTypeStringReference to notification type
notificationChannelStringReference to notification channel
priorityIntImportance level
serialStringUnique identifier
isActiveBooleanActive status
deletedBooleanSoft deletion flag
deletedAtDateTimeDeletion timestamp
createdAtDateTimeCreation timestamp
__vIntVersion number

Relationships:

  • Notifications → NotificationTypes (Many-to-One): Each notification has one type
  • Notifications → NotificationChannels (Many-to-One): Each notification uses one channel

NotificationTypes

Defines categories of notifications.

FieldTypeDescription
_idObjectIdPrimary key
titleStringType name
descriptionStringType description
levelIntImportance level

Relationships:

  • NotificationTypes → Notifications (One-to-Many): Each type can be used by multiple notifications

NotificationChannels

Defines delivery methods for notifications.

FieldTypeDescription
_idObjectIdPrimary key
titleStringChannel name
descriptionStringChannel description
levelIntPriority level

Relationships:

  • NotificationChannels → Notifications (One-to-Many): Each channel can be used by multiple notifications

Permissions and Access Control

Permissions

Defines system permissions that can be assigned to users.

FieldTypeDescription
_idObjectIdPrimary key
serialStringUnique identifier
nameStringPermission name
descriptionStringPermission description
permissionCategoryStringReference to category
isActiveBooleanPermission status
createdAtDateTimeCreation timestamp
createdByStringCreator reference
__vIntVersion number
deletedBooleanSoft deletion flag
deletedAtDateTimeDeletion timestamp
deletedByStringDeleter reference

Relationships:

  • Permissions → PermissionCategories (Many-to-One): Each permission belongs to one category
  • Permissions → UserPermissions (One-to-Many): Each permission can be assigned to multiple users

PermissionCategories

Groups permissions into logical categories.

FieldTypeDescription
_idObjectIdPrimary key
serialStringUnique identifier
nameStringCategory name
descriptionStringCategory description
isActiveBooleanCategory status
createdAtDateTimeCreation timestamp
createdByStringCreator reference
__vIntVersion number

Relationships:

  • PermissionCategories → Permissions (One-to-Many): Each category can contain multiple permissions

UserPermissions

Links users to their assigned permissions.

FieldTypeDescription
_idObjectIdPrimary key
userStringReference to user
permissionStringReference to permission
serialStringUnique identifier
isActiveBooleanAssignment status
deletedBooleanSoft deletion flag
createdAtDateTimeCreation timestamp
createdByStringCreator reference
deletedAtDateTimeDeletion timestamp
__vIntVersion number
deletedByStringDeleter reference

Relationships:

  • UserPermissions → Users (Many-to-One): Each permission assignment belongs to one user
  • UserPermissions → Permissions (Many-to-One): Each permission assignment refers to one permission

Policies

Stores system policies and terms that users must accept.

FieldTypeDescription
_idObjectIdPrimary key
titleStringPolicy title
contentStringPolicy text
versionStringPolicy version
isActiveBooleanPolicy status
typeStringPolicy type
effectiveDateDateTimeWhen policy takes effect
createdAtDateTimeCreation timestamp
updatedAtDateTimeLast update timestamp

Relationships:

  • Policies → UserPolicies (One-to-Many): Each policy can have multiple user acceptances

Organizations

Companies

Stores information about organizations using the system.

FieldTypeDescription
_idObjectIdPrimary key
nameStringCompany name
nitStringTax identification number
addressStringPhysical address
emailStringContact email
phoneNumberLongContact number
managerDataManagerDataManager information
createdAtDateTimeCreation timestamp
deletedBooleanSoft deletion flag
deletedAtDateTimeDeletion timestamp
isActiveBooleanCompany status
sloganStringCompany motto
userAdminStringAdmin user reference
editedAtDateTimeLast edit timestamp
isMainBooleanPrimary company flag

Relationships:

  • Companies → Users (One-to-Many): Each company can have multiple users
  • Companies → ManagerData (One-to-One): Each company has one manager data record

ManagerData

Embedded document within Companies that stores manager information.

FieldTypeDescription
nameStringManager name
documentTypeStringID type
documentStringID number
emailStringContact email
phoneNumberStringContact number

HightSchools

Stores information about educational institutions.

FieldTypeDescription
_idObjectIdPrimary key
idStringSchool identifier
nameStringSchool name
addressStringPhysical address
nitStringTax identification number
emailStringContact email
__vIntVersion number

Relationships:

  • HightSchools → Courses (One-to-Many): Each school can have multiple courses

Courses

Stores information about courses offered by schools.

FieldTypeDescription
_idObjectIdPrimary key
idStringCourse identifier
nameStringCourse name
hightSchoolStringReference to school

Relationships:

  • Courses → HightSchools (Many-to-One): Each course belongs to one school

Clients

Stores information about client organizations.

FieldTypeDescription
_idObjectIdPrimary key
nameStringClient name
nitStringTax identification number
epsCodeStringHealth provider code
addressStringPhysical address
phoneNumberStringContact number
emailStringContact email
overdueInvoiceIdsObjectId[]Overdue invoice references
creditLimitNumberMaximum credit allowed
transactionsObjectId[]Transaction references
avatarStringLogo reference
isParticularBooleanIndividual client flag
regimeStringTax regime
serialStringUnique identifier
isActiveBooleanClient status
deletedBooleanSoft deletion flag
createdAtDateTimeCreation timestamp
createdByStringCreator reference
deletedAtDateTimeDeletion timestamp
__vNumberVersion number

System Configuration

Configs

Stores system configuration settings.

FieldTypeDescription
_idObjectIdPrimary key
nameStringConfiguration name
flagBooleanToggle state
allowedUsersString[]Users with access
disallowedUsersString[]Users without access
createdByStringCreator reference
createdAtDateTimeCreation timestamp
editedAtDateTimeLast edit timestamp
editedByStringLast editor reference
isActiveBooleanConfiguration status
descriptionStringConfiguration description
__vIntVersion number

Feedbacks

Stores user feedback and feature requests.

FieldTypeDescription
_idObjectIdPrimary key
titleStringFeedback title
descriptionStringFeedback content
isFeatureBooleanFeature request flag
isSupportBooleanSupport request flag
serialStringUnique identifier
isActiveBooleanFeedback status
deletedBooleanSoft deletion flag
createdAtDateTimeCreation timestamp
createdByStringCreator reference
deletedAtDateTimeDeletion timestamp
__vIntVersion number

Audit and Reporting

AuditLogs

Tracks user actions within the system for security and compliance.

FieldTypeDescription
_idObjectIdPrimary key
userStringUser reference
actionStringAction performed
entityStringAffected entity
detailsStringAction details
ipStringUser IP address
isActiveBooleanLog status
deletedBooleanSoft deletion flag
timestampDateTimeAction timestamp
deletedAtDateTimeDeletion timestamp
createdAtDateTimeCreation timestamp
__vNumberVersion number

Relationships:

  • AuditLogs → Users (Many-to-One): Each log entry is associated with one user

Reports

Stores generated reports and their download history.

FieldTypeDescription
_idObjectIdPrimary key
invoiceIdStringRelated invoice reference
reportTypeStringReport category
downloadHistoryObjectId[]Download record references
createdAtDateTimeCreation timestamp
__vNumberVersion number

WeeklySchedules

Stores scheduling information for activities and participants.

FieldTypeDescription
_idObjectIdPrimary key
weekNumberNumberWeek number
yearNumberYear
daysObjectId[]Day references
participantsObjectId[]Participant references
__vNumberVersion number

File Storage

FsFiles

Stores metadata for files stored in the system.

FieldTypeDescription
_idObjectIdPrimary key
lengthIntFile size in bytes
chunkSizeIntGridFS chunk size
uploadDateDateTimeUpload timestamp
filenameStringOriginal filename

Database Relationships Diagram

graph TD
Users --> Roles
Users --> Companies
UserPolicies --> Users
UserPolicies --> Policies
Activities --> Emotions
UserResponses --> Users
UserResponses --> Activities
Pretest --> Users
Notifications --> NotificationTypes
Notifications --> NotificationChannels
Permissions --> PermissionCategories
UserPermissions --> Users
UserPermissions --> Permissions
Companies --> Users
Courses --> HightSchools
AuditLogs --> Users

Common Patterns

The database schema follows several common patterns:

  1. Soft Deletion: Most collections include deleted and deletedAt fields to support soft deletion.

  2. Audit Fields: Most collections include creation and modification timestamps and user references.

  3. Versioning: Many collections include a __v field for optimistic concurrency control.

  4. Embedded Documents: Complex data structures are represented as embedded documents (e.g., Resources within Activities).

  5. Reference by ID: Relationships between collections are established using ObjectId references.

  6. Status Flags: Most collections include an isActive field to indicate current status.

  7. Serial Numbers: Many collections include a serial field as a human-readable unique identifier.