Compare commits

...

7 Commits

Author SHA1 Message Date
83b1cb397d adding gitea service 2026-03-26 19:36:25 -03:00
76cdb9654e adding rollout to pipelines
Some checks failed
Mindforge Cronjob Build and Deploy / Build Mindforge Cronjob Image (push) Failing after 1m51s
Mindforge Cronjob Build and Deploy / Deploy Mindforge Cronjob (internal) (push) Has been skipped
Mindforge API Build and Deploy / Build Mindforge API Image (push) Failing after 2m46s
Mindforge API Build and Deploy / Deploy Mindforge API (internal) (push) Has been skipped
Mindforge Web Build and Deploy (internal) / Build Mindforge Web Image (push) Successful in 4m50s
Mindforge Web Build and Deploy (internal) / Deploy Mindforge Web (internal) (push) Successful in 45s
2026-03-21 20:09:05 -03:00
3e09b03753 adding new mindforge applications
All checks were successful
Mindforge API Build and Deploy / Build Mindforge API Image (push) Successful in 1m8s
Mindforge Cronjob Build and Deploy / Build Mindforge Cronjob Image (push) Successful in 1m19s
Mindforge API Build and Deploy / Deploy Mindforge API (internal) (push) Successful in 11s
Mindforge Cronjob Build and Deploy / Deploy Mindforge Cronjob (internal) (push) Successful in 10s
Mindforge Web Build and Deploy (internal) / Build Mindforge Web Image (push) Successful in 2m25s
Mindforge Web Build and Deploy (internal) / Deploy Mindforge Web (internal) (push) Successful in 12s
2026-03-20 22:51:04 -03:00
36e405a9a8 Merge branch 'claude/dazzling-visvesvaraya'
Some checks failed
Mindforge API Build and Deploy / Build Mindforge API Image (push) Failing after 17s
Mindforge API Build and Deploy / Deploy Mindforge API (internal) (push) Has been skipped
Mindforge Web Build and Deploy / Build Mindforge Web Image (push) Failing after 18s
Mindforge Web Build and Deploy / Deploy Mindforge Web (internal) (push) Has been skipped
Mindforge Cronjob Build and Deploy / Build Mindforge Cronjob Image (push) Successful in 41s
Mindforge Cronjob Build and Deploy / Deploy Mindforge Cronjob (internal) (push) Successful in 10s
2026-03-20 21:26:12 -03:00
794e314fa7 adding new project pipelines 2026-03-20 21:26:05 -03:00
afff091457 adding top_n_files
All checks were successful
Mindforge Cronjob Build and Deploy / Build Mindforge Cronjob Image (push) Successful in 1m19s
Mindforge Cronjob Build and Deploy / Deploy Mindforge Cronjob (internal) (push) Successful in 43s
2026-03-20 21:25:19 -03:00
510abaa358 adding claude to gitignore 2026-03-20 11:03:18 -03:00
69 changed files with 5043 additions and 8 deletions

View File

@@ -0,0 +1,89 @@
name: Mindforge API Build and Deploy
on:
push:
branches:
- main
paths:
- "Mindforge.API/**"
- ".gitea/workflows/**"
workflow_dispatch: {}
env:
REGISTRY_HOST: git.ivanch.me
REGISTRY_USERNAME: ivanch
IMAGE_API: ${{ env.REGISTRY_HOST }}/ivanch/mindforge-api
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
jobs:
build_mindforge_api:
name: Build Mindforge API Image
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Log in to Container Registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" \
| docker login "${{ env.REGISTRY_HOST }}" \
-u "${{ env.REGISTRY_USERNAME }}" \
--password-stdin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push Multi-Arch Image
uses: docker/build-push-action@v6
with:
push: true
context: Mindforge.API
platforms: linux/amd64,linux/arm64
tags: |
${{ env.IMAGE_API }}:latest
deploy_mindforge_api:
name: Deploy Mindforge API (internal)
runs-on: ubuntu-amd64
needs: build_mindforge_api
steps:
- name: Check KUBE_CONFIG validity
run: |
if [ -z "${KUBE_CONFIG}" ] || [ "${KUBE_CONFIG}" = "" ] || [ "${KUBE_CONFIG// }" = "" ]; then
echo "KUBE_CONFIG is not set or is empty."
exit 1
fi
- name: Check out repository
uses: actions/checkout@v2
- name: Download and install dependencies
run: |
apt-get update -y
apt-get install -y curl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
install -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
- name: Set up kubeconfig
run: |
cd Mindforge.API/deploy
echo "$KUBE_CONFIG" > kubeconfig.yaml
env:
KUBE_CONFIG: ${{ env.KUBE_CONFIG }}
- name: Check connection to cluster
run: |
cd Mindforge.API/deploy
kubectl --kubeconfig=kubeconfig.yaml cluster-info
- name: Apply mindforge-api deployment
run: |
cd Mindforge.API/deploy
kubectl --kubeconfig=kubeconfig.yaml apply -f mindforge-api.yaml
- name: Rollout restart
run: |
cd Mindforge.API/deploy
kubectl --kubeconfig=kubeconfig.yaml rollout restart deployment mindforge-api -n mindforge

View File

@@ -0,0 +1,92 @@
name: Mindforge Web Build and Deploy (internal)
on:
push:
branches:
- main
paths:
- "Mindforge.Web/**"
- ".gitea/workflows/**"
workflow_dispatch: {}
env:
REGISTRY_HOST: git.ivanch.me
REGISTRY_USERNAME: ivanch
IMAGE_WEB: ${{ env.REGISTRY_HOST }}/ivanch/mindforge-web
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
VITE_API_BASE_URL: http://api.mindforge.haven
jobs:
build_mindforge_web:
name: Build Mindforge Web Image
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Log in to Container Registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" \
| docker login "${{ env.REGISTRY_HOST }}" \
-u "${{ env.REGISTRY_USERNAME }}" \
--password-stdin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push Multi-Arch Image
uses: docker/build-push-action@v6
with:
push: true
context: Mindforge.Web
platforms: linux/amd64,linux/arm64
build-args: |
VITE_API_BASE_URL=${{ env.VITE_API_BASE_URL }}
tags: |
${{ env.IMAGE_WEB }}:latest
deploy_mindforge_web:
name: Deploy Mindforge Web (internal)
runs-on: ubuntu-amd64
needs: build_mindforge_web
steps:
- name: Check KUBE_CONFIG validity
run: |
if [ -z "${KUBE_CONFIG}" ] || [ "${KUBE_CONFIG}" = "" ] || [ "${KUBE_CONFIG// }" = "" ]; then
echo "KUBE_CONFIG is not set or is empty."
exit 1
fi
- name: Check out repository
uses: actions/checkout@v2
- name: Download and install dependencies
run: |
apt-get update -y
apt-get install -y curl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
install -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
- name: Set up kubeconfig
run: |
cd Mindforge.Web/deploy
echo "$KUBE_CONFIG" > kubeconfig.yaml
env:
KUBE_CONFIG: ${{ env.KUBE_CONFIG }}
- name: Check connection to cluster
run: |
cd Mindforge.Web/deploy
kubectl --kubeconfig=kubeconfig.yaml cluster-info
- name: Apply mindforge-web deployment
run: |
cd Mindforge.Web/deploy
kubectl --kubeconfig=kubeconfig.yaml apply -f mindforge-web.yaml
- name: Rollout restart
run: |
cd Mindforge.Web/deploy
kubectl --kubeconfig=kubeconfig.yaml rollout restart deployment mindforge-web -n mindforge

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.claude/
_bmad*

3
Mindforge.API/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
bin
obj
appsettings.Development.json

View File

