Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 19, 2025

This PR significantly enhances the .github/copilot-instructions.md file to include comprehensive Javalin patterns, design philosophy, and best practices. The improvements will help AI assistants (like GitHub Copilot) generate correct, idiomatic Javalin code.

What's Changed

The documentation has been expanded from 152 to 859 lines with the following new sections:

Core Philosophy & Principles

Added clear explanation of Javalin's design philosophy:

  • No Annotations - All configuration is code-based
  • No Reflection - Everything is explicit and statically typed
  • No Magic - Plain, understandable code
  • Functional First - Heavy use of lambdas and functional interfaces
  • Consumer-based Configuration - All config uses Consumer<Config> pattern

Comprehensive Pattern Documentation

Configuration Patterns - Shows consumer-based configuration, nested hierarchy, and proper use of config objects (http, router, staticFiles, events)

Handler Patterns - Functional interface handlers with lambdas and method references, emphasizing Javalin 7's config.routes API

Routing Patterns - Documents both routing styles:

  • Direct routing: config.routes.get/post/delete/etc()
  • ApiBuilder for nested structures: config.routes.apiBuilder(() -> { ... })

Lifecycle Management - Before/after handlers, beforeMatched, exception handlers (preferred over try-catch), and error handlers

Context Usage - Comprehensive examples of request data access and response building patterns

Plugin Patterns - Using bundled plugins, creating custom plugins, and context-extending plugins

WebSocket Patterns - Event handlers (onConnect, onMessage, onClose, onError) and JSON over WebSocket

Async Patterns - CompletableFuture support and virtual threads (Java 21+)

JSON Patterns - Built-in Jackson support, serialization/deserialization examples

Anti-Patterns Section

Documents what NOT to do with clear examples:

  • ❌ Don't use annotations (Javalin is annotation-free)
  • ❌ Don't extend classes (no base class inheritance needed)
  • ❌ Don't use reflection (everything is explicit)
  • ❌ Don't use old Javalin 6 API (app.get() method chaining)
  • ❌ Don't catch everything (use exception handlers instead)

Testing Patterns & Best Practices

  • TestUtil usage for integration tests
  • Unit testing with mocks
  • 10-point best practices summary

Validation

To ensure accuracy, this PR includes:

  • New test file: CopilotInstructionsPatternValidation.java that validates all documented patterns compile correctly
  • All examples use the correct Javalin 7 API (config.routes instead of deprecated method chaining)
  • Build passes successfully with all examples

Impact

These improvements will help AI assistants:

  • Generate correct, idiomatic Javalin 7 code
  • Understand Javalin's functional, annotation-free philosophy
  • Avoid common mistakes and deprecated patterns
  • Follow established best practices
  • Create maintainable, production-ready code

The documentation is now fully aligned with:

Closes #XXXX

Original prompt

This section details on the original issue you should resolve

<issue_title>Improve copilot instructions</issue_title>
<issue_description>Improve https://github.com/javalin/javalin/blob/master/.github/copilot-instructions.md to include common Javalin patterns, such as avoiding annotations, using consumers for configuration, etc. Thoroughly the current documentation (https://javalin.io/documentation) to understand the public API and philosophy of the framework.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #2482


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI self-assigned this Oct 19, 2025
@tipsy tipsy marked this pull request as ready for review October 19, 2025 10:14
Copilot AI changed the title [WIP] Improve Copilot instructions documentation for Javalin [github] Improve copilot-instructions.md with comprehensive Javalin patterns and philosophy Oct 19, 2025
Copilot AI requested a review from tipsy October 19, 2025 10:17
@tipsy tipsy merged commit 55572e3 into master Oct 19, 2025
@tipsy tipsy deleted the copilot/improve-copilot-instructions branch October 19, 2025 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve copilot instructions

2 participants