[github] Improve copilot-instructions.md with comprehensive Javalin patterns and philosophy #2483
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR significantly enhances the
.github/copilot-instructions.mdfile 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:
Consumer<Config>patternComprehensive 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.routesAPIRouting Patterns - Documents both routing styles:
config.routes.get/post/delete/etc()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:
app.get()method chaining)Testing Patterns & Best Practices
Validation
To ensure accuracy, this PR includes:
CopilotInstructionsPatternValidation.javathat validates all documented patterns compile correctlyconfig.routesinstead of deprecated method chaining)Impact
These improvements will help AI assistants:
The documentation is now fully aligned with:
/javalin/src/test/kotlin/io/javalin/examples/Closes #XXXX
Original prompt
Fixes #2482
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.