Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions plugins/coalesce-accelerator/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
"Vuetify",
"TypeScript"
],
"categories": ["Framework", "FullStack"],
"contents": {
"instructions": [
"instructions/coalesce-workflows.md",
"instructions/ef-core-patterns.md",
"instructions/code-generation.md"
]
}
"categories": [
"Framework",
"FullStack"
],
"skills": "skills/"
}
74 changes: 74 additions & 0 deletions plugins/coalesce-accelerator/skills/add-data-source/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
name: add-data-source
description: Add a custom Coalesce IDataSource to filter or shape entity data for a specific use case
---

# Add Data Source Skill

Create a custom Coalesce `IDataSource<T>` implementation to provide filtered, shaped, or security-scoped access to an entity beyond the default CRUD behavior.

## When to Use

Invoke this skill when you need to:
- Expose a filtered subset of an entity (e.g., "only active records")
- Add includes/eager loading not present on the default source
- Scope data to the current user (tenancy, ownership)
- Return a projection or computed view of an entity

## Data Source Pattern

```csharp
using IntelliTect.Coalesce;
using IntelliTect.Coalesce.Api;
using IntelliTect.Coalesce.TypeDefinition;

[Coalesce]
public class ActiveEntitySource : StandardDataSource<Entity, AppDbContext>
{
public ActiveEntitySource(CrudContext<AppDbContext> context) : base(context) { }

public override IQueryable<Entity> GetQuery(IDataSourceParameters parameters)
=> base.GetQuery(parameters)
.Where(e => e.IsActive)
.Include(e => e.RelatedEntity);
}
```

## Steps

1. **Create the data source class** in a `DataSources/` folder beside your entity models
2. **Decorate with `[Coalesce]`** so the CLI picks it up during code generation
3. **Override `GetQuery`** — compose from `base.GetQuery()` to retain default filtering/sorting support
4. **Optionally override `TransformResults`** for post-query shaping
5. **Run `coalesce_generate`** to expose it in the API:
```bash
coalesce_generate
```
6. **Verify the new data source appears** in the generated API and TypeScript service
7. **Write tests** that confirm filtering/scoping works correctly

## User-Scoped Data Source Pattern

```csharp
[Coalesce]
public class MyRecordsSource : StandardDataSource<Record, AppDbContext>
{
private readonly ICurrentUserService _currentUser;

public MyRecordsSource(CrudContext<AppDbContext> context, ICurrentUserService currentUser)
: base(context)
{
_currentUser = currentUser;
}

public override IQueryable<Record> GetQuery(IDataSourceParameters parameters)
=> base.GetQuery(parameters)
.Where(r => r.OwnerId == _currentUser.UserId);
}
```

## Notes

- Multiple data sources can exist for the same entity — each becomes a selectable source in the API
- The default data source is `StandardDataSource<T>` — your custom sources supplement it
- Always test that unauthorized data cannot be reached through alternative data sources
63 changes: 63 additions & 0 deletions plugins/coalesce-accelerator/skills/generate-migration/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: generate-migration
description: Generate an EF Core migration and run it for the current Coalesce project
---

# Generate Migration Skill

Generate a new EF Core database migration after making changes to Coalesce entity models, then optionally apply it to the database.

## When to Use

Invoke this skill after you have:
- Added, renamed, or removed a property on a Coalesce entity
- Added or removed a navigation property or relationship
- Changed a `[StringLength]`, `[Required]`, or other schema-affecting attribute
- Added a new entity class to the `DbContext`

## Steps

1. **Verify the model compiles**
```bash
dotnet build
```
Fix any compiler errors before proceeding.

2. **Regenerate Coalesce artifacts** to keep the API and TypeScript types in sync:
```bash
coalesce_generate
```

3. **Add the EF Core migration** using a descriptive PascalCase name that describes the change:
```bash
dotnet ef migrations add <MigrationName> --project <DataProject> --startup-project <WebProject>
```
Examples: `AddCompanyPhoneNumber`, `RemoveOrderLegacyStatus`, `AddIndexOnUserEmail`

4. **Review the generated migration file** in `Migrations/` — verify the `Up()` and `Down()` methods match your intent. Check for:
- Unexpected table drops or column drops
- Missing `nullable` settings
- Correct foreign key constraints

5. **Apply the migration to the database**:
```bash
dotnet ef database update --project <DataProject> --startup-project <WebProject>
```

6. **Run tests** to confirm nothing regressed:
```bash
dotnet test
```

## Naming Conventions

Migration names should be short, PascalCase, and describe **what changed**:
- ✅ `AddUserEmailIndex`
- ✅ `RenameCompanyAddressToStreet`
- ❌ `Update1`, `Migration20240101`, `Changes`

## Notes

- Always review the generated `.cs` migration file before applying — EF Core may infer destructive changes
- If the migration is complex, split it: one for schema changes, one for data changes
- For seed data changes, consider a separate data migration or a custom `IHostedService`
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
---
name: run-code-generation
description: Run Coalesce code generation to regenerate TypeScript types and API client after C# model changes
---

