Data Seeding
Relevant source files
The following files were used as context for generating this wiki page:
The Data Seeding feature in Traduora is a mechanism for populating the database with initial data. Its primary purpose is to create a default administrator user, which is essential for accessing the platform when public user signups are disabled (TR_SIGNUPS_ENABLED=false). This ensures that an administrator can log in to manage the application, invite other users, and configure projects.
The seeding process can be triggered either manually via command-line scripts or automatically when the application starts up, based on an environment variable. The system is designed to be extensible, allowing for additional data, such as demo data, to be seeded in the future, although its current implementation focuses on user creation.
Sources: README.md, api/src/seeds/seed-data.service.ts:16-19
Seeding Architecture
The data seeding functionality is built using several key components within the NestJS framework. The SeedModule is responsible for setting up the necessary providers and dependencies for the seeding process.
Sources: api/src/seeds/seed.module.ts
Core Components
| Component | Description | File |
|---|---|---|
SeedDataService | Orchestrates the entire seeding process. It contains methods to run all seeds or just the default seeds. | api/src/seeds/seed-data.service.ts |
UserSeed | Contains the specific logic for seeding user data, primarily the default admin user. | api/src/seeds/user.seed.ts |
UserService | A service dependency used by UserSeed to interact with the user data model and create the user record. | api/src/seeds/user.seed.ts:12-12 |
seed-cli.ts | The command-line interface entry point for manually triggering the seeding process. (Not provided in context) | api/package.json:28-29 |
SeedModule | The NestJS module that imports and provides all the necessary services for data seeding. | api/src/seeds/seed.module.ts |
The following diagram illustrates the relationship between these components.
This diagram shows that the SeedDataService uses UserSeed to perform the user seeding operation, which in turn relies on UserService to handle the database interaction.
Sources: api/src/seeds/seed.module.ts:13-15, api/src/seeds/seed-data.service.ts:11-11, api/src/seeds/user.seed.ts:12-12
Seeding Process Flow
The seeding process can be initiated in two main ways: automatically at startup or manually via a CLI command. The flow is managed by the SeedDataService, which offers two primary methods: runAllSeed and runDefaultSeed.
runDefaultSeed: Executes only the "default" seed operations. Currently, this is limited to seeding the default admin user.runAllSeed: Executes a "complete" set of seed operations. While designed to be extensible for more data, it currently only calls the same default user seeding operation.
Sources: api/src/seeds/seed-data.service.ts:16-19, 35-37
The following flowchart shows the logic within the SeedDataService.
This flowchart shows how both runDefaultSeed and runAllSeed currently lead to the execution of seedDefaultUsers.
Sources: api/src/seeds/seed-data.service.ts:16-19, 35-37
Default Admin User Seeding
The core function of the seeding process is to create a default administrator account. This is handled by the UserSeed service.
The createDefaultAdmin method in UserSeed first checks if the admin user already exists by email. If the user does not exist, it proceeds to create a new user with credentials specified by environment variables. If the user already exists, the creation is skipped to avoid duplicates.
Sources: api/src/seeds/user.seed.ts:27-32
The sequence diagram below illustrates the creation of the default admin user.
This diagram shows the interactions between services to check for and create the default admin user in the database.
Sources: api/src/seeds/user.seed.ts:15-50
Execution and Configuration
The data seeding process can be configured and executed through environment variables and yarn scripts.
Automatic Seeding
To enable automatic seeding when the application starts, the following environment variable must be set:
TR_SEED_DATA=true: When this is set, the seed scripts will run automatically during application startup.
Sources: README.md, api/package.json:28-29
Manual Seeding
Manual seeding is performed using yarn scripts defined in api/package.json. These scripts can be run from the monorepo root or from within the api package directory.
| Command | Description |
|---|---|
yarn seed | Runs all seeds. This is triggered by the seed script in api/package.json, which sets TR_SEED_DATA=true and executes seed-cli.ts. |
yarn seed:default | Runs only the default seeds (i.e., the admin user). This is triggered by the seed:default script, which sets TR_DEFAULT_SEED_ONLY=true in addition to TR_SEED_DATA=true. |
Sources: README.md, api/package.json:28-29
Admin User Configuration
The credentials for the default admin user can be customized using environment variables. If these are not set, default values are used.
| Environment Variable | Description | Default Value |
|---|---|---|
TR_ADMIN_EMAIL | Admin user's email address. | local.admin@ever.co |
TR_ADMIN_PASSWORD | Admin user's password. | sTr0ngP@ssw0rd!2025 |
TR_ADMIN_NAME | Admin user's display name. | Admin |
These credentials can be changed through the user settings interface after the first login.
Sources: README.md, api/src/seeds/user.seed.ts:18-24