Skip to content

Commit

Permalink
Moment42 - Refactor and improve architecture, fix bugs, and resolve s…
Browse files Browse the repository at this point in the history
…tatic code analysis warnings
  • Loading branch information
tjementum committed Sep 9, 2024
1 parent 864f076 commit e6020cb
Show file tree
Hide file tree
Showing 72 changed files with 196 additions and 243 deletions.
2 changes: 1 addition & 1 deletion application/Moment42.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BackOffice.Tests", "back-of
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "calendar-assistant", "calendar-assistant", "{5D0BAB65-65B0-4A2E-8504-3A620E687A4B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CalendarAssistant.Core", "calendar-assistant\Core\CalendarAssistant.Core.csproj", "{83508F78-E0D5-4159-A470-99879225FEB5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CalendarAssistant", "calendar-assistant\Core\CalendarAssistant.csproj", "{83508F78-E0D5-4159-A470-99879225FEB5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CalendarAssistant.Workers", "calendar-assistant\Workers\CalendarAssistant.Workers.csproj", "{541B2F1F-D895-4A4D-AE5B-750AA2824B6A}"
EndProject
Expand Down
16 changes: 1 addition & 15 deletions application/calendar-assistant/Api/CalendarAssistant.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core\CalendarAssistant.Core.csproj" />
<ProjectReference Include="..\Core\CalendarAssistant.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.development.json">
<DependentUpon>appsettings.json</DependentUpon>
</Content>
</ItemGroup>

</Project>
21 changes: 12 additions & 9 deletions application/calendar-assistant/Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
using Moment42.CalendarAssistant.Core;
using Moment42.CalendarAssistant;
using PlatformPlatform.SharedKernel;
using PlatformPlatform.SharedKernel.SinglePageApp;

var builder = WebApplication.CreateBuilder(args);

// Configure services for the Application, Infrastructure, and Api layers like Entity Framework, Repositories, MediatR,
// FluentValidation validators, Pipelines.
// Configure storage infrastructure like Database, BlobStorage, Logging, Telemetry, Entity Framework DB Context, etc.
builder
.AddApiInfrastructure()
.AddDevelopmentPort(9300)
.AddCalendarAssistantInfrastructure();

// Configure dependency injection services like Repositories, MediatR, Pipelines, FluentValidation validators, etc.
builder.Services
.AddCoreServices(builder.Configuration)
.AddApiServices(builder, DependencyConfiguration.Assembly)
.AddStorage(builder)
.AddSinglePageAppFallback()
.ConfigureDevelopmentPort(builder, 9300);
.AddApiServices(Assembly.GetExecutingAssembly(), DependencyConfiguration.Assembly)
.AddCalendarAssistantServices(builder.Configuration)
.AddSinglePageAppFallback();

var app = builder.Build();

// Add common configuration for all APIs like Swagger, HSTS, and DeveloperExceptionPage.
app.UseApiCoreConfiguration();
app.UseApiServices();

// Server the SPA and static files if no other endpoints are found
app.UseSinglePageAppFallback();
Expand Down
12 changes: 0 additions & 12 deletions application/calendar-assistant/Api/appsettings.development.json

This file was deleted.