# Run Code Generation Skill

Trigger and manage Coalesce's code generation pipeline to regenerate TypeScript types, API clients, and ViewModels after C# model or service changes.

## When to Use

Invoke this skill when you:
- Have made changes to C# entity classes and need to regenerate TypeScript types
- Need to run coalesce_generate and understand what it produces
- Want to troubleshoot code generation errors or stale generated files
- Are setting up or configuring the code generation pipeline

# Coalesce Code Generation

This guide explains what Coalesce generates, how to run code generation, customize the output, and manage regeneration workflows.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,92 @@
---
name: scaffold-entity
description: Scaffold a new Coalesce entity class with EF Core annotations, navigation properties, and register it in the DbContext
---

# Scaffold Entity Skill

Create a complete Coalesce-compatible C# entity class with appropriate EF Core data annotations, navigation properties, and DbContext registration.

## When to Use

Invoke this skill when you need to:
- Add a new domain entity to the Coalesce data model
- Create a related/child entity with a foreign key relationship
- Scaffold a lookup/reference table entity

## Required Information

Before scaffolding, gather:
1. **Entity name** — PascalCase noun (e.g., `Invoice`, `ProjectMilestone`)
2. **Properties** — names, types, and whether required/optional
3. **Relationships** — parent entity (if any), one-to-many or many-to-many
4. **Table name** — usually pluralized entity name (e.g., `Invoices`)

## Scaffold Pattern

```csharp
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using IntelliTect.Coalesce.DataAnnotations;

[Table("EntityNamePlural")]
public class EntityName
{
// Primary key — name must be {EntityName}Id
[Key]
public int EntityNameId { get; set; }

// Required string property
[Required]
[StringLength(255)]
[Display(Name = "Friendly Label")]
public required string Name { get; set; }

// Optional string property
[StringLength(1024)]
public string? Description { get; set; }

// Foreign key + navigation (many-to-one)
public int ParentId { get; set; }
public Parent Parent { get; set; } = null!;

// Audit fields
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime? UpdatedAt { get; set; }
}
```

## Steps

1. **Create the entity file** in the `Models/` directory
2. **Add the DbSet** to the application's `DbContext`:
```csharp
public DbSet<EntityName> EntityNames { get; set; }
```
3. **Run `coalesce_generate`** to generate the API and TypeScript types:
```bash
coalesce_generate
```
4. **Create a migration** to add the table (use the `generate-migration` skill)
5. **Build and test**:
```bash
dotnet build && dotnet test
```

## Coalesce-Specific Annotations

| Attribute | Effect |
|-----------|--------|
| `[Read(Roles = "Admin")]` | Restrict read access by role |
| `[Edit(Roles = "Admin")]` | Restrict edit access by role |
| `[Hidden]` | Exclude from generated list views |
| `[Search]` | Include property in text search |
| `[DefaultOrderBy]` | Set default sort property |
| `[ListText]` | Use as display text in dropdowns |


## Reference: EF Core Patterns

# Entity Framework Core Patterns with Coalesce

This guide covers Entity Framework Core (EF Core) best practices, patterns, and configurations specifically for Coalesce development.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
---
name: setup-coalesce-project
description: Set up a new Coalesce full-stack project from scratch including models, DbContext, and project structure
---

# Setup Coalesce Project Skill

Guide the full setup of a new Coalesce full-stack project including C# models, EF Core DbContext, Coalesce configuration, and Vue 3 frontend scaffolding.

## When to Use

Invoke this skill when you:
- Are starting a brand new Coalesce project from scratch
- Need to configure an existing project to use Coalesce
- Want to understand the required project structure and dependencies
- Are setting up the full development workflow for a Coalesce application

# Coalesce Workflows

This guide covers the end-to-end workflows for developing with Coalesce, from project setup through code generation to full-stack deployment.
Expand Down
13 changes: 5 additions & 8 deletions plugins/csharp-best-practices/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
"enterprise",
"dotnet"
],
"categories": ["Language", "Enterprise"],
"contents": {
"instructions": [
"instructions/csharp-patterns.md",
"instructions/naming-conventions.md",
"instructions/async-patterns.md"
]
}
"categories": [
"Language",
"Enterprise"
],
"skills": "skills/"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
---
name: apply-csharp-patterns
description: Apply enterprise C# patterns including error handling, dependency injection, and clean code principles
---

# Apply C# Patterns Skill

Apply idiomatic C# language patterns including type design, null handling, pattern matching, LINQ, and modern C# features for clean, maintainable enterprise code.

## When to Use

Invoke this skill when you:
- Need to refactor existing code to follow C# best practices
- Are writing new C# code and want to apply proper patterns
- Want a review of C# language feature usage in a file or class
- Are modernizing older C# code to use current language features

# C# Language Patterns & Best Practices

Comprehensive guide to idiomatic C# patterns, type design, and language features for writing maintainable, performant code.
Expand Down
Loading
Loading