Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Aiaiaiaiaia - #35

Merged
danielvanginneken merged 11 commits into
mainfrom
AIAIAIAIAIA
Jan 8, 2026
Merged

danielvanginneken merged 11 commits into
mainfrom
AIAIAIAIAIA

Conversation

@danielvanginneken

Copy link
Copy Markdown
Contributor

This pull request introduces a new AI prediction feature to the backend, including all necessary infrastructure, service, controller, and model layers. It also improves logging, updates environment and dependency configurations, and makes minor data model and repository adjustments for consistency.

AI Prediction Feature Implementation:

  • Added interfaces, models, and service classes for AI predictions, including PredictionPayload, PredictionResponse, and PredictionMatch in prediction.model.ts, the IAiService interface in ai.port.ts, and the HTTP client implementation in prediction-client.ts. [1] [2] [3] [4] [5]
  • Registered the AI service, HTTP client, and controller in the NestJS module, and exposed a new POST /ai/predict endpoint via AiController. [1] [2] [3] [4] [5]
  • Added the AI_SERVICE_URL environment variable to .env.example for external AI service configuration.
  • Added required dependencies for HTTP and configuration support: @nestjs/axios, @nestjs/config, and axios.

Logging and Observability Improvements:

  • Refactored LoggerService to extend Nest's ConsoleLogger, ensuring structured JSON logging and consistent context setting across services and middleware. [1] [2] [3]
  • Updated service constructors to set logger context for improved traceability. [1] [2] [3]

Data Model and Repository Adjustments:

  • Updated the Prisma schema to add explicit relations between UserFavorites, User, and ChoiceModule, and added a userFavorites relation on User and ChoiceModule. [1] [2]
  • Removed unnecessary non-null assertions (!) in the ChoiceModulesRepository to align with updated Prisma typing and improve type safety. [1] [2] [3] [4] [5]

@danielvanginneken danielvanginneken self-assigned this Jan 8, 2026
Copilot AI review requested due to automatic review settings January 8, 2026 09:58
@danielvanginneken danielvanginneken added the enhancement New feature or request label Jan 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces a comprehensive AI prediction feature to the backend application, enabling course/module recommendations based on user preferences. The implementation follows a layered architecture with proper separation of concerns across presentation, application, domain, and infrastructure layers. Additionally, the PR refactors the logging system to use structured JSON output and makes database schema improvements for better type safety.

  • Added complete AI prediction infrastructure including DTOs, controllers, services, HTTP client, and domain models
  • Refactored LoggerService to extend NestJS ConsoleLogger with structured JSON logging and consistent context setting
  • Enhanced Prisma schema with explicit relations for UserFavorites and improved type safety by removing non-null assertions in the repository

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/presentation/dtos/ai.dto.ts Defines validation rules for AI prediction request payload with user preferences
src/presentation/controllers/ai.controller.ts Exposes POST /ai/predict endpoint with session-based authentication
src/application/services/ai.service.ts Application service that orchestrates prediction requests and wraps results in Result type
src/application/ports/ai.port.ts Defines IAiService interface for dependency injection
src/infrastructure/ai-service/prediction-client.ts HTTP client implementation for external AI service communication with error handling
src/domain/predictions/prediction.model.ts Domain models for prediction payload, response, and match data structures
src/domain/predictions/prediction-client.interface.ts Interface for prediction client abstraction
src/common/logger.service.ts Refactored to extend ConsoleLogger with structured JSON logging output
src/infrastructure/middleware/request-logging.middleware.ts Updated to set logger context for better traceability
src/infrastructure/database/prisma.ts Improved type safety for Prisma event listeners and added context setting
src/infrastructure/database/schema/schema.prisma Added explicit relations between UserFavorites, User, and ChoiceModule
src/infrastructure/database/repositories/choicemodules.repository.ts Removed unnecessary non-null assertions for improved type safety
src/application/services/auth.service.ts Added logger context setting in constructor
src/app.module.ts Registered AI service, HTTP client, and controller with dependency injection
package.json Added @nestjs/axios, @nestjs/config, and axios dependencies
package-lock.json Lock file updates for new dependencies
.env.example Added AI_SERVICE_URL configuration variable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/application/services/ai.service.ts Resolved
Comment thread src/presentation/dtos/ai.dto.ts Resolved
Comment on lines +15 to +34
/**
* Centralized formatter to ensure consistent JSON structure.
* Handles objects, strings, and circular references safely.
*/
private formatEntry(
level: LogLevel,
message: unknown,
context?: string,
meta?: unknown,
): string {
const entry = {
timestamp: new Date().toISOString(),
level,
context: context ?? this.name,
message: typeof message === 'string' ? message : JSON.stringify(message),
context: context ?? this.contextName,
message: typeof message === 'string' ? message : message,
...(meta ? { meta } : {}),
};

if (meta) payload.meta = meta;
return JSON.stringify(payload);
// Using a replacer or library like 'safe-stable-stringify' is better for prod, but standard JSON.stringify works fine for now.
return JSON.stringify(entry);

Copilot AI Jan 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 17 claims the formatter "Handles objects, strings, and circular references safely", but the implementation at line 34 uses standard JSON.stringify which does NOT handle circular references safely - it will throw a TypeError if circular references are encountered. Either update the implementation to actually handle circular references (e.g., using a replacer function or a library like 'safe-stable-stringify'), or update the documentation to remove the claim about handling circular references safely.

Copilot uses AI. Check for mistakes.
@danielvanginneken
danielvanginneken merged commit 1baedbf into main Jan 8, 2026
4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants