Skip to content

Project Template Feature

Overview

ProjectTemplate is a proposed feature that allows creating projects from predefined templates. This benefits both:

  1. Seeding - Create consistent seed projects with less code
  2. Users - Create new projects from templates (future feature)

Current State

The current implementation provides the foundation for deterministic project creation:

  • Project.CreateWithId() - Factory method for creating projects with specific IDs
  • Study.CreateWithId() - Factory method for creating studies with specific IDs
  • DatabaseSeeder - Uses factory methods instead of reflection

These factory methods enable predictable entity creation for seeding and testing.

Proposed Architecture

Domain Model

// SyRF.ProjectManagement.Core/Model/TemplateAggregate/ProjectTemplate.cs
public class ProjectTemplate : AggregateRoot<Guid>
{
    public string Name { get; private set; }
    public string? Description { get; private set; }
    public Guid? CreatorId { get; private set; }  // null for system templates
    public bool IsSystemTemplate => CreatorId == null;

    public AgreementMode DefaultAgreementMode { get; private set; }
    public IReadOnlyList<StageTemplate> Stages { get; private set; }
    public IReadOnlyList<QuestionTemplate> Questions { get; private set; }

    // Factory methods
    public static ProjectTemplate CreateSystemTemplate(string name, string description);
    public static ProjectTemplate CreateFromProject(Project source, string name, Guid creatorId);

    // Apply template to create a project
    public Project CreateProject(string name, Guid creatorId, int schemaVersion);
}

public class StageTemplate
{
    public string Name { get; set; }
    public StageType Type { get; set; }
    public bool IsActive { get; set; }
    public int Order { get; set; }
}

public class QuestionTemplate
{
    public string Text { get; set; }
    public QuestionType Type { get; set; }
    public IEnumerable<string> Options { get; set; }
}

Service Interface

// SyRF.ProjectManagement.Core/Interfaces/IProjectTemplateService.cs
public interface IProjectTemplateService
{
    // Create templates
    Task<ProjectTemplate> CreateTemplateFromProjectAsync(Guid projectId, string name, Guid creatorId);
    Task<ProjectTemplate> CreateEmptyTemplateAsync(string name, Guid creatorId);

    // Query templates
    Task<IEnumerable<ProjectTemplate>> GetAvailableTemplatesAsync(Guid? investigatorId);
    Task<ProjectTemplate?> GetSystemTemplateAsync(string templateName);

    // Create project from template
    Task<Project> CreateProjectFromTemplateAsync(Guid templateId, string name, Guid creatorId);
}

System Templates

Predefined templates for common use cases:

Template Name AgreementMode Stages Description
basic-screening SingleReviewerDecides Screening only Quick single-reviewer setup
dual-review AutomatedDualScreening Screening + Annotation Standard dual review workflow
complete-review AutomatedDualScreening Screening + Annotation + Extraction Full systematic review
living-review AutomatedDualScreening All stages + Living search Continuous review

Repository

// SyRF.ProjectManagement.Core/Interfaces/IProjectTemplateRepository.cs
public interface IProjectTemplateRepository : IRepository<ProjectTemplate, Guid>
{
    Task<ProjectTemplate?> GetByNameAsync(string name);
    Task<IEnumerable<ProjectTemplate>> GetSystemTemplatesAsync();
    Task<IEnumerable<ProjectTemplate>> GetUserTemplatesAsync(Guid creatorId);
}

Implementation Phases

Phase 1: Core Infrastructure (Future PR)

  1. Create ProjectTemplate aggregate root
  2. Create IProjectTemplateRepository interface
  3. Create MongoDB repository implementation
  4. Add unit tests

Phase 2: Service Layer (Future PR)

  1. Create IProjectTemplateService interface
  2. Implement template creation from projects
  3. Implement project creation from templates
  4. Add integration tests

Phase 3: System Templates (Future PR)

  1. Create default system templates
  2. Seed system templates at startup
  3. Add template selection to project creation API

Phase 4: User Templates (Future PR)

  1. Allow users to create templates from their projects
  2. Template sharing/visibility settings
  3. Template versioning

API Endpoints (Future)

Endpoint Method Description
/api/templates GET List available templates
/api/templates/{id} GET Get template details
/api/templates POST Create template from project
/api/projects/from-template POST Create project from template

Seeder Integration

Once implemented, templates can simplify the DatabaseSeeder:

// Example: Using templates in DatabaseSeeder
var template = await _templateService.GetSystemTemplateAsync("dual-review");
var project = await _templateService.CreateProjectFromTemplateAsync(
    template.Id,
    "Quick Start Demo",
    SeedDataConstants.SeedBotId);

Benefits

  1. Consistency - All projects from same template have identical structure
  2. Maintainability - Change template once, affects all future projects
  3. User Experience - Users can quickly create projects without configuring from scratch
  4. Testing - Templates can be unit tested independently