3 changes: 3 additions & 0 deletions application/calendar-assistant/Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"blob-storage": "UseDevelopmentStorage=true"
},
"AzureOpenAI": {
"Endpoint": "",
"Key": "",
Expand Down
2 changes: 1 addition & 1 deletion application/calendar-assistant/CalendarAssistant.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"AppGateway\\AppGateway.csproj",
"shared-kernel\\SharedKernel\\SharedKernel.csproj",
"shared-kernel\\Tests\\SharedKernel.Tests.csproj",
"calendar-assistant\\Core\\CalendarAssistant.Core.csproj",
"calendar-assistant\\Core\\CalendarAssistant.csproj",
"calendar-assistant\\Api\\CalendarAssistant.Api.csproj",
"calendar-assistant\\WebApp\\CalendarAssistant.WebApp.esproj",
"calendar-assistant\\Tests\\CalendarAssistant.Tests.csproj"
Expand Down
20 changes: 10 additions & 10 deletions application/calendar-assistant/Core/AI/AIAgent.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System.Text.Json;
using Microsoft.Bot.Builder;
using Moment42.CalendarAssistant.Core.AI.Actions.CancelEvent;
using Moment42.CalendarAssistant.Core.AI.Actions.CreateEvent;
using Moment42.CalendarAssistant.Core.AI.Actions.GetCalendarSchedule;
using Moment42.CalendarAssistant.Core.AI.Actions.RescheduleEvent;
using Moment42.CalendarAssistant.Core.AI.Contracts;
using Moment42.CalendarAssistant.Core.AI.Gpt;
using Moment42.CalendarAssistant.Core.AI.Planner;
using Moment42.CalendarAssistant.Core.Conversations.Application;

namespace Moment42.CalendarAssistant.Core.AI;
using Moment42.CalendarAssistant.AI.Actions.CancelEvent;
using Moment42.CalendarAssistant.AI.Actions.CreateEvent;
using Moment42.CalendarAssistant.AI.Actions.GetCalendarSchedule;
using Moment42.CalendarAssistant.AI.Actions.RescheduleEvent;
using Moment42.CalendarAssistant.AI.Contracts;
using Moment42.CalendarAssistant.AI.Gpt;
using Moment42.CalendarAssistant.AI.Planner;
using Moment42.CalendarAssistant.Conversations.Application;

namespace Moment42.CalendarAssistant.AI;

public sealed class AIAgent(
ActionPlanner actionPlanner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Json.Schema;
using Json.Schema.Generation;

namespace Moment42.CalendarAssistant.Core.AI.Actions;
namespace Moment42.CalendarAssistant.AI.Actions;

internal class ActionSchemaBuilder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Moment42.CalendarAssistant.Core.Conversations.Application;
using Moment42.CalendarAssistant.Core.MicrosoftGraph;
using Moment42.CalendarAssistant.Conversations.Application;
using Moment42.CalendarAssistant.MicrosoftGraph;

namespace Moment42.CalendarAssistant.Core.AI.Actions.CancelEvent;
namespace Moment42.CalendarAssistant.AI.Actions.CancelEvent;

public sealed class CancelEventAction(IMicrosoftGraphServiceFactory microsoftGraphServiceFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Json.Schema.Generation;

namespace Moment42.CalendarAssistant.Core.AI.Actions.CancelEvent;
namespace Moment42.CalendarAssistant.AI.Actions.CancelEvent;

public sealed class CancelEventParameters
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Globalization;
using AdaptiveCards.Templating;
using Microsoft.Bot.Builder;
using Moment42.CalendarAssistant.Core.Conversations.AdaptiveCards;
using Moment42.CalendarAssistant.Core.Conversations.AdaptiveCards.Contracts;
using Moment42.CalendarAssistant.Core.Conversations.Application;
using Moment42.CalendarAssistant.Core.Conversations.Extensions;
using Moment42.CalendarAssistant.Conversations.AdaptiveCards;
using Moment42.CalendarAssistant.Conversations.AdaptiveCards.Contracts;
using Moment42.CalendarAssistant.Conversations.Application;
using Moment42.CalendarAssistant.Conversations.Extensions;

namespace Moment42.CalendarAssistant.Core.AI.Actions.CreateEvent;
namespace Moment42.CalendarAssistant.AI.Actions.CreateEvent;

public sealed class CreateEventAction(AdaptiveCardProvider adaptiveCardProvider)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Json.Schema.Generation;

namespace Moment42.CalendarAssistant.Core.AI.Actions.CreateEvent;
namespace Moment42.CalendarAssistant.AI.Actions.CreateEvent;

public sealed class CreateEventParameters
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Text.Json;
using Microsoft.Graph.Models;
using Moment42.CalendarAssistant.Core.MicrosoftGraph;
using Moment42.CalendarAssistant.MicrosoftGraph;

namespace Moment42.CalendarAssistant.Core.AI.Actions.GetCalendarSchedule;
namespace Moment42.CalendarAssistant.AI.Actions.GetCalendarSchedule;

public sealed class GetCalendarScheduleAction(IMicrosoftGraphServiceFactory microsoftGraphServiceFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Json.Schema.Generation;

namespace Moment42.CalendarAssistant.Core.AI.Actions.GetCalendarSchedule;
namespace Moment42.CalendarAssistant.AI.Actions.GetCalendarSchedule;

public sealed class GetCalendarScheduleParameters
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Globalization;
using Microsoft.Graph.Models;
using Moment42.CalendarAssistant.Core.Conversations.Application;
using Moment42.CalendarAssistant.Core.MicrosoftGraph;
using Moment42.CalendarAssistant.Conversations.Application;
using Moment42.CalendarAssistant.MicrosoftGraph;

namespace Moment42.CalendarAssistant.Core.AI.Actions.RescheduleEvent;
namespace Moment42.CalendarAssistant.AI.Actions.RescheduleEvent;

public sealed class RescheduleEventAction(IMicrosoftGraphServiceFactory microsoftGraphServiceFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Json.Schema.Generation;

namespace Moment42.CalendarAssistant.Core.AI.Actions.RescheduleEvent;
namespace Moment42.CalendarAssistant.AI.Actions.RescheduleEvent;

public sealed class RescheduleEventParameters
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Moment42.CalendarAssistant.Core.AI.Planner;
using Moment42.CalendarAssistant.AI.Planner;

namespace Moment42.CalendarAssistant.Core.AI.Contracts;
namespace Moment42.CalendarAssistant.AI.Contracts;

public sealed record AIGptResponse(PlannedAction[]? PlannedActions, PlannedAction[]? PossibleActions, PlannerThoughts? Thoughts);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json;

namespace Moment42.CalendarAssistant.Core.AI.Contracts;
namespace Moment42.CalendarAssistant.AI.Contracts;

public sealed record PlannedAction(string UniqueId, string Name, Dictionary<string, JsonElement> Parameters);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Moment42.CalendarAssistant.Core.AI.Gpt;
namespace Moment42.CalendarAssistant.AI.Gpt;

internal class AzureOpenAIConfiguration
{
Expand Down
4 changes: 2 additions & 2 deletions application/calendar-assistant/Core/AI/Gpt/GptClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using Azure.AI.OpenAI;
using Microsoft.ApplicationInsights;
using Microsoft.Extensions.Options;
using Moment42.CalendarAssistant.Core.TelemetryEvents;
using Moment42.CalendarAssistant.TelemetryEvents;
using OpenAI.Chat;

namespace Moment42.CalendarAssistant.Core.AI.Gpt;
namespace Moment42.CalendarAssistant.AI.Gpt;

internal class GptClient(IOptions<AzureOpenAIConfiguration> azureOpenAIConfiguration, TelemetryClient telemetryClient) : IGptClient
{
Expand Down
2 changes: 1 addition & 1 deletion application/calendar-assistant/Core/AI/Gpt/GptMessage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using OpenAI.Chat;

namespace Moment42.CalendarAssistant.Core.AI.Gpt;
namespace Moment42.CalendarAssistant.AI.Gpt;

public sealed record GptMessage(string Message, GptMessageRole ChatRole)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Moment42.CalendarAssistant.Core.AI.Gpt;
namespace Moment42.CalendarAssistant.AI.Gpt;

public enum GptMessageRole
{
Expand Down
2 changes: 1 addition & 1 deletion application/calendar-assistant/Core/AI/Gpt/GptTokenizer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.ML.Tokenizers;

namespace Moment42.CalendarAssistant.Core.AI.Gpt;
namespace Moment42.CalendarAssistant.AI.Gpt;

public sealed class GptTokenizer(Tokenizer tokenizer) : IGptTokenizer
{
Expand Down
2 changes: 1 addition & 1 deletion application/calendar-assistant/Core/AI/Gpt/IGptClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using OpenAI.Chat;

namespace Moment42.CalendarAssistant.Core.AI.Gpt;
namespace Moment42.CalendarAssistant.AI.Gpt;

public interface IGptClient
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Moment42.CalendarAssistant.Core.AI.Gpt;
namespace Moment42.CalendarAssistant.AI.Gpt;

public interface IGptTokenizer
{
Expand Down
18 changes: 9 additions & 9 deletions application/calendar-assistant/Core/AI/Planner/ActionPlanner.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Text.Json;
using Json.Schema;
using Moment42.CalendarAssistant.Core.AI.Actions;
using Moment42.CalendarAssistant.Core.AI.Actions.CancelEvent;
using Moment42.CalendarAssistant.Core.AI.Actions.CreateEvent;
using Moment42.CalendarAssistant.Core.AI.Actions.GetCalendarSchedule;
using Moment42.CalendarAssistant.Core.AI.Actions.RescheduleEvent;
using Moment42.CalendarAssistant.Core.AI.Contracts;
using Moment42.CalendarAssistant.Core.AI.Gpt;
using Moment42.CalendarAssistant.Core.Conversations.Application;
using Moment42.CalendarAssistant.AI.Actions;
using Moment42.CalendarAssistant.AI.Actions.CancelEvent;
using Moment42.CalendarAssistant.AI.Actions.CreateEvent;
using Moment42.CalendarAssistant.AI.Actions.GetCalendarSchedule;
using Moment42.CalendarAssistant.AI.Actions.RescheduleEvent;
using Moment42.CalendarAssistant.AI.Contracts;
using Moment42.CalendarAssistant.AI.Gpt;
using Moment42.CalendarAssistant.Conversations.Application;
using OpenAI.Chat;

namespace Moment42.CalendarAssistant.Core.AI.Planner;
namespace Moment42.CalendarAssistant.AI.Planner;

public sealed class ActionPlanner(IGptClient gptClient, IGptTokenizer gptTokenizer)
{
Expand Down
4 changes: 2 additions & 2 deletions application/calendar-assistant/Core/AI/Planner/Plan.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text;
using Moment42.CalendarAssistant.Core.AI.Contracts;
using Moment42.CalendarAssistant.AI.Contracts;

namespace Moment42.CalendarAssistant.Core.AI.Planner;
namespace Moment42.CalendarAssistant.AI.Planner;

public sealed record Plan(PlannedAction[]? PlannedActions, PlannedAction[]? PossibleActions, PlannerThoughts? Thoughts)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Moment42.CalendarAssistant.Core.AI.Planner;
namespace Moment42.CalendarAssistant.AI.Planner;

public sealed record PlannerThoughts(string Thought, string Reasoning);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Moment42.CalendarAssistant.Core.Authentication;
namespace Moment42.CalendarAssistant.Authentication;

public sealed class AuthenticationConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Moment42.CalendarAssistant.Core.Authentication;
namespace Moment42.CalendarAssistant.Authentication;

internal static class OAuthProviders
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>Moment42.CalendarAssistant.Core</AssemblyName>
<RootNamespace>Moment42.CalendarAssistant.Core</RootNamespace>
<AssemblyName>Moment42.CalendarAssistant</AssemblyName>
<RootNamespace>Moment42.CalendarAssistant</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Moment42.CalendarAssistant.Core.Conversations.AdaptiveCards;
namespace Moment42.CalendarAssistant.Conversations.AdaptiveCards;

public sealed class AdaptiveCardProvider(string folderPath)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Moment42.CalendarAssistant.Core.AI.Actions.CreateEvent;
using Moment42.CalendarAssistant.AI.Actions.CreateEvent;

namespace Moment42.CalendarAssistant.Core.Conversations.AdaptiveCards.Contracts;
namespace Moment42.CalendarAssistant.Conversations.AdaptiveCards.Contracts;

internal record CreateEventConfirmation(string EventId, CreateEventParameters CreateEventParameters, string Time, bool HasAttendees);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Moment42.CalendarAssistant.Core.Conversations.AdaptiveCards.Contracts;
namespace Moment42.CalendarAssistant.Conversations.AdaptiveCards.Contracts;

internal record CreateEventResult(string Title, string Time, string? Location, string Url);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Moment42.CalendarAssistant.Core.Conversations.AdaptiveCards.Contracts;
namespace Moment42.CalendarAssistant.Conversations.AdaptiveCards.Contracts;

internal record WelcomeMessage(string Title, string Message);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Bot.Schema;
using Newtonsoft.Json.Linq;

namespace Moment42.CalendarAssistant.Core.Conversations.Application;
namespace Moment42.CalendarAssistant.Conversations.Application;

internal abstract class AdaptiveCardActionRoute(string verb) : Route
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using Moment42.CalendarAssistant.Core.AI;
using Moment42.CalendarAssistant.Core.Conversations.Authentication;
using Moment42.CalendarAssistant.AI;
using Moment42.CalendarAssistant.Conversations.Authentication;
using IndexOutOfRangeException = System.IndexOutOfRangeException;

namespace Moment42.CalendarAssistant.Core.Conversations.Application;
namespace Moment42.CalendarAssistant.Conversations.Application;

internal class ConversationApplication(
IStorage storage,
Expand Down
Loading

0 comments on commit e6020cb

Please sign in to comment.