@@ -0,0 +1,43 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Mindforge.API.Exceptions;
using Mindforge.API.Models.Requests;
using Mindforge.API.Services.Interfaces;
namespace Mindforge.API.Controllers
{
[ApiController]
[Route("api/v1/file")]
public class FileController : ControllerBase
{
private readonly IFileService _fileService;
public FileController(IFileService fileService)
{
_fileService = fileService;
}
[HttpPost("check")]
public async Task<IActionResult> CheckFile([FromBody] FileCheckRequest request)
{
if (string.IsNullOrWhiteSpace(request.FileContent) || string.IsNullOrWhiteSpace(request.CheckType))
{
throw new UserException("FileContent and CheckType are required.");
}
try
{
var base64Bytes = Convert.FromBase64String(request.FileContent);
request.FileContent = System.Text.Encoding.UTF8.GetString(base64Bytes);
}
catch (FormatException)
{
throw new UserException("FileContent must be a valid base64 string.");
}
var response = await _fileService.CheckFileAsync(request);
return Ok(new { result = response });
}
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Mindforge.API.Exceptions;
using Mindforge.API.Models.Requests;
using Mindforge.API.Services.Interfaces;
namespace Mindforge.API.Controllers
{
[ApiController]
[Route("api/v1/flashcard")]
public class FlashcardController : ControllerBase
{
private readonly IFlashcardService _flashcardService;
public FlashcardController(IFlashcardService flashcardService)
{
_flashcardService = flashcardService;
}
[HttpPost("generate")]
public async Task<IActionResult> Generate([FromBody] FlashcardGenerateRequest request)
{
if (string.IsNullOrWhiteSpace(request.FileContent) || request.Amount <= 0)
{
throw new UserException("FileContent is required and Amount must be greater than 0.");
}
try
{
var base64Bytes = Convert.FromBase64String(request.FileContent);
request.FileContent = System.Text.Encoding.UTF8.GetString(base64Bytes);
}
catch (FormatException)
{
throw new UserException("FileContent must be a valid base64 string.");
}
var response = await _flashcardService.GenerateFlashcardsAsync(request);
return Ok(new { result = response });
}
}
}

View File

@@ -0,0 +1,40 @@
using Microsoft.AspNetCore.Mvc;
using Mindforge.API.Services.Interfaces;
namespace Mindforge.API.Controllers
{
[ApiController]
[Route("api/v1/repository")]
public class RepositoryController : ControllerBase
{
private readonly IGiteaService _giteaService;
public RepositoryController(IGiteaService giteaService)
{
_giteaService = giteaService;
}
[HttpGet("info")]
public IActionResult GetInfo()
{
return Ok(new { name = _giteaService.GetRepositoryName() });
}
[HttpGet("tree")]
public async Task<IActionResult> GetTree()
{
var tree = await _giteaService.GetFileTreeAsync();
return Ok(tree);
}
[HttpGet("file")]
public async Task<IActionResult> GetFile([FromQuery] string path)
{
if (string.IsNullOrWhiteSpace(path))
return BadRequest(new { error = "path query parameter is required." });
var content = await _giteaService.GetFileContentAsync(path);
return Ok(new { path, content });
}
}
}

21
Mindforge.API/Dockerfile Normal file
View File

@@ -0,0 +1,21 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS builder
ARG TARGETARCH
ARG TARGETOS
WORKDIR /app
COPY Mindforge.API.csproj ./
RUN dotnet restore -a $TARGETARCH
COPY . .
RUN dotnet publish -c Release -a $TARGETARCH --no-restore -o /app/publish
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine
WORKDIR /app
COPY --from=builder /app/publish .
ENV ASPNETCORE_URLS=http://+:8080
ENV OPENAI_API_KEY=""
ENV GEMINI_API_KEY=""
EXPOSE 8080
ENTRYPOINT ["dotnet", "Mindforge.API.dll"]

View File

@@ -0,0 +1,11 @@
using System;
namespace Mindforge.API.Exceptions
{
public class UserException : Exception
{
public UserException(string message) : base(message)
{
}
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Mindforge.API.Exceptions;
namespace Mindforge.API.Middlewares
{
public class ExceptionHandlingMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger<ExceptionHandlingMiddleware> _logger;
public ExceptionHandlingMiddleware(RequestDelegate next, ILogger<ExceptionHandlingMiddleware> logger)
{
_next = next;
_logger = logger;
}
public async Task InvokeAsync(HttpContext context)
{
try
{
await _next(context);
}
catch (UserException ex)
{
_logger.LogWarning(ex, "User error");
await HandleExceptionAsync(context, StatusCodes.Status400BadRequest, ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "Internal server error");
await HandleExceptionAsync(context, StatusCodes.Status500InternalServerError, $"Internal server error: {ex.Message}");
}
}
private static Task HandleExceptionAsync(HttpContext context, int statusCode, string message)
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = statusCode;
var result = JsonSerializer.Serialize(new { error = message });
return context.Response.WriteAsync(result);
}
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.12" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
@Mindforge.API_HostAddress = http://localhost:5123
GET {{Mindforge.API_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@@ -0,0 +1,8 @@
namespace Mindforge.API.Models.Enums
{
public enum LlmProvider
{
OpenAI,
Gemini
}
}

View File

@@ -0,0 +1,10 @@
namespace Mindforge.API.Models
{
public class FileTreeNode
{
public string Name { get; set; } = "";
public string Path { get; set; } = "";
public string Type { get; set; } = ""; // "file" | "folder"
public List<FileTreeNode>? Children { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
namespace Mindforge.API.Models.Requests
{
public class FileCheckRequest
{
public string FileContent { get; set; } = string.Empty;
public string FileName { get; set; } = string.Empty;
/// <summary>
/// Expected values: "language" or "content"
/// </summary>
public string CheckType { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,21 @@
using System.Text.Json.Serialization;
namespace Mindforge.API.Models.Requests
{
public class FlashcardGenerateRequest
{
public string FileContent { get; set; } = string.Empty;
public string FileName { get; set; } = string.Empty;
public int Amount { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public FlashcardMode? Mode { get; set; } = FlashcardMode.Simple;
}
public enum FlashcardMode
{
Basic,
Simple,
Detailed,
Hyper
}
}

88
Mindforge.API/Program.cs Normal file
View File

@@ -0,0 +1,88 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Mindforge.API.Providers;
using Mindforge.API.Services;
using Mindforge.API.Services.Interfaces;
var builder = WebApplication.CreateBuilder(args);
// Ensure environment variables are loaded into IConfiguration
builder.Configuration.AddEnvironmentVariables();
// Add services to the container.
builder.Services.AddControllers();
builder.Logging.AddConsole();
builder.Logging.AddDebug();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
// Configure CORS
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
// Register HttpClient for providers
builder.Services.AddHttpClient();
// Register Providers
builder.Services.AddScoped<ILlmApiProvider, OpenAIApiProvider>();
builder.Services.AddScoped<ILlmApiProvider, GeminiApiProvider>();
// Register Services
builder.Services.AddScoped<IAgentService, AgentService>();
builder.Services.AddScoped<IFileService, FileService>();
builder.Services.AddScoped<IFlashcardService, FlashcardService>();
builder.Services.AddScoped<IGiteaService, GiteaService>();
var app = builder.Build();
app.UseCors("AllowAll");
app.UseMiddleware<Mindforge.API.Middlewares.ExceptionHandlingMiddleware>();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
// Check for env vars
var openAiKey = builder.Configuration["OPENAI_API_KEY"];
var geminiKey = builder.Configuration["GEMINI_API_KEY"];
if (string.IsNullOrEmpty(openAiKey))
{
app.Logger.LogWarning("OPENAI_API_KEY not found in configuration.");
}
if (string.IsNullOrEmpty(geminiKey))
{
app.Logger.LogWarning("GEMINI_API_KEY not found in configuration.");
}
var giteaRepoUrl = builder.Configuration["GITEA_REPO_URL"];
var giteaAccessToken = builder.Configuration["GITEA_ACCESS_TOKEN"];
if (string.IsNullOrEmpty(giteaRepoUrl))
{
app.Logger.LogWarning("GITEA_REPO_URL not found in configuration. Repository features will not work.");
}
if (string.IsNullOrEmpty(giteaAccessToken))
{
app.Logger.LogWarning("GITEA_ACCESS_TOKEN not found in configuration. Repository features will not work.");
}
app.Run();

View File

@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5123",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7116;http://localhost:5123",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,202 @@
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
namespace Mindforge.API.Providers
{
public class GeminiApiProvider : ILlmApiProvider
{
private readonly HttpClient _httpClient;
private readonly IConfiguration _configuration;
private readonly ILogger<GeminiApiProvider> _logger;
public GeminiApiProvider(HttpClient httpClient, IConfiguration configuration, ILogger<GeminiApiProvider> logger)
{
_httpClient = httpClient;
_httpClient.Timeout = TimeSpan.FromMinutes(5);
_configuration = configuration;
_logger = logger;
}
public async Task<string> SendRequestAsync(string systemPrompt, string userPrompt, string model)
{
var apiKey = _configuration["GEMINI_API_KEY"];
if (string.IsNullOrEmpty(apiKey))
{
throw new Exception("GEMINI_API_KEY not found in configuration.");
}
var apiBase = "https://generativelanguage.googleapis.com/v1beta";
var url = $"{apiBase.TrimEnd('/')}/models/{model}:generateContent?key={apiKey}";
var reqBody = new
{
system_instruction = string.IsNullOrEmpty(systemPrompt) ? null : new
{
parts = new[] { new { text = systemPrompt } }
},
contents = new[]
{
new
{
role = "user",
parts = new[] { new { text = userPrompt } }
}
}
};
var jsonBody = JsonSerializer.Serialize(reqBody, new JsonSerializerOptions { DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull });
using var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
var response = await _httpClient.SendAsync(request);
var responseBody = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
throw new Exception($"Gemini API error status {(int)response.StatusCode}: {responseBody}");
}
var result = JsonSerializer.Deserialize<JsonElement>(responseBody);
if (result.TryGetProperty("candidates", out var candidates) && candidates.GetArrayLength() > 0)
{
var content = candidates[0].GetProperty("content");
if (content.TryGetProperty("parts", out var parts) && parts.GetArrayLength() > 0)
{
return parts[0].GetProperty("text").GetString() ?? string.Empty;
}
}
throw new Exception("empty response from Gemini API");
}
public async Task<string> SendRequestBatchAsync(string systemPrompt, string userPrompt, string model)
{
var apiKey = _configuration["GEMINI_API_KEY"];
if (string.IsNullOrEmpty(apiKey))
throw new Exception("GEMINI_API_KEY not found in configuration.");
var apiBase = "https://generativelanguage.googleapis.com/v1beta";
var jsonOptions = new JsonSerializerOptions { DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull };
// Build single inline request
var batchBody = new
{
batch = new
{
display_name = "mindforge-batch",
input_config = new
{
requests = new
{
requests = new[]
{
new
{
request = new
{
system_instruction = string.IsNullOrEmpty(systemPrompt) ? null : new
{
parts = new[] { new { text = systemPrompt } }
},
contents = new[]
{
new
{
role = "user",
parts = new[] { new { text = userPrompt } }
}
}
},
metadata = new { key = "request-1" }
}
}
}
}
}
};
// Submit batch job
var createUrl = $"{apiBase}/models/{model}:batchGenerateContent?key={apiKey}";
using var createReq = new HttpRequestMessage(HttpMethod.Post, createUrl);
createReq.Content = new StringContent(JsonSerializer.Serialize(batchBody, jsonOptions), Encoding.UTF8, "application/json");
var createResp = await _httpClient.SendAsync(createReq);
var createBody = await createResp.Content.ReadAsStringAsync();
if (!createResp.IsSuccessStatusCode)
throw new Exception($"Gemini Batch API error creating job {(int)createResp.StatusCode}: {createBody}");
_logger.LogInformation("Gemini Batch API job created");
var createResult = JsonSerializer.Deserialize<JsonElement>(createBody);
if (!createResult.TryGetProperty("name", out var nameEl))
throw new Exception("Gemini Batch API did not return a job name.");
var batchName = nameEl.GetString()!;
var pollUrl = $"{apiBase}/{batchName}?key={apiKey}";
_logger.LogInformation("Gemini Batch API job name: {BatchName}", batchName);
// Poll until terminal state
while (true)
{
await Task.Delay(TimeSpan.FromSeconds(10));
using var pollReq = new HttpRequestMessage(HttpMethod.Get, pollUrl);
var pollResp = await _httpClient.SendAsync(pollReq);
var pollBody = await pollResp.Content.ReadAsStringAsync();
if (!pollResp.IsSuccessStatusCode)
throw new Exception($"Gemini Batch API error polling status {(int)pollResp.StatusCode}: {pollBody}");
var pollResult = JsonSerializer.Deserialize<JsonElement>(pollBody);
var metadata = pollResult.GetProperty("metadata");
var state = metadata.GetProperty("state");
_logger.LogInformation("Gemini Batch API job state: {State}", state.GetString());
switch (state.GetString())
{
case "BATCH_STATE_SUCCEEDED":
if (pollResult.TryGetProperty("response", out var batchResponse) &&
batchResponse.TryGetProperty("inlinedResponses", out var inlinedResponses) &&
inlinedResponses.TryGetProperty("inlinedResponses", out var inlinedResponsesInternal) &&
inlinedResponsesInternal.GetArrayLength() > 0)
{
_logger.LogInformation("Gemini Batch API job succeeded");
var first = inlinedResponsesInternal[0];
if (first.TryGetProperty("error", out var reqError))
throw new Exception($"Gemini Batch request error: {reqError}");
if (first.TryGetProperty("response", out var innerResponse) &&
innerResponse.TryGetProperty("candidates", out var candidates) &&
candidates.GetArrayLength() > 0)
{
var content = candidates[0].GetProperty("content");
if (content.TryGetProperty("parts", out var parts) && parts.GetArrayLength() > 0)
return parts[0].GetProperty("text").GetString() ?? string.Empty;
}
}
throw new Exception("Gemini Batch job succeeded but returned no content.");
case "BATCH_STATE_FAILED":
throw new Exception($"Gemini Batch job failed: {pollBody}");
case "BATCH_STATE_CANCELLED":
throw new Exception("Gemini Batch job was cancelled.");
case "BATCH_STATE_EXPIRED":
throw new Exception("Gemini Batch job expired before completing.");
// BATCH_STATE_PENDING / BATCH_STATE_RUNNING — keep polling
}
}
}
}
}

View File

@@ -0,0 +1,10 @@
using System.Threading.Tasks;
namespace Mindforge.API.Providers
{
public interface ILlmApiProvider
{
Task<string> SendRequestAsync(string systemPrompt, string userPrompt, string model);
Task<string> SendRequestBatchAsync(string systemPrompt, string userPrompt, string model);
}
}

View File

@@ -0,0 +1,110 @@
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
namespace Mindforge.API.Providers
{
public class OpenAIApiProvider : ILlmApiProvider
{
private readonly HttpClient _httpClient;
private readonly IConfiguration _configuration;
private readonly ILogger<OpenAIApiProvider> _logger;
public OpenAIApiProvider(HttpClient httpClient, IConfiguration configuration, ILogger<OpenAIApiProvider> logger)
{
_httpClient = httpClient;
_httpClient.Timeout = TimeSpan.FromMinutes(5);
_configuration = configuration;
_logger = logger;
}
public async Task<string> SendRequestAsync(string systemPrompt, string userPrompt, string model)
{
var apiKey = _configuration["OPENAI_API_KEY"];
if (string.IsNullOrEmpty(apiKey))
{
throw new Exception("OPENAI_API_KEY not found in configuration.");
}
var apiBase = "https://api.openai.com/v1";
var url = $"{apiBase.TrimEnd('/')}/responses";
var reqBody = new
{
model = model,
input = new[]
{
new { role = "developer", content = systemPrompt },
new { role = "user", content = userPrompt }
},
reasoning = new
{
effort = "low"
}
};
var jsonBody = JsonSerializer.Serialize(reqBody);
Exception? lastErr = null;
for (int i = 0; i < 5; i++)
{
using var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
request.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
try
{
var response = await _httpClient.SendAsync(request);
var responseBody = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
lastErr = new Exception($"OpenAI API error status {(int)response.StatusCode}: {responseBody}");
await Task.Delay(TimeSpan.FromSeconds(1 << i));
continue;
}
var result = JsonSerializer.Deserialize<JsonElement>(responseBody);
if (result.TryGetProperty("output", out var outputArray))
{
foreach (var outputItem in outputArray.EnumerateArray())
{
if (outputItem.TryGetProperty("content", out var contentArray))
{
foreach (var contentItem in contentArray.EnumerateArray())
{
if (contentItem.TryGetProperty("text", out var textContent))
{
return textContent.GetString() ?? string.Empty;
}
}
}
}
}
_logger.LogWarning("OpenAI API raw response: {responseBody}", responseBody);
throw new Exception("empty response from OpenAI API");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in OpenAI API request");
lastErr = ex;
await Task.Delay(TimeSpan.FromSeconds(1 << i));
}
}
throw new Exception($"failed to get OpenAI response after 5 attempts. Last error: {lastErr?.Message}", lastErr);
}
public async Task<string> SendRequestBatchAsync(string systemPrompt, string userPrompt, string model)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Mindforge.API.Models.Enums;
using Mindforge.API.Providers;
using Mindforge.API.Services.Interfaces;
namespace Mindforge.API.Services
{
public class AgentService : IAgentService
{
private readonly IEnumerable<ILlmApiProvider> _providers;
public AgentService(IEnumerable<ILlmApiProvider> providers)
{
_providers = providers;
}
public Task<string> ProcessRequestAsync(LlmProvider providerEnum, string systemPrompt, string userPrompt, string model)
{
ILlmApiProvider provider = providerEnum switch
{
LlmProvider.OpenAI => _providers.OfType<OpenAIApiProvider>().FirstOrDefault()
?? throw new Exception("OpenAI provider not registered"),
LlmProvider.Gemini => _providers.OfType<GeminiApiProvider>().FirstOrDefault()
?? throw new Exception("Gemini provider not registered"),
_ => throw new Exception("Unknown provider")
};
return provider.SendRequestAsync(systemPrompt, userPrompt, model);
}
public Task<string> ProcessRequestBatchAsync(LlmProvider providerEnum, string systemPrompt, string userPrompt, string model)
{
ILlmApiProvider provider = providerEnum switch
{
LlmProvider.OpenAI => _providers.OfType<OpenAIApiProvider>().FirstOrDefault()
?? throw new Exception("OpenAI provider not registered"),
LlmProvider.Gemini => _providers.OfType<GeminiApiProvider>().FirstOrDefault()
?? throw new Exception("Gemini provider not registered"),
_ => throw new Exception("Unknown provider")
};
return provider.SendRequestBatchAsync(systemPrompt, userPrompt, model);
}
}
}

View File

@@ -0,0 +1,61 @@
using System;
using System.Threading.Tasks;
using Mindforge.API.Models.Enums;
using Mindforge.API.Models.Requests;
using Mindforge.API.Services.Interfaces;
using Mindforge.API.Exceptions;
namespace Mindforge.API.Services
{
public class FileService : IFileService
{
private readonly IAgentService _agentService;
private const LlmProvider DefaultProvider = LlmProvider.OpenAI;
private const string DefaultModel = "gpt-5-mini";
public FileService(IAgentService agentService)
{
_agentService = agentService;
}
public async Task<string> CheckFileAsync(FileCheckRequest request)
{
string systemPrompt;
if (request.CheckType.ToLower() == "language")
{
systemPrompt = $@"Você é um revisor de textos sênior e especialista em língua portuguesa do Brasil.
Sua tarefa é analisar o texto fornecido e corrigir rigorosamente todos os erros gramaticais, de concordância, pontuação, garantindo clareza, coesão e fluidez.
Por favor, siga esta estrutura:
1. Retorne o texto completamente revisado e polido.
2. Não adicione nenhum texto adicional, apenas o texto revisado.
3. Não altere o sentido do texto, mantenha a mesma ideia. Apenas corrija os erros gramaticais, de concordância e pontuação.
Responda única e exclusivamente em português do Brasil.
Foque em textos de concursos públicos, principalmente para a banca Cebraspe.";
}
else if (request.CheckType.ToLower() == "content")
{
systemPrompt = $@"Você é um analista de conteúdo experiente, especializado em revisão crítica e verificação de fatos.
Sua tarefa é realizar uma análise rigorosa do texto fornecido, identificando erros lógicos, imprecisões de conteúdo, contradições internas e inconsistências argumentativas.
Por favor, siga esta estrutura:
1. Destaque cada problema encontrado no texto original.
2. Explique detalhadamente por que é um erro ou inconsistência.
3. Apresente sugestões claras e embasadas para reescrever ou corrigir os trechos problemáticos, melhorando a coerência e a lógica e a clareza do conteúdo.
Responda única e exclusivamente em português do Brasil e mantenha um tom analítico e construtivo.
Responda em tópicos para ser apresentados ao usuário, sendo sucinto e não extremamente detalhado.
Os resumos serão utilizados para concursos públicos, principalmente para a banca Cebraspe.
";
}
else
{
throw new UserException("Tipo de verificação inválido. Use 'language' ou 'content'.");
}
string userPrompt = $"Arquivo: {request.FileName}\nConteúdo:\n{request.FileContent}";
return await _agentService.ProcessRequestAsync(DefaultProvider, systemPrompt, userPrompt, DefaultModel);
}
}
}

View File

@@ -0,0 +1,83 @@
using System.Threading.Tasks;
using Mindforge.API.Models.Enums;
using Mindforge.API.Models.Requests;
using Mindforge.API.Services.Interfaces;
namespace Mindforge.API.Services
{
public class FlashcardService : IFlashcardService
{
private readonly IAgentService _agentService;
private readonly ILogger<FlashcardService> _logger;
private const LlmProvider DefaultProvider = LlmProvider.Gemini;
private string DefaultModel = "gemini-3.1-flash-image-preview";
public FlashcardService(IAgentService agentService, ILogger<FlashcardService> logger)
{
_agentService = agentService;
_logger = logger;
}
public async Task<string> GenerateFlashcardsAsync(FlashcardGenerateRequest request)
{
var extraPrompt = "";
switch (request.Mode)
{
case FlashcardMode.Basic:
DefaultModel = "gemini-3.1-flash-lite-preview";
break;
case FlashcardMode.Simple:
DefaultModel = "gemini-3.1-flash-image-preview";
break;
case FlashcardMode.Detailed:
DefaultModel = "gemini-3.1-flash-image-preview";
extraPrompt = "Crie flashcards mais detalhados.";
break;
case FlashcardMode.Hyper:
DefaultModel = "gemini-3.1-pro-preview";
extraPrompt = "Adicione também pequenas questões para fixação, para que o usuário possa testar seus conhecimentos. As questões devem ser curtas e objetivas, como se fosse cobradas em prova mesmo.";
break;
}
string systemPrompt = $@"Você é um assistente educacional especializado em criar flashcards para o Anki.
Baseado no texto fornecido, crie exatamente {request.Amount} flashcards que focam nos conceitos mais importantes e difíceis.
A resposta FINAL deve ser APENAS no formato CSV, pronto para importação no Anki, sem nenhum texto adicional antes ou depois.
O formato CSV deve ter duas colunas: a frente da carta (pergunta/conceito) e o verso (resposta/explicação). Use ponto e vírgula (;) como separador. Não adicione o cabeçalho.
As perguntas e respostas devem estar estritamente em Português do Brasil.
Exemplo de saída:
""Qual é a capital do Brasil?"";""Brasília""
""Qual é a maior cidade do Brasil?"";""São Paulo""
Com base no arquivo fornecido, crie exatamente {request.Amount} flashcards que focam nos conceitos mais importantes e difíceis.
{extraPrompt}
";
string userPrompt = $"Arquivo: {request.FileName}\nConteúdo:\n{request.FileContent}";
//var result = await _agentService.ProcessRequestAsync(DefaultProvider, systemPrompt, userPrompt, DefaultModel);
var result = await _agentService.ProcessRequestBatchAsync(DefaultProvider, systemPrompt, userPrompt, DefaultModel);
var lines = result.Split('\n');
if (lines.Length == 0)
{
throw new Exception("Nenhum flashcard gerado.");
}
if (lines.Length > request.Amount)
{
_logger.LogWarning("Quantidade de flashcards excede o limite.");
}
if (lines.Length < request.Amount)
{
_logger.LogWarning("Quantidade de flashcards abaixo do limite.");
}
return result;
}
}
}

View File

@@ -0,0 +1,165 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Configuration;
using Mindforge.API.Exceptions;
using Mindforge.API.Models;
using Mindforge.API.Services.Interfaces;
namespace Mindforge.API.Services
{
public class GiteaService : IGiteaService
{
private readonly HttpClient _httpClient;
private readonly string _baseUrl;
private readonly string _owner;
private readonly string _repo;
private readonly string _token;
private static readonly JsonSerializerOptions JsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
public GiteaService(HttpClient httpClient, IConfiguration configuration)
{
_httpClient = httpClient;
var repoUrl = configuration["GITEA_REPO_URL"];
if (string.IsNullOrEmpty(repoUrl))
throw new InvalidOperationException("GITEA_REPO_URL is not set in configuration.");
_token = configuration["GITEA_ACCESS_TOKEN"]
?? throw new InvalidOperationException("GITEA_ACCESS_TOKEN is not set in configuration.");
// Parse: https://host/owner/repo or https://host/owner/repo.git
var normalizedUrl = repoUrl.TrimEnd('/').TrimEnd(".git".ToCharArray());
var uri = new Uri(normalizedUrl);
_baseUrl = $"{uri.Scheme}://{uri.Host}{(uri.IsDefaultPort ? "" : $":{uri.Port}")}";
var parts = uri.AbsolutePath.Trim('/').Split('/');
_owner = parts[0];
_repo = parts[1];
}
public string GetRepositoryName() => _repo;
public async Task<List<FileTreeNode>> GetFileTreeAsync()
{
// Get the master branch to obtain the latest commit SHA
var branchJson = await GetApiAsync($"/api/v1/repos/{_owner}/{_repo}/branches/master");
var branch = JsonSerializer.Deserialize<GiteaBranch>(branchJson, JsonOptions)
?? throw new InvalidOperationException("Failed to parse branch response from Gitea.");
var treeSha = branch.Commit.Id;
// Fetch the full recursive tree
var treeJson = await GetApiAsync($"/api/v1/repos/{_owner}/{_repo}/git/trees/{treeSha}?recursive=true");
var treeResponse = JsonSerializer.Deserialize<GiteaTreeResponse>(treeJson, JsonOptions)
?? throw new InvalidOperationException("Failed to parse tree response from Gitea.");
return BuildTree(treeResponse.Tree);
}
public async Task<string> GetFileContentAsync(string path)
{
var request = new HttpRequestMessage(HttpMethod.Get,
$"{_baseUrl}/api/v1/repos/{_owner}/{_repo}/raw/{path}?ref=master");
request.Headers.Add("Authorization", $"token {_token}");
var response = await _httpClient.SendAsync(request);
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
throw new UserException($"File not found in repository: {path}");
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
private async Task<string> GetApiAsync(string endpoint)
{
var request = new HttpRequestMessage(HttpMethod.Get, $"{_baseUrl}{endpoint}");
request.Headers.Add("Authorization", $"token {_token}");
var response = await _httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
private static List<FileTreeNode> BuildTree(List<GiteaTreeItem> items)
{
var root = new List<FileTreeNode>();
var folderMap = new Dictionary<string, FileTreeNode>();
// Only include .md files and their parent folders
var mdFiles = items.Where(i => i.Type == "blob" && i.Path.EndsWith(".md")).ToList();
var neededFolders = new HashSet<string>();
foreach (var file in mdFiles)
{
var dir = System.IO.Path.GetDirectoryName(file.Path)?.Replace('\\', '/');
while (!string.IsNullOrEmpty(dir))
{
neededFolders.Add(dir);
dir = System.IO.Path.GetDirectoryName(dir)?.Replace('\\', '/');
}
}
// Create folder nodes
foreach (var item in items.Where(i => i.Type == "tree" && neededFolders.Contains(i.Path)).OrderBy(i => i.Path))
{
var node = new FileTreeNode
{
Name = System.IO.Path.GetFileName(item.Path),
Path = item.Path,
Type = "folder",
Children = []
};
folderMap[item.Path] = node;
}
// Place file and folder nodes into parent
var allNodes = mdFiles.Select(i => new FileTreeNode
{
Name = System.IO.Path.GetFileName(i.Path),
Path = i.Path,
Type = "file"
}).Concat(folderMap.Values).OrderBy(n => n.Path);
foreach (var node in allNodes)
{
var parentPath = System.IO.Path.GetDirectoryName(node.Path)?.Replace('\\', '/');
if (string.IsNullOrEmpty(parentPath))
root.Add(node);
else if (folderMap.TryGetValue(parentPath, out var parent))
parent.Children!.Add(node);
}
return root;
}
// ---- Gitea API DTOs ----
private class GiteaBranch
{
[JsonPropertyName("commit")]
public GiteaCommit Commit { get; set; } = new();
}
private class GiteaCommit
{
[JsonPropertyName("id")]
public string Id { get; set; } = "";
}
private class GiteaTreeResponse
{
[JsonPropertyName("tree")]
public List<GiteaTreeItem> Tree { get; set; } = [];
}
private class GiteaTreeItem
{
[JsonPropertyName("path")]
public string Path { get; set; } = "";
[JsonPropertyName("type")]
public string Type { get; set; } = ""; // "blob" | "tree"
}
}
}

View File

@@ -0,0 +1,11 @@
using System.Threading.Tasks;
using Mindforge.API.Models.Enums;
namespace Mindforge.API.Services.Interfaces
{
public interface IAgentService
{
Task<string> ProcessRequestAsync(LlmProvider provider, string systemPrompt, string userPrompt, string model);
Task<string> ProcessRequestBatchAsync(LlmProvider provider, string systemPrompt, string userPrompt, string model);
}
}

View File

@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using Mindforge.API.Models.Requests;
namespace Mindforge.API.Services.Interfaces
{
public interface IFileService
{
Task<string> CheckFileAsync(FileCheckRequest request);
}
}

View File

@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using Mindforge.API.Models.Requests;
namespace Mindforge.API.Services.Interfaces
{
public interface IFlashcardService
{
Task<string> GenerateFlashcardsAsync(FlashcardGenerateRequest request);
}
}

View File

@@ -0,0 +1,11 @@
using Mindforge.API.Models;
namespace Mindforge.API.Services.Interfaces
{
public interface IGiteaService
{
Task<List<FileTreeNode>> GetFileTreeAsync();
Task<string> GetFileContentAsync(string path);
string GetRepositoryName();
}
}

View File

@@ -0,0 +1,13 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"OPENAI_API_KEY": "",
"GEMINI_API_KEY": "",
"GITEA_REPO_URL": "",
"GITEA_ACCESS_TOKEN": ""
}

View File

@@ -0,0 +1,82 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mindforge-api
namespace: mindforge
spec:
replicas: 1
selector:
matchLabels:
app: mindforge-api
template:
metadata:
labels:
app: mindforge-api
spec:
containers:
- name: mindforge-api
image: git.ivanch.me/ivanch/mindforge-api:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
env:
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: mindforge-secrets
key: OPENAI_API_KEY
- name: GEMINI_API_KEY
valueFrom:
secretKeyRef:
name: mindforge-secrets
key: GEMINI_API_KEY
- name: GITEA_REPO_URL
valueFrom:
secretKeyRef:
name: mindforge-secrets
key: GITEA_REPO_URL
- name: GITEA_ACCESS_TOKEN
valueFrom:
secretKeyRef:
name: mindforge-secrets
key: GITEA_ACCESS_TOKEN
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "1"
---
apiVersion: v1
kind: Service
metadata:
name: mindforge-api
namespace: mindforge
spec:
selector:
app: mindforge-api
ports:
- port: 80
targetPort: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mindforge-api
namespace: mindforge
labels:
app.kubernetes.io/name: mindforge-api
spec:
ingressClassName: nginx
rules:
- host: "api.mindforge.haven"
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: mindforge-api
port:
number: 80

1
Mindforge.Web/.env Normal file
View File

@@ -0,0 +1 @@
VITE_API_BASE_URL=http://localhost:5123

1
Mindforge.Web/.env.dev Normal file
View File

@@ -0,0 +1 @@
VITE_API_BASE_URL=http://localhost:5123

24
Mindforge.Web/.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

15
Mindforge.Web/Dockerfile Normal file
View File

@@ -0,0 +1,15 @@
FROM node:22-alpine AS builder
ARG VITE_API_BASE_URL
ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -0,0 +1,61 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mindforge-web
namespace: mindforge
spec:
replicas: 1
selector:
matchLabels:
app: mindforge-web
template:
metadata:
labels:
app: mindforge-web
spec:
containers:
- name: mindforge-web
image: git.ivanch.me/ivanch/mindforge-web:latest
imagePullPolicy: Always
ports:
- containerPort: 80
resources:
requests:
memory: "32Mi"
cpu: "100m"
limits:
memory: "128Mi"
cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
name: mindforge-web
namespace: mindforge
spec:
selector:
app: mindforge-web
ports:
- port: 80
targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: mindforge-web
namespace: mindforge
labels:
app.kubernetes.io/name: mindforge-web
spec:
ingressClassName: nginx
rules:
- host: "mindforge.haven"
http:
paths:
- path: "/"
pathType: Prefix
backend:
service:
name: mindforge-web
port:
number: 80

16
Mindforge.Web/index.html Normal file
View File

@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mindforge</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

1897
Mindforge.Web/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,24 @@
{
"name": "mindforge-web",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"preview": "vite preview"
},
"dependencies": {
"@types/marked": "^5.0.2",
"diff": "^8.0.3",
"marked": "^17.0.4",
"preact": "^10.29.0"
},
"devDependencies": {
"@preact/preset-vite": "^2.10.4",
"@types/diff": "^7.0.2",
"@types/node": "^24.12.0",
"typescript": "~5.9.3",
"vite": "^8.0.1"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

62
Mindforge.Web/src/app.css Normal file
View File

@@ -0,0 +1,62 @@
.home-hero {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
animation: fadeIn 0.8s ease-out;
}
.hero-title {
font-size: 4rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 2px;
margin-bottom: 1rem;
text-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
background: linear-gradient(90deg, #f4f5f5, #00b4d8);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
}
.hero-subtitle {
font-size: 1.5rem;
color: rgba(244, 245, 245, 0.8);
font-weight: 300;
letter-spacing: 1px;
}
.module-content {
width: 100%;
max-width: 800px;
margin: 0 auto;
animation: slideUp 0.5s ease-out;
}
.subtitle {
font-size: 1.2rem;
color: rgba(244, 245, 245, 0.8);
margin-bottom: 2rem;
}
.placeholder-box {
background: rgba(255, 255, 255, 0.05);
border: 1px dashed rgba(255, 255, 255, 0.2);
border-radius: 12px;
padding: 4rem 2rem;
font-size: 1.5rem;
color: rgba(244, 245, 245, 0.5);
text-align: center;
backdrop-filter: blur(4px);
-webkit-backdrop-filter: blur(4px);
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes slideUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}

34
Mindforge.Web/src/app.tsx Normal file
View File

@@ -0,0 +1,34 @@
import { useState } from 'preact/hooks';
import './app.css';
import { Header } from './components/Header';
import { Sidebar } from './components/Sidebar';
import { VerificadorComponent } from './components/VerificadorComponent';
import { FlashcardComponent } from './components/FlashcardComponent';
export function App() {
const [activeModule, setActiveModule] = useState<'home' | 'verificador' | 'flashcards'>('home');
return (
<>
<Header onGoHome={() => setActiveModule('home')} />
<div class="main-layout">
<Sidebar activeModule={activeModule} onModuleChange={setActiveModule} />
<main class="content-area">
<div style={{ display: activeModule === 'home' || !activeModule ? 'block' : 'none' }}>
<div class="home-hero">
<img src="/assets/mindforge-banner.png" alt="Mindforge Banner" style={{ maxWidth: '100%', height: 'auto', marginBottom: '2rem', borderRadius: '12px', boxShadow: '0 4px 15px rgba(0,0,0,0.5)', zIndex: -10 }} />
<h1 class="hero-title">Mindforge! - STAY HARD!</h1>
<p class="hero-subtitle">Sua ferramenta de forja mental e estudos.</p>
</div>
</div>
<div style={{ display: activeModule === 'verificador' ? 'block' : 'none', height: '100%', width: '100%' }}>
<VerificadorComponent />
</div>
<div style={{ display: activeModule === 'flashcards' ? 'block' : 'none', height: '100%', width: '100%' }}>
<FlashcardComponent />
</div>
</main>
</div>
</>
);
}

View File

@@ -0,0 +1,41 @@
.btn {
font-family: var(--font-main);
font-weight: 700;
font-size: 1rem;
padding: 0.8rem 1.5rem;
border-radius: 8px;
border: none;
cursor: pointer;
outline: none;
transition: all 0.3s ease;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
letter-spacing: 0.5px;
}
.btn-primary {
background: rgba(255, 255, 255, 0.1);
color: var(--color-text-creamy);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-primary:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
.btn-primary:active {
transform: translateY(0);
}
.btn-secondary {
background: transparent;
color: var(--color-text-creamy);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.btn-secondary:hover {
background: rgba(255, 255, 255, 0.05);
}

View File

@@ -0,0 +1,22 @@
import type { ComponentChildren } from 'preact';
import './Button.css';
interface ButtonProps extends preact.JSX.HTMLAttributes<HTMLButtonElement> {
children: ComponentChildren;
variant?: 'primary' | 'secondary';
className?: string;
onClick?: (e?: any) => any;
disabled?: boolean;
style?: any;
}
export function Button({ children, variant = 'primary', className = '', ...props }: ButtonProps) {
return (
<button
className={`btn btn-${variant} ${className}`}
{...props}
>
{children}
</button>
);
}

View File

@@ -0,0 +1,89 @@
.file-tree {
background: rgba(255, 255, 255, 0.04);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
padding: 0.75rem;
max-height: 380px;
overflow-y: auto;
font-size: 0.9rem;
}
.tree-folder {
margin-bottom: 2px;
}
.tree-folder-header {
display: flex;
align-items: center;
gap: 6px;
padding: 4px 6px;
border-radius: 4px;
cursor: pointer;
user-select: none;
color: rgba(255, 255, 255, 0.85);
font-weight: 600;
}
.tree-folder-header:hover {
background: rgba(255, 255, 255, 0.07);
}
.tree-folder-arrow {
font-size: 0.75rem;
color: rgba(255, 255, 255, 0.5);
width: 12px;
}
.tree-folder-name {
color: rgba(255, 255, 255, 0.85);
}
.tree-folder-children {
padding-left: 18px;
border-left: 1px solid rgba(255, 255, 255, 0.08);
margin-left: 6px;
}
.tree-file {
margin-bottom: 1px;
}
.tree-file-label {
display: flex;
align-items: center;
gap: 8px;
padding: 4px 6px;
border-radius: 4px;
cursor: pointer;
color: rgba(255, 255, 255, 0.7);
}
.tree-file-label:hover {
background: rgba(255, 255, 255, 0.06);
color: rgba(255, 255, 255, 0.9);
}
.tree-file-label input[type="checkbox"] {
accent-color: #7c6fcd;
width: 14px;
height: 14px;
cursor: pointer;
flex-shrink: 0;
}
.tree-file-name {
font-size: 0.875rem;
}
.tree-loading,
.tree-error,
.tree-empty {
padding: 1rem;
color: rgba(255, 255, 255, 0.5);
font-size: 0.9rem;
text-align: center;
}
.tree-error {
color: #ff7b72;
}

View File

@@ -0,0 +1,82 @@
import { useState, useEffect } from 'preact/hooks';
import { MindforgeApiService, type FileTreeNode } from '../services/MindforgeApiService';
import './FileTreeComponent.css';
interface FileTreeComponentProps {
selectedPaths: string[];
onSelectionChange: (paths: string[]) => void;
}
interface FolderNodeProps {
node: FileTreeNode;
selectedPaths: string[];
onToggle: (path: string) => void;
}
function FolderNode({ node, selectedPaths, onToggle }: FolderNodeProps) {
const [expanded, setExpanded] = useState(true);
if (node.type === 'file') {
return (
<div className="tree-file">
<label className="tree-file-label">
<input
type="checkbox"
checked={selectedPaths.includes(node.path)}
onChange={() => onToggle(node.path)}
/>
<span className="tree-file-name">{node.name}</span>
</label>
</div>
);
}
return (
<div className="tree-folder">
<div className="tree-folder-header" onClick={() => setExpanded(e => !e)}>
<span className="tree-folder-arrow">{expanded ? '▾' : '▸'}</span>
<span className="tree-folder-name">{node.name}</span>
</div>
{expanded && node.children && (
<div className="tree-folder-children">
{node.children.map(child => (
<FolderNode key={child.path} node={child} selectedPaths={selectedPaths} onToggle={onToggle} />
))}
</div>
)}
</div>
);
}
export function FileTreeComponent({ selectedPaths, onSelectionChange }: FileTreeComponentProps) {
const [tree, setTree] = useState<FileTreeNode[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
MindforgeApiService.getRepositoryTree()
.then(setTree)
.catch(err => setError(err.message))
.finally(() => setLoading(false));
}, []);
const togglePath = (path: string) => {
if (selectedPaths.includes(path)) {
onSelectionChange(selectedPaths.filter(p => p !== path));
} else {
onSelectionChange([...selectedPaths, path]);
}
};
if (loading) return <div className="tree-loading">Carregando repositório...</div>;
if (error) return <div className="tree-error">Erro ao carregar repositório: {error}</div>;
if (tree.length === 0) return <div className="tree-empty">Nenhum arquivo encontrado no repositório.</div>;
return (
<div className="file-tree">
{tree.map(node => (
<FolderNode key={node.path} node={node} selectedPaths={selectedPaths} onToggle={togglePath} />
))}
</div>
);
}

View File

@@ -0,0 +1,207 @@
.flashcard-container {
width: 100%;
max-width: 800px;
margin: 0 auto;
animation: slideUp 0.5s ease-out;
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.flashcard-form {
display: flex;
flex-direction: column;
gap: 1.2rem;
background: rgba(255, 255, 255, 0.05);
padding: 2rem;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.input-group {
display: flex;
flex-direction: column;
gap: 0.8rem;
text-align: left;
}
.input-group label {
font-weight: 700;
color: var(--color-text-creamy);
}
.text-area {
width: 100%;
min-height: 200px;
background: rgba(0, 0, 0, 0.2);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 8px;
padding: 1rem;
color: var(--color-text-creamy);
font-family: inherit;
font-size: 1rem;
resize: vertical;
}
.text-area:focus {
outline: none;
border-color: var(--color-accent);
}
.file-input-wrapper {
display: flex;
align-items: center;
gap: 1rem;
}
.file-input {
display: none;
}
.file-input-label {
background: var(--color-sidebar);
color: var(--color-text-creamy);
padding: 0.6rem 1.2rem;
border-radius: 6px;
cursor: pointer;
border: 1px solid rgba(255, 255, 255, 0.2);
transition: all 0.2s ease;
}
.file-input-label:hover {
background: rgba(255, 255, 255, 0.1);
border-color: var(--color-accent);
}
.slider-wrapper {
display: flex;
align-items: center;
gap: 1rem;
}
.slider-input {
flex: 1;
-webkit-appearance: none;
appearance: none;
width: 100%;
height: 8px;
background: rgba(0, 0, 0, 0.3);
border-radius: 4px;
outline: none;
}
.slider-input::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: var(--color-accent);
cursor: pointer;
transition: transform 0.1s;
}
.slider-input::-webkit-slider-thumb:hover {
transform: scale(1.2);
}
.amount-display {
font-weight: 700;
color: var(--color-accent);
min-width: 40px;
text-align: right;
font-size: 1.1rem;
}
/* Spinner */
.spinner-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 3rem 0;
gap: 1rem;
}
.spinner {
width: 50px;
height: 50px;
border: 4px solid rgba(255, 255, 255, 0.1);
border-left-color: var(--color-accent);
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.success-message {
color: #7ee787;
text-align: center;
font-weight: 700;
margin-top: 1rem;
animation: fadeIn 0.5s ease-out;
}
.radio-group {
display: flex;
flex-wrap: wrap;
background: rgba(0, 0, 0, 0.3);
padding: 4px;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
width: fit-content;
overflow: hidden;
gap: 4px;
}
.radio-item {
position: relative;
flex: 1;
min-width: 100px;
}
.radio-item input[type="radio"] {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
.radio-label {
display: flex;
align-items: center;
justify-content: center;
padding: 0.8rem 1.2rem;
cursor: pointer;
border-radius: 8px;
font-size: 0.95rem;
font-weight: 600;
color: rgba(255, 255, 255, 0.6);
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
white-space: nowrap;
}
.radio-item input[type="radio"]:checked + .radio-label {
background: var(--color-accent);
color: #000;
box-shadow: 0 4px 12px rgba(var(--color-accent-rgb), 0.3);
}
.radio-item:hover .radio-label:not(.radio-item input[type="radio"]:checked + .radio-label) {
background: rgba(255, 255, 255, 0.05);
color: #fff;
}
/* Animations for selection */
.radio-item input[type="radio"]:checked + .radio-label {
animation: selectBounce 0.3s ease-out;
}
@keyframes selectBounce {
0% { transform: scale(0.95); }
50% { transform: scale(1.02); }
100% { transform: scale(1); }
}

View File

@@ -0,0 +1,183 @@
import { useState } from 'preact/hooks';
import { MindforgeApiService, type FlashcardMode } from '../services/MindforgeApiService';
import { FileTreeComponent } from './FileTreeComponent';
import { Button } from './Button';
import './FlashcardComponent.css';
// Mapping of flashcard mode to its maximum allowed amount
const modeMax: Record<FlashcardMode, number> = {
Basic: 25,
Simple: 30,
Detailed: 70,
Hyper: 130,
};
function utf8ToBase64(str: string): string {
const bytes = new TextEncoder().encode(str);
const binary = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
return window.btoa(binary);
}
export function FlashcardComponent() {
const [selectedPaths, setSelectedPaths] = useState<string[]>([]);
const [amount, setAmount] = useState<number>(20);
const [mode, setMode] = useState<FlashcardMode>('Simple');
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [success, setSuccess] = useState<boolean>(false);
const handleModeChange = (newMode: FlashcardMode) => {
setMode(newMode);
setAmount(20);
};
const handleGenerate = async () => {
if (selectedPaths.length === 0) {
setError('Selecione pelo menos um arquivo do repositório para gerar os flashcards.');
return;
}
setLoading(true);
setError(null);
setSuccess(false);
try {
// Fetch all selected files and merge their content
const fileContents = await Promise.all(
selectedPaths.map(path => MindforgeApiService.getFileContent(path))
);
const mergedContent = fileContents.map(f => f.content).join('\n\n---\n\n');
const mergedFileName = selectedPaths.length === 1
? (selectedPaths[0].split('/').pop() ?? 'merged.md')
: 'merged.md';
const base64Content = utf8ToBase64(mergedContent);
const res = await MindforgeApiService.generateFlashcards({
fileContent: base64Content,
fileName: mergedFileName,
amount,
mode,
});
downloadCSV(res.result);
setSuccess(true);
} catch (err: any) {
setError(err.message || 'Ocorreu um erro ao gerar os flashcards.');
} finally {
setLoading(false);
}
};
const downloadCSV = (content: string) => {
const bom = new Uint8Array([0xEF, 0xBB, 0xBF]);
const blob = new Blob([bom, content], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `flashcards_${Date.now()}.csv`);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
};
return (
<div className="flashcard-container">
<h2 className="title" style={{ fontSize: '2.5rem' }}>Gerador de Flashcards</h2>
<p className="subtitle">Selecione os arquivos do repositório para gerar flashcards. Múltiplos arquivos serão combinados.</p>
<div className="flashcard-form">
<div className="input-group">
<label>Arquivos do Repositório</label>
<FileTreeComponent selectedPaths={selectedPaths} onSelectionChange={setSelectedPaths} />
{selectedPaths.length > 0 && (
<div style={{ fontSize: '0.85rem', color: 'rgba(255,255,255,0.5)', marginTop: '0.4rem' }}>
{selectedPaths.length} arquivo{selectedPaths.length !== 1 ? 's' : ''} selecionado{selectedPaths.length !== 1 ? 's' : ''}
{selectedPaths.length > 1 ? ' — conteúdo será combinado' : ''}
</div>
)}
</div>
<div className="input-group">
<label>Quantidade Estimada de Flashcards (10 - {modeMax[mode]})</label>
<div className="slider-wrapper">
<input
type="range"
className="slider-input"
min="10"
max={modeMax[mode]}
value={amount}
onInput={(e) => setAmount(parseInt((e.target as HTMLInputElement).value))}
/>
<span className="amount-display">{amount}</span>
</div>
</div>
<div className="input-group">
<label>Modo de Geração</label>
<div className="radio-group">
<div className="radio-item">
<input
type="radio"
id="mode-basic"
name="mode"
value="Basic"
checked={mode === 'Basic'}
onChange={(e) => handleModeChange((e.target as HTMLInputElement).value as FlashcardMode)}
/>
<label htmlFor="mode-basic" className="radio-label" title="Modo básico, rápido e simples. Geralmente conteúdos simples e repetíveis">Básico</label>
</div>
<div className="radio-item">
<input
type="radio"
id="mode-simple"
name="mode"
value="Simple"
checked={mode === 'Simple'}
onChange={(e) => handleModeChange((e.target as HTMLInputElement).value as FlashcardMode)}
/>
<label htmlFor="mode-simple" className="radio-label" title="Modo rápido e simples, possui uma melhor compreensão">Simples</label>
</div>
<div className="radio-item">
<input
type="radio"
id="mode-detailed"
name="mode"
value="Detailed"
checked={mode === 'Detailed'}
onChange={(e) => handleModeChange((e.target as HTMLInputElement).value as FlashcardMode)}
/>
<label htmlFor="mode-detailed" className="radio-label" title="Modelo avançado, maior gama de detalhes">Detalhado</label>
</div>
<div className="radio-item">
<input
type="radio"
id="mode-hyper"
name="mode"
value="Hyper"
checked={mode === 'Hyper'}
onChange={(e) => handleModeChange((e.target as HTMLInputElement).value as FlashcardMode)}
/>
<label htmlFor="mode-hyper" className="radio-label" title="Modelo Pro, complexo e com perguntas adicionais">Hiper</label>
</div>
</div>
</div>
<Button variant="primary" onClick={handleGenerate} disabled={loading} style={{ marginTop: '1rem' }}>
{loading ? 'Gerando...' : 'Gerar Flashcards e Baixar (CSV)'}
</Button>
{error && <div style={{ color: '#ff7b72', marginTop: '1rem' }}>{error}</div>}
{success && <div className="success-message">Flashcards gerados com sucesso! O download deve ter começado.</div>}
</div>
{loading && (
<div className="spinner-container">
<div className="spinner"></div>
<p>Extraindo os melhores conceitos para os seus flashcards. Aguarde...</p>
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,61 @@
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 70px;
background-color: var(--color-header);
/* Imposing black with glassy effect */
background: rgba(15, 15, 15, 0.85);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.header-content {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
position: relative;
}
.header-repo {
position: absolute;
right: 24px;
display: flex;
align-items: center;
gap: 6px;
background: rgba(255, 255, 255, 0.06);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 6px;
padding: 4px 10px;
}
.header-repo-icon {
font-size: 0.9rem;
color: rgba(255, 255, 255, 0.5);
}
.header-repo-name {
font-size: 0.8rem;
color: rgba(255, 255, 255, 0.65);
font-family: var(--font-main);
letter-spacing: 0.5px;
}
.header-title {
color: var(--color-text-creamy);
font-family: var(--font-main);
font-size: 1.8rem;
font-weight: 700;
letter-spacing: 2px;
text-transform: uppercase;
margin: 0;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

View File

@@ -0,0 +1,34 @@
import { useState, useEffect } from 'preact/hooks';
import { MindforgeApiService } from '../services/MindforgeApiService';
import './Header.css';
interface HeaderProps {
onGoHome?: () => void;
}
export function Header({ onGoHome }: HeaderProps) {
const [repoName, setRepoName] = useState<string | null>(null);
useEffect(() => {
MindforgeApiService.getRepositoryInfo()
.then(info => setRepoName(info.name))
.catch(() => setRepoName(null));
}, []);
return (
<header class="header">
<div class="header-content">
<div style={{ display: 'flex', alignItems: 'center', cursor: 'pointer' }} onClick={onGoHome}>
<img src="/assets/mindforge.png" alt="Mindforge" width="55" height="55" style={{ marginRight: '10px' }} />
<h1 class="header-title">Mindforge</h1>
</div>
{repoName && (
<div class="header-repo">
<span class="header-repo-icon"></span>
<span class="header-repo-name">{repoName}</span>
</div>
)}
</div>
</header>
);
}

View File

@@ -0,0 +1,41 @@
.sidebar {
width: 280px;
background-color: var(--color-sidebar);
border-right: 1px solid rgba(255, 255, 255, 0.05);
display: flex;
flex-direction: column;
padding: 2rem 1.5rem;
box-shadow: 4px 0 15px rgba(0, 0, 0, 0.2);
/* Ensure it fits cleanly below the header or is independent */
height: calc(100vh - 70px);
position: sticky;
top: 70px;
}
.sidebar-header {
margin-bottom: 2rem;
}
.sidebar-title {
color: rgba(244, 245, 245, 0.6);
font-size: 0.9rem;
text-transform: uppercase;
letter-spacing: 1.5px;
font-weight: 700;
margin: 0;
}
.sidebar-nav {
display: flex;
flex-direction: column;
gap: 1rem;
}
.sidebar-btn {
width: 100%;
text-align: left;
display: flex;
justify-content: flex-start;
padding: 1rem 1.2rem;
font-size: 1.05rem;
}

View File

@@ -0,0 +1,33 @@
import { Button } from './Button';
import './Sidebar.css';
interface SidebarProps {
onModuleChange: (module: 'home' | 'verificador' | 'flashcards') => void;
activeModule: 'home' | 'verificador' | 'flashcards';
}
export function Sidebar({ onModuleChange, activeModule }: SidebarProps) {
return (
<aside class="sidebar">
<div class="sidebar-header">
<h2 class="sidebar-title">Módulos</h2>
</div>
<div class="sidebar-nav">
<Button
variant={activeModule === 'verificador' ? 'primary' : 'secondary'}
onClick={() => onModuleChange('verificador')}
className="sidebar-btn"
>
Verificador
</Button>
<Button
variant={activeModule === 'flashcards' ? 'primary' : 'secondary'}
onClick={() => onModuleChange('flashcards')}
className="sidebar-btn"
>
Flashcards
</Button>
</div>
</aside>
);
}

View File

@@ -0,0 +1,199 @@
.verificador-container {
width: 100%;
max-width: 1000px;
margin: 0 auto;
animation: slideUp 0.5s ease-out;
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.file-result-block {
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
padding: 1rem;
margin-bottom: 1rem;
}
.file-result-title {
font-size: 0.9rem;
font-weight: 600;
color: rgba(255, 255, 255, 0.6);
margin-bottom: 0.75rem;
padding-bottom: 0.5rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
font-family: monospace;
}
.verificador-form {
display: flex;
flex-direction: column;
gap: 1.2rem;
background: rgba(255, 255, 255, 0.05);
padding: 2rem;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.input-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
text-align: left;
}
.input-group label {
font-weight: 700;
color: var(--color-text-creamy);
}
.text-area {
width: 100%;
min-height: 200px;
background: rgba(0, 0, 0, 0.2);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 8px;
padding: 1rem;
color: var(--color-text-creamy);
font-family: inherit;
font-size: 1rem;
resize: vertical;
}
.text-area:focus {
outline: none;
border-color: var(--color-accent);
}
.file-input-wrapper {
display: flex;
align-items: center;
gap: 1rem;
}
.file-input {
display: none;
}
.file-input-label {
background: var(--color-sidebar);
color: var(--color-text-creamy);
padding: 0.6rem 1.2rem;
border-radius: 6px;
cursor: pointer;
border: 1px solid rgba(255, 255, 255, 0.2);
transition: all 0.2s ease;
}
.file-input-label:hover {
background: rgba(255, 255, 255, 0.1);
border-color: var(--color-accent);
}
.select-input {
background: rgba(0, 0, 0, 0.2);
border: 1px solid rgba(255, 255, 255, 0.2);
color: var(--color-text-creamy);
padding: 0.8rem;
border-radius: 8px;
font-size: 1rem;
cursor: pointer;
}
.select-input:focus {
outline: none;
border-color: var(--color-accent);
}
.select-input option {
background: var(--color-bg);
color: var(--color-text-creamy);
}
/* Response Section */
.response-section {
background: rgba(255, 255, 255, 0.05);
padding: 2rem;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.response-content {
text-align: left;
white-space: pre-wrap;
background: rgba(0, 0, 0, 0.2);
padding: 1.5rem;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.1);
font-family: monospace;
font-size: 0.95rem;
line-height: 1.5;
overflow-x: auto;
}
.diff-view {
display: flex;
flex-wrap: wrap;
}
.diff-added {
background-color: rgba(46, 160, 67, 0.3);
color: #7ee787;
border-radius: 3px;
}
.diff-removed {
background-color: rgba(248, 81, 73, 0.3);
color: #ff7b72;
text-decoration: line-through;
border-radius: 3px;
}
.side-by-side {
display: flex;
gap: 1rem;
width: 100%;
}
.side-pane {
flex: 1;
display: flex;
flex-direction: column;
gap: 0.5rem;
min-width: 0;
}
.pane-title {
font-size: 1.1rem;
font-weight: 700;
text-align: center;
color: var(--color-accent);
}
/* Spinner */
.spinner-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 3rem 0;
gap: 1rem;
}
.spinner {
width: 50px;
height: 50px;
border: 4px solid rgba(255, 255, 255, 0.1);
border-left-color: var(--color-accent);
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}

View File

@@ -0,0 +1,194 @@
import { useState } from 'preact/hooks';
import { MindforgeApiService } from '../services/MindforgeApiService';
import { FileTreeComponent } from './FileTreeComponent';
import { Button } from './Button';
import * as diff from 'diff';
import { marked } from 'marked';
import './VerificadorComponent.css';
function utf8ToBase64(str: string): string {
const bytes = new TextEncoder().encode(str);
const binary = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
return window.btoa(binary);
}
type CheckTypeEnum = 'language' | 'content' | 'both';
interface FileResult {
path: string;
fileName: string;
originalContent: string;
languageResult: string | null;
contentResult: string | null;
error: string | null;
}
export function VerificadorComponent() {
const [selectedPaths, setSelectedPaths] = useState<string[]>([]);
const [checkType, setCheckType] = useState<CheckTypeEnum>('language');
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [results, setResults] = useState<FileResult[]>([]);
const handleSubmit = async () => {
if (selectedPaths.length === 0) {
setError('Selecione pelo menos um arquivo do repositório.');
return;
}
setLoading(true);
setError(null);
setResults([]);
try {
const fileResults = await Promise.all(
selectedPaths.map(async (path): Promise<FileResult> => {
const fileName = path.split('/').pop() ?? path;
try {
const { content } = await MindforgeApiService.getFileContent(path);
const base64Content = utf8ToBase64(content);
let languageResult: string | null = null;
let contentResult: string | null = null;
if (checkType === 'both') {
const [langRes, contRes] = await Promise.all([
MindforgeApiService.checkFile({ fileContent: base64Content, fileName, checkType: 'language' }),
MindforgeApiService.checkFile({ fileContent: base64Content, fileName, checkType: 'content' }),
]);
languageResult = langRes.result;
contentResult = contRes.result;
} else {
const res = await MindforgeApiService.checkFile({ fileContent: base64Content, fileName, checkType });
if (checkType === 'language') languageResult = res.result;
else contentResult = res.result;
}
return { path, fileName, originalContent: content, languageResult, contentResult, error: null };
} catch (err: any) {
return { path, fileName, originalContent: '', languageResult: null, contentResult: null, error: err.message };
}
})
);
setResults(fileResults);
} catch (err: any) {
setError(err.message || 'Ocorreu um erro ao processar os arquivos.');
} finally {
setLoading(false);
}
};
const renderDiff = (original: string, updated: string) => {
const diffResult = diff.diffWordsWithSpace(original, updated);
return (
<div className="diff-view">
{diffResult.map((part, index) => {
const className = part.added ? 'diff-added' : part.removed ? 'diff-removed' : '';
return (
<span key={index} className={className}>
{part.value}
</span>
);
})}
</div>
);
};
return (
<div className="verificador-container">
<h2 className="title" style={{ fontSize: '2.5rem' }}>Verificador de Arquivos</h2>
<p className="subtitle">Selecione os arquivos do repositório para validação de linguagem ou conteúdo.</p>
<div className="verificador-form">
<div className="input-group">
<label>Arquivos do Repositório</label>
<FileTreeComponent selectedPaths={selectedPaths} onSelectionChange={setSelectedPaths} />
{selectedPaths.length > 0 && (
<div style={{ fontSize: '0.85rem', color: 'rgba(255,255,255,0.5)', marginTop: '0.4rem' }}>
{selectedPaths.length} arquivo{selectedPaths.length !== 1 ? 's' : ''} selecionado{selectedPaths.length !== 1 ? 's' : ''}
</div>
)}
</div>
<div className="input-group">
<label>Tipo de Verificação</label>
<select
className="select-input"
value={checkType}
onChange={(e) => setCheckType((e.target as HTMLSelectElement).value as CheckTypeEnum)}
>
<option value="language">Linguagem</option>
<option value="content">Conteúdo</option>
<option value="both">Linguagem e Conteúdo</option>
</select>
</div>
<Button variant="primary" onClick={handleSubmit} disabled={loading} style={{ marginTop: '1rem' }}>
{loading ? 'Processando...' : 'Verificar'}
</Button>
{error && <div style={{ color: '#ff7b72', marginTop: '1rem' }}>{error}</div>}
</div>
{loading && (
<div className="spinner-container">
<div className="spinner"></div>
<p>Analisando sua forja mental...</p>
</div>
)}
{!loading && results.length > 0 && (
<div className="response-section">
{results.map((fileResult) => (
<div key={fileResult.path} className="file-result-block">
<div className="file-result-title">{fileResult.fileName}</div>
{fileResult.error && (
<div style={{ color: '#ff7b72', padding: '0.5rem' }}>{fileResult.error}</div>
)}
{!fileResult.error && checkType === 'language' && fileResult.languageResult && (
<div className="side-pane">
<div className="pane-title">Linguagem (Diff)</div>
<div className="response-content">
{renderDiff(fileResult.originalContent, fileResult.languageResult)}
</div>
</div>
)}
{!fileResult.error && checkType === 'content' && fileResult.contentResult && (
<div className="side-pane">
<div className="pane-title">Conteúdo</div>
<div
className="response-content markdown-body"
dangerouslySetInnerHTML={{ __html: marked.parse(fileResult.contentResult) as string }}
/>
</div>
)}
{!fileResult.error && checkType === 'both' && fileResult.languageResult && fileResult.contentResult && (
<div className="side-by-side">
<div className="side-pane">
<div className="pane-title">Linguagem (Diff)</div>
<div className="response-content" style={{ minHeight: '200px' }}>
{renderDiff(fileResult.originalContent, fileResult.languageResult)}
</div>
</div>
<div className="side-pane">
<div className="pane-title">Conteúdo</div>
<div
className="response-content markdown-body"
style={{ minHeight: '200px' }}
dangerouslySetInnerHTML={{ __html: marked.parse(fileResult.contentResult) as string }}
/>
</div>
</div>
)}
</div>
))}
</div>
)}
</div>
);
}

View File

@@ -0,0 +1,57 @@
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700&display=swap');
:root {
--color-bg: #005873;
--color-header: #0f0f0f;
--color-sidebar: #013a4c;
--color-text-creamy: #f4f5f5;
--color-accent: #00b4d8;
--color-accent-rgb: 0, 180, 216;
--color-accent-hover: #0096c7;
--font-main: 'Lato', sans-serif;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: var(--font-main);
background-color: var(--color-bg);
color: var(--color-text-creamy);
margin: 0;
min-height: 100vh;
-webkit-font-smoothing: antialiased;
}
#app {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.main-layout {
display: flex;
flex: 1;
margin-top: 70px; /* offset for fixed header */
}
.content-area {
flex: 1;
padding: 2rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
}
.title {
font-size: 3rem;
font-weight: 700;
margin-bottom: 2rem;
text-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

View File

@@ -0,0 +1,5 @@
import { render } from 'preact'
import './index.css'
import { App } from './app.tsx'
render(<App />, document.getElementById('app')!)

View File

@@ -0,0 +1,90 @@
const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:5123';
export interface FileTreeNode {
name: string;
path: string;
type: 'file' | 'folder';
children?: FileTreeNode[];
}
export interface RepositoryInfo {
name: string;
}
export interface FileContentResponse {
path: string;
content: string;
}
export interface CheckFileRequest {
fileContent: string;
fileName: string;
checkType: 'language' | 'content';
}
export interface CheckFileResponse {
result: string;
}
export interface GenerateFlashcardsRequest {
fileContent: string;
fileName: string;
amount: number;
mode: FlashcardMode;
}
export type FlashcardMode = 'Basic' | 'Simple' | 'Detailed' | 'Hyper';
export interface GenerateFlashcardsResponse {
result: string;
}
export const MindforgeApiService = {
async checkFile(data: CheckFileRequest): Promise<CheckFileResponse> {
const response = await fetch(`${BASE_URL}/api/v1/file/check`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`Error checking file: ${response.statusText}`);
}
return response.json();
},
async generateFlashcards(data: GenerateFlashcardsRequest): Promise<GenerateFlashcardsResponse> {
const response = await fetch(`${BASE_URL}/api/v1/flashcard/generate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`Error generating flashcards: ${response.statusText}`);
}
return response.json();
},
async getRepositoryInfo(): Promise<RepositoryInfo> {
const response = await fetch(`${BASE_URL}/api/v1/repository/info`);
if (!response.ok) throw new Error(`Error fetching repository info: ${response.statusText}`);
return response.json();
},
async getRepositoryTree(): Promise<FileTreeNode[]> {
const response = await fetch(`${BASE_URL}/api/v1/repository/tree`);
if (!response.ok) throw new Error(`Error fetching repository tree: ${response.statusText}`);
return response.json();
},
async getFileContent(path: string): Promise<FileContentResponse> {
const response = await fetch(`${BASE_URL}/api/v1/repository/file?path=${encodeURIComponent(path)}`);
if (!response.ok) throw new Error(`Error fetching file ${path}: ${response.statusText}`);
return response.json();
},
};

View File

@@ -0,0 +1,33 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2023",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2023", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"skipLibCheck": true,
"paths": {
"react": ["./node_modules/preact/compat/"],
"react-dom": ["./node_modules/preact/compat/"]
},
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
"jsxImportSource": "preact",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}

View File

@@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}

View File

@@ -0,0 +1,26 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": ["node"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}

View File

@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite'
// https://vite.dev/config/
export default defineConfig({
plugins: [preact()],
})

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
## Mindforge Architecture
This is a project that will be used to aid the user in making notes and studying for hard exams and tests.

View File

@@ -9,4 +9,6 @@ SUMMARY_FORMATTER_PROVIDER=openai
# LLM models # LLM models
GEMINI_MODEL=gemini-3-flash-preview GEMINI_MODEL=gemini-3-flash-preview
OPENAI_MODEL=gpt-5-mini OPENAI_MODEL=gpt-5-mini
TOP_N_FILES=10

View File

@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"strconv"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"mindforge.cronjob/internal/agent" "mindforge.cronjob/internal/agent"
@@ -27,6 +28,14 @@ func main() {
// Initialize services // Initialize services
gitService := git.NewGitService() gitService := git.NewGitService()
// Resolve how many top files to return (TOP_N_FILES env var, default 10)
topN := 10
if v := os.Getenv("TOP_N_FILES"); v != "" {
if n, err := strconv.Atoi(v); err == nil && n > 0 {
topN = n
}
}
// Get modifications // Get modifications
var modifications map[string]string var modifications map[string]string
error := gitService.FetchContents(gitRepo) error := gitService.FetchContents(gitRepo)
@@ -34,7 +43,15 @@ func main() {
log.Println("ERROR: Failed to fetch contents:", error) log.Println("ERROR: Failed to fetch contents:", error)
} }
modifications, error = gitService.GetModifications(7) // Resolve how many days to look back (LAST_N_DAYS env var, default 7)
days := 7
if v := os.Getenv("LAST_N_DAYS"); v != "" {
if n, err := strconv.Atoi(v); err == nil && n > 0 {
days = n
}
}
modifications, error = gitService.GetModifications(days, topN)
if error != nil { if error != nil {
log.Println("ERROR: Failed to get modifications:", error) log.Println("ERROR: Failed to get modifications:", error)
} }
@@ -42,7 +59,7 @@ func main() {
fmt.Printf("Found %d modifications\n", len(modifications)) fmt.Printf("Found %d modifications\n", len(modifications))
for file, content := range modifications { for file, content := range modifications {
fmt.Printf("File: %s\n", file) fmt.Printf("Processing file: %s\n", file)
raw_summary, err := agent.SummaryCreatorAgent(file, content) raw_summary, err := agent.SummaryCreatorAgent(file, content)
if err != nil { if err != nil {

View File

@@ -50,6 +50,10 @@ spec:
value: gemini-3-flash-preview value: gemini-3-flash-preview
- name: OPENAI_MODEL - name: OPENAI_MODEL
value: gpt-5-mini value: gpt-5-mini
- name: TOP_N_FILES
value: "10"
- name: LAST_N_DAYS
value: "7"
resources: resources:
requests: requests:
memory: "256Mi" memory: "256Mi"

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"sort"
"strings" "strings"
"time" "time"
) )
@@ -13,7 +14,10 @@ import (
type Service interface { type Service interface {
CheckConnection(url string) error CheckConnection(url string) error
FetchContents(url string) error FetchContents(url string) error
GetModifications(days int) (map[string]string, error) // GetModifications returns the diffs of the top-N most-changed files (by lines
// added/removed) modified within the last 'days' days. Files with 4 or fewer
// changed lines are always excluded. Pass topN <= 0 to return all qualifying files.
GetModifications(days int, topN int) (map[string]string, error)
} }
type gitService struct { type gitService struct {
@@ -85,7 +89,7 @@ func (s *gitService) FetchContents(url string) error {
return nil return nil
} }
func (s *gitService) GetModifications(days int) (map[string]string, error) { func (s *gitService) GetModifications(days int, topN int) (map[string]string, error) {
mods := make(map[string]string) mods := make(map[string]string)
// Determine the commit to diff against (the latest commit *before* 'days' ago) // Determine the commit to diff against (the latest commit *before* 'days' ago)
@@ -103,7 +107,7 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
} }
// Get the list of modified files between the base commit and HEAD // Get the list of modified files between the base commit and HEAD
cmdFiles := exec.Command("git", "diff", "--name-only", baseCommit, "HEAD") cmdFiles := exec.Command("git", "-c", "core.quotePath=false", "diff", "--name-only", baseCommit, "HEAD")
cmdFiles.Dir = s.repoDir cmdFiles.Dir = s.repoDir
filesOut, err := cmdFiles.Output() filesOut, err := cmdFiles.Output()
if err != nil { if err != nil {
@@ -112,6 +116,8 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
files := strings.Split(strings.TrimSpace(string(filesOut)), "\n") files := strings.Split(strings.TrimSpace(string(filesOut)), "\n")
for _, file := range files { for _, file := range files {
fmt.Printf("Processing file: %s\n", file)
if file == "" { if file == "" {
continue continue
} }
@@ -121,6 +127,11 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
continue continue
} }
// Skip files with "Conteúdos.md" in the path
if strings.Contains(file, "Conteúdos.md") {
continue
}
originalFile := file originalFile := file
// Remove first folder from file path // Remove first folder from file path
@@ -135,7 +146,7 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
rangeStr = baseCommit + "..HEAD" rangeStr = baseCommit + "..HEAD"
} }
cmdDiff := exec.Command("git", "log", "-p", "-i", "--invert-grep", "--grep=refactor", rangeStr, "--", originalFile) cmdDiff := exec.Command("git", "-c", "core.quotePath=false", "log", "-p", "-i", "--invert-grep", "--grep=refactor", rangeStr, "--", originalFile)
cmdDiff.Dir = s.repoDir cmdDiff.Dir = s.repoDir
diffOut, err := cmdDiff.Output() diffOut, err := cmdDiff.Output()
if err != nil { if err != nil {
@@ -147,5 +158,44 @@ func (s *gitService) GetModifications(days int) (map[string]string, error) {
} }
} }
return mods, nil // Count the number of changed lines (additions + deletions) per file.
// Lines starting with '+' or '-' are changed lines; lines starting with '+++'
// or '---' are the diff file headers and must be excluded.
type fileScore struct {
name string
score int
}
scores := make([]fileScore, 0, len(mods))
for name, diff := range mods {
count := 0
for _, line := range strings.Split(diff, "\n") {
if (strings.HasPrefix(line, "+") || strings.HasPrefix(line, "-")) &&
!strings.HasPrefix(line, "++") && !strings.HasPrefix(line, "--") {
count++
}
}
// Ignore files with 4 or fewer lines changed
if count <= 4 {
fmt.Printf("Ignoring file %s: %d lines changed\n", name, count)
continue
}
scores = append(scores, fileScore{name: name, score: count})
}
// Sort descending by number of changed lines
sort.Slice(scores, func(i, j int) bool {
return scores[i].score > scores[j].score
})
// Keep only the top-N entries (if topN <= 0, keep all qualifying files)
if topN > 0 && len(scores) > topN {
scores = scores[:topN]
}
result := make(map[string]string, len(scores))
for _, fs := range scores {
result[fs.name] = mods[fs.name]
}
return result, nil
} }

24
mindforge.sln Normal file
View File

@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mindforge.API", "Mindforge.API\Mindforge.API.csproj", "{038E2A68-9556-09E2-3A91-52464940A286}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{038E2A68-9556-09E2-3A91-52464940A286}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{038E2A68-9556-09E2-3A91-52464940A286}.Debug|Any CPU.Build.0 = Debug|Any CPU
{038E2A68-9556-09E2-3A91-52464940A286}.Release|Any CPU.ActiveCfg = Release|Any CPU
{038E2A68-9556-09E2-3A91-52464940A286}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3765D3A9-6691-44E4-8741-710E14090009}
EndGlobalSection
EndGlobal