Skip to content
Closed
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
2 changes: 1 addition & 1 deletion cli/SimpleModule.Cli/Commands/Doctor/DoctorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private static void AutoFix(SolutionContext solution, List<CheckResult> results)
var moduleName = result.Name["API -> ".Length..];
ProjectManipulator.AddProjectReference(
solution.ApiCsprojPath,
$@"..\modules\{moduleName}\{moduleName}\{moduleName}.csproj"
$@"..\modules\{moduleName}\src\{moduleName}\{moduleName}.csproj"
);
AnsiConsole.MarkupLine(
$"[green] Fixed: added {moduleName} reference to API csproj[/]"
Expand Down
24 changes: 24 additions & 0 deletions cli/SimpleModule.Cli/Commands/New/NewModuleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public override int Execute(CommandContext context, NewModuleSettings settings)
var moduleDir = solution.GetModuleProjectPath(moduleName);
var eventsDir = Path.Combine(contractsDir, "Events");
var endpointsDir = Path.Combine(moduleDir, "Endpoints", moduleName);
var viewsDir = solution.GetModuleViewsPath(moduleName);
var pagesDir = Path.Combine(moduleDir, "Pages");
var testDir = solution.GetTestProjectPath(moduleName);

void Plan(string path) => ops.Add((path, FileAction.Create));
Expand All @@ -51,6 +53,10 @@ public override int Execute(CommandContext context, NewModuleSettings settings)
Plan(Path.Combine(moduleDir, $"{moduleName}DbContext.cs"));
Plan(Path.Combine(moduleDir, $"{singularName}Service.cs"));
Plan(Path.Combine(endpointsDir, "GetAllEndpoint.cs"));
Plan(Path.Combine(viewsDir, "IndexEndpoint.cs"));
Plan(Path.Combine(viewsDir, "Index.tsx"));
Plan(Path.Combine(pagesDir, "index.ts"));
Plan(Path.Combine(moduleDir, "vite.config.ts"));
Plan(Path.Combine(testDir, $"{moduleName}.Tests.csproj"));
Plan(Path.Combine(testDir, "GlobalUsings.cs"));
Plan(Path.Combine(testDir, "Unit", $"{singularName}ServiceTests.cs"));
Expand All @@ -73,6 +79,8 @@ public override int Execute(CommandContext context, NewModuleSettings settings)
{
Directory.CreateDirectory(eventsDir);
Directory.CreateDirectory(endpointsDir);
Directory.CreateDirectory(viewsDir);
Directory.CreateDirectory(pagesDir);
Directory.CreateDirectory(Path.Combine(testDir, "Unit"));
Directory.CreateDirectory(Path.Combine(testDir, "Integration"));

Expand Down Expand Up @@ -125,6 +133,22 @@ public override int Execute(CommandContext context, NewModuleSettings settings)
Path.Combine(endpointsDir, "GetAllEndpoint.cs"),
templates.GetAllEndpoint(moduleName, singularName)
);
File.WriteAllText(
Path.Combine(viewsDir, "IndexEndpoint.cs"),
ModuleTemplates.IndexViewEndpoint(moduleName)
);
File.WriteAllText(
Path.Combine(viewsDir, "Index.tsx"),
ModuleTemplates.IndexPageTsx(moduleName)
);
File.WriteAllText(
Path.Combine(pagesDir, "index.ts"),
ModuleTemplates.PagesIndexTs(moduleName)
);
File.WriteAllText(
Path.Combine(moduleDir, "vite.config.ts"),
ModuleTemplates.ViteConfig()
);

File.WriteAllText(
Path.Combine(testDir, $"{moduleName}.Tests.csproj"),
Expand Down
22 changes: 0 additions & 22 deletions cli/SimpleModule.Cli/Infrastructure/SlnxManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,4 @@ private static string DetectIndent(List<string> lines)

return " ";
}

private static int FindFolderClosingTag(List<string> lines, string folderName)
{
var folderIndex = lines.FindIndex(l =>
l.Contains($"<Folder Name=\"{folderName}\">", StringComparison.Ordinal)
);
if (folderIndex < 0)
{
return -1;
}

// Find closing </Folder> tag
for (var i = folderIndex + 1; i < lines.Count; i++)
{
if (lines[i].TrimStart().StartsWith("</Folder>", StringComparison.Ordinal))
{
return i;
}
}

return -1;
}
}
45 changes: 45 additions & 0 deletions cli/SimpleModule.Cli/Templates/ModuleTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,51 @@ public string GlobalUsings()
""";
}

public static string IndexViewEndpoint(string moduleName) =>
$$"""
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using SimpleModule.Core;
using SimpleModule.Core.Inertia;

namespace SimpleModule.{{moduleName}}.Views;

