From d60730c4bf0aefa818a6ab770541e5764fd322b6 Mon Sep 17 00:00:00 2001 From: TomiEckert Date: Thu, 26 Feb 2026 21:51:36 +0100 Subject: [PATCH] Refactor: Reorganize project structure by moving core components into dedicated directories and introducing new configuration and API models. --- GroqApiClient.cs => Api/GroqApiClient.cs | 39 ++----------------- Api/Models/LlamaModels.cs | 33 ++++++++++++++++ Api/Models/WhisperResponse.cs | 9 +++++ AudioRecorder.cs => Audio/AudioRecorder.cs | 5 ++- .../ConfigManager.cs | 18 +-------- Configuration/ToakConfig.cs | 16 ++++++++ PromptBuilder.cs => Core/PromptBuilder.cs | 4 +- StateTracker.cs => Core/StateTracker.cs | 2 +- ClipboardManager.cs => IO/ClipboardManager.cs | 2 +- Notifications.cs => IO/Notifications.cs | 2 +- TextInjector.cs => IO/TextInjector.cs | 2 +- Program.cs | 6 ++- .../AppJsonSerializerContext.cs | 5 ++- 13 files changed, 83 insertions(+), 60 deletions(-) rename GroqApiClient.cs => Api/GroqApiClient.cs (77%) create mode 100644 Api/Models/LlamaModels.cs create mode 100644 Api/Models/WhisperResponse.cs rename AudioRecorder.cs => Audio/AudioRecorder.cs (97%) rename ConfigManager.cs => Configuration/ConfigManager.cs (61%) create mode 100644 Configuration/ToakConfig.cs rename PromptBuilder.cs => Core/PromptBuilder.cs (98%) rename StateTracker.cs => Core/StateTracker.cs (97%) rename ClipboardManager.cs => IO/ClipboardManager.cs (98%) rename Notifications.cs => IO/Notifications.cs (96%) rename TextInjector.cs => IO/TextInjector.cs (98%) rename AppJsonSerializerContext.cs => Serialization/AppJsonSerializerContext.cs (87%) diff --git a/GroqApiClient.cs b/Api/GroqApiClient.cs similarity index 77% rename from GroqApiClient.cs rename to Api/GroqApiClient.cs index f90de8c..077eaff 100644 --- a/GroqApiClient.cs +++ b/Api/GroqApiClient.cs @@ -2,43 +2,10 @@ using System.Net.Http.Headers; using System.Text.Json; using System.Text.Json.Serialization; -namespace Toak; +using Toak.Api.Models; +using Toak.Serialization; -public class WhisperResponse -{ - [JsonPropertyName("text")] - public string Text { get; set; } = string.Empty; -} - -public class LlamaRequestMessage -{ - [JsonPropertyName("role")] - public string Role { get; set; } = string.Empty; - [JsonPropertyName("content")] - public string Content { get; set; } = string.Empty; -} - -public class LlamaRequest -{ - [JsonPropertyName("model")] - public string Model { get; set; } = "llama-3.1-8b-instant"; - [JsonPropertyName("messages")] - public LlamaRequestMessage[] Messages { get; set; } = Array.Empty(); - [JsonPropertyName("temperature")] - public double Temperature { get; set; } = 0.0; -} - -public class LlamaResponse -{ - [JsonPropertyName("choices")] - public LlamaChoice[] Choices { get; set; } = Array.Empty(); -} - -public class LlamaChoice -{ - [JsonPropertyName("message")] - public LlamaRequestMessage Message { get; set; } = new(); -} +namespace Toak.Api; public class GroqApiClient { diff --git a/Api/Models/LlamaModels.cs b/Api/Models/LlamaModels.cs new file mode 100644 index 0000000..405bfac --- /dev/null +++ b/Api/Models/LlamaModels.cs @@ -0,0 +1,33 @@ +using System.Text.Json.Serialization; + +namespace Toak.Api.Models; + +public class LlamaRequestMessage +{ + [JsonPropertyName("role")] + public string Role { get; set; } = string.Empty; + [JsonPropertyName("content")] + public string Content { get; set; } = string.Empty; +} + +public class LlamaRequest +{ + [JsonPropertyName("model")] + public string Model { get; set; } = "llama-3.1-8b-instant"; + [JsonPropertyName("messages")] + public LlamaRequestMessage[] Messages { get; set; } = Array.Empty(); + [JsonPropertyName("temperature")] + public double Temperature { get; set; } = 0.0; +} + +public class LlamaResponse +{ + [JsonPropertyName("choices")] + public LlamaChoice[] Choices { get; set; } = Array.Empty(); +} + +public class LlamaChoice +{ + [JsonPropertyName("message")] + public LlamaRequestMessage Message { get; set; } = new(); +} diff --git a/Api/Models/WhisperResponse.cs b/Api/Models/WhisperResponse.cs new file mode 100644 index 0000000..ec648c2 --- /dev/null +++ b/Api/Models/WhisperResponse.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace Toak.Api.Models; + +public class WhisperResponse +{ + [JsonPropertyName("text")] + public string Text { get; set; } = string.Empty; +} diff --git a/AudioRecorder.cs b/Audio/AudioRecorder.cs similarity index 97% rename from AudioRecorder.cs rename to Audio/AudioRecorder.cs index 597252c..2c02142 100644 --- a/AudioRecorder.cs +++ b/Audio/AudioRecorder.cs @@ -1,6 +1,9 @@ using System.Diagnostics; -namespace Toak; +using Toak.Core; +using Toak.IO; + +namespace Toak.Audio; public static class AudioRecorder { diff --git a/ConfigManager.cs b/Configuration/ConfigManager.cs similarity index 61% rename from ConfigManager.cs rename to Configuration/ConfigManager.cs index 69dbdcd..69be953 100644 --- a/ConfigManager.cs +++ b/Configuration/ConfigManager.cs @@ -1,23 +1,9 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace Toak; - -public class ToakConfig -{ - public string GroqApiKey { get; set; } = string.Empty; - public string TypingBackend { get; set; } = "xdotool"; // wtype or xdotool - public bool ModulePunctuation { get; set; } = true; - public bool ModuleTechnicalSanitization { get; set; } = true; - public string StyleMode { get; set; } = "Professional"; - public bool StructureBulletPoints { get; set; } = false; - public bool StructureSmartParagraphing { get; set; } = true; - - public string WhisperLanguage { get; set; } = string.Empty; - public string LlmModel { get; set; } = "openai/gpt-oss-20b"; - public string WhisperModel { get; set; } = "whisper-large-v3-turbo"; -} +using Toak.Serialization; +namespace Toak.Configuration; public static class ConfigManager { private static readonly string ConfigDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config", "toak"); diff --git a/Configuration/ToakConfig.cs b/Configuration/ToakConfig.cs new file mode 100644 index 0000000..2c54f2c --- /dev/null +++ b/Configuration/ToakConfig.cs @@ -0,0 +1,16 @@ +namespace Toak.Configuration; + +public class ToakConfig +{ + public string GroqApiKey { get; set; } = string.Empty; + public string TypingBackend { get; set; } = "xdotool"; // wtype or xdotool + public bool ModulePunctuation { get; set; } = true; + public bool ModuleTechnicalSanitization { get; set; } = true; + public string StyleMode { get; set; } = "Professional"; + public bool StructureBulletPoints { get; set; } = false; + public bool StructureSmartParagraphing { get; set; } = true; + + public string WhisperLanguage { get; set; } = string.Empty; + public string LlmModel { get; set; } = "openai/gpt-oss-20b"; + public string WhisperModel { get; set; } = "whisper-large-v3-turbo"; +} diff --git a/PromptBuilder.cs b/Core/PromptBuilder.cs similarity index 98% rename from PromptBuilder.cs rename to Core/PromptBuilder.cs index a87bf6c..4e8077d 100644 --- a/PromptBuilder.cs +++ b/Core/PromptBuilder.cs @@ -1,6 +1,8 @@ using System.Text; -namespace Toak; +using Toak.Configuration; + +namespace Toak.Core; public static class PromptBuilder { diff --git a/StateTracker.cs b/Core/StateTracker.cs similarity index 97% rename from StateTracker.cs rename to Core/StateTracker.cs index 31b0bbd..5d22d44 100644 --- a/StateTracker.cs +++ b/Core/StateTracker.cs @@ -1,4 +1,4 @@ -namespace Toak; +namespace Toak.Core; public static class StateTracker { diff --git a/ClipboardManager.cs b/IO/ClipboardManager.cs similarity index 98% rename from ClipboardManager.cs rename to IO/ClipboardManager.cs index 216ef40..1bdb873 100644 --- a/ClipboardManager.cs +++ b/IO/ClipboardManager.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace Toak; +namespace Toak.IO; public static class ClipboardManager { diff --git a/Notifications.cs b/IO/Notifications.cs similarity index 96% rename from Notifications.cs rename to IO/Notifications.cs index a4b0475..2397b40 100644 --- a/Notifications.cs +++ b/IO/Notifications.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace Toak; +namespace Toak.IO; public static class Notifications { diff --git a/TextInjector.cs b/IO/TextInjector.cs similarity index 98% rename from TextInjector.cs rename to IO/TextInjector.cs index ca44363..1844358 100644 --- a/TextInjector.cs +++ b/IO/TextInjector.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace Toak; +namespace Toak.IO; public static class TextInjector { diff --git a/Program.cs b/Program.cs index 288a735..f4ecf7d 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,9 @@ using System.Diagnostics; -using Toak; +using Toak.Audio; +using Toak.Configuration; +using Toak.Api; +using Toak.Core; +using Toak.IO; bool pipeToStdout = args.Contains("--pipe") || args.Contains("-p") || Console.IsOutputRedirected; bool copyToClipboard = args.Contains("--copy"); diff --git a/AppJsonSerializerContext.cs b/Serialization/AppJsonSerializerContext.cs similarity index 87% rename from AppJsonSerializerContext.cs rename to Serialization/AppJsonSerializerContext.cs index dc56eea..b06ab97 100644 --- a/AppJsonSerializerContext.cs +++ b/Serialization/AppJsonSerializerContext.cs @@ -1,6 +1,9 @@ using System.Text.Json.Serialization; -namespace Toak; +using Toak.Configuration; +using Toak.Api.Models; + +namespace Toak.Serialization; [JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] [JsonSerializable(typeof(ToakConfig))]