public class IndexEndpoint : IViewEndpoint
{
public void Map(IEndpointRouteBuilder app)
{
app.MapGet("/", () => Inertia.Render("{{moduleName}}/Index", new { }))
.ExcludeFromDescription();
}
}
""";

public static string PagesIndexTs(string moduleName) =>
$$"""
export const pages: Record<string, () => Promise<unknown>> = {
'{{moduleName}}/Index': () => import('../Views/Index'),
};
""";

public static string IndexPageTsx(string moduleName) =>
"""
export default function Index() {
return (
<div style={{ padding: '2rem' }}>
<h1>__MODULE_NAME__</h1>
<p>Welcome to the __MODULE_NAME__ module. Edit Views/Index.tsx to customize this page.</p>
</div>
);
}
""".Replace("__MODULE_NAME__", moduleName, StringComparison.Ordinal);

public static string ViteConfig() =>
"""
import { defineModuleConfig } from '@simplemodule/client/module';

export default defineModuleConfig(import.meta.dirname);
""";

// ── Medium C# files (read + strip + rename) ─────────────────────

public string ContractsInterface(string moduleName, string singularName)
Expand Down
5 changes: 2 additions & 3 deletions framework/SimpleModule.AI.Anthropic/AnthropicExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace SimpleModule.AI.Anthropic;

Expand All @@ -16,9 +17,7 @@ IConfiguration configuration

services.AddSingleton<IChatClient>(sp =>
{
var opts =
configuration.GetSection("AI:Anthropic").Get<AnthropicOptions>()
?? new AnthropicOptions();
var opts = sp.GetRequiredService<IOptions<AnthropicOptions>>().Value;
var client = new AnthropicClient(opts.ApiKey);
return client.Messages;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace SimpleModule.Core.Hosting;

/// <summary>
/// Calls lifecycle hooks on all discovered modules during application startup and shutdown.
/// Supports both <see cref="IModule.OnStartAsync"/>/<see cref="IModule.OnStopAsync"/> (default methods)
/// and the focused <see cref="IModuleLifecycle"/> interface.
/// Modules implement lifecycle by overriding <see cref="IModule.OnStartAsync"/> /
/// <see cref="IModule.OnStopAsync"/> default methods.
/// </summary>
public sealed partial class ModuleLifecycleHostedService(
IEnumerable<IModule> modules,
Expand All @@ -31,14 +31,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
var moduleName = module.GetType().Name;
try
{
if (module is IModuleLifecycle lifecycle)
{
await lifecycle.OnStartAsync(cancellationToken);
}
else
{
await module.OnStartAsync(cancellationToken);
}
await module.OnStartAsync(cancellationToken);
LogModuleStarted(logger, moduleName);
}
catch (OperationCanceledException)
Expand Down Expand Up @@ -69,14 +62,7 @@ public async Task StopAsync(CancellationToken cancellationToken)
var moduleName = module.GetType().Name;
try
{
if (module is IModuleLifecycle lifecycle)
{
await lifecycle.OnStopAsync(cancellationToken);
}
else
{
await module.OnStopAsync(cancellationToken);
}
await module.OnStopAsync(cancellationToken);
LogModuleStopped(logger, moduleName);
}
catch (OperationCanceledException)
Expand Down
14 changes: 0 additions & 14 deletions framework/SimpleModule.Core/IModuleLifecycle.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ public void Emit(SourceProductionContext context, DiscoveryData data)
}
}

var hasLocalizationModule = data.Modules.Any(m => m.ModuleName == "Localization");
if (hasLocalizationModule)
{
sb.AppendLine();
sb.AppendLine(" app.InitializeLocalization();");
}

sb.AppendLine();
sb.AppendLine(" // Source-generated endpoint mapping");
sb.AppendLine(" app.MapModuleEndpoints();");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class ModuleDiscovererGenerator : IIncrementalGenerator
new DbContextRegistryEmitter(),
new ContractRegistryEmitter(),
new AgentExtensionsEmitter(),
new LocalizationExtensionsEmitter(),
new RoutesEmitter(),
new TypeScriptRoutesEmitter(),
];
Expand Down
5 changes: 4 additions & 1 deletion framework/SimpleModule.Rag/KnowledgeRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public sealed class KnowledgeRecord
[VectorStoreData(IsIndexed = true)]
public string? ModuleName { get; set; }

[VectorStoreVector(1536)]
// Dimension is configured at runtime via VectorStoreCollectionDefinition built from
// RagOptions.EmbeddingDimension. The attribute default below is only used when callers
// bypass VectorKnowledgeStore and use attribute-based discovery directly.
[VectorStoreVector(VectorKnowledgeStore.DefaultEmbeddingDimension)]
public ReadOnlyMemory<float> Embedding { get; set; }
}
Loading
Loading