Moderne Prethink recipes
Moderne Prethink recipes generate structured context that gives AI coding agents a clear, accurate understanding of your entire codebase. Instead of forcing AI agents to infer your architecture from raw code, Prethink provides pre-resolved knowledge about service endpoints, dependencies, test coverage, and more.
Why use Prethink
AI coding agents like Claude Code, Cursor, and GitHub Copilot struggle with enterprise codebases due to:
- Token limits that prevent them from fitting your entire codebase into context
- Shallow code understanding that forces them to infer types, dependencies, and cross-repository relationships from raw text (often resulting in hallucinations)
- Repetitive context building that wastes tokens re-describing code structure on every interaction
These aren't faults of the models themselves - they're data problems. When working with vast enterprise codebases, AI models don't have the semantic context needed to be comprehensive, accurate, and efficient.
Prethink solves these problems by generating verified, structured context that AI agents can reason over directly. This means faster responses, lower costs, and more accurate results.
What Prethink provides
Moderne Prethink delivers pre-resolved, verified knowledge that AI agents can reason over directly:
- Architectural patterns: Service endpoints, database connections, external service calls, and messaging patterns
- Resolved dependency graphs: Complete dependency trees, including transitive dependencies
- Known vulnerabilities: Security issues identified across your repositories
- Declared migration targets: Your organization's upgrade and modernization goals
- Deterministic recipes: Structured transformations that can be applied reliably
With Prethink:
- Code structure is documented, not guessed
- Relationships between services are already mapped
- Your goals and constraints are part of the context
- AI reasons over facts instead of reconstructing them
How Prethink works
Prethink is delivered as a set of OpenRewrite recipes that generate multi-repo, trusted context for AI agents. When you run Prethink recipes against your codebase, they produce structured outputs that capture context, including:
- Code data tables: Deep insights only discoverable using Moderne's Lossless Semantic Tree (LST) code model
- Dependency inventory: Complete picture of libraries including transitive dependencies
- Knowledge graph (optional): System-level map of how components, dependencies, and behaviors connect
- CALM-formatted artifacts: Architecture diagrams with nodes and relationships that can be visualized with CALM-compatible tools
These outputs can be continuously updated as your codebase evolves by re-running Prethink recipes. This ensures your AI agents always have current, accurate context.
Recipe modules
Prethink is distributed as two complementary modules:
| Module | Description |
|---|---|
io.moderne.recipe:rewrite-prethink | A pre-configured module with out-of-the-box discovery for Spring MVC, JAX-RS, JPA, Kafka, and more. Includes LLM integrations for code comprehension. |
org.openrewrite.recipe:rewrite-prethink | Open-source building blocks for custom Prethink recipes. Use this when you have custom frameworks or want full control over context generation. |
What the Moderne module discovers
The io.moderne.recipe:rewrite-prethink module provides out-of-the-box discovery for common frameworks:
Java/JVM:
- Service endpoint discovery: Spring MVC, JAX-RS, Micronaut, Quarkus
- Database connection discovery: JPA, Spring Data, JDBC, MyBatis
- External service call discovery: RestTemplate, WebClient, Feign, Apache HttpClient, OkHttp, JAX-RS clients
- Messaging pattern discovery: Kafka, RabbitMQ, JMS, Spring Cloud Stream, AWS SQS
- Security configuration discovery: Spring Security, CORS, OAuth2
- Service component discovery: @Service, @Component, @Named annotations
- Data asset discovery: JPA entities, Java records, DTOs
Node.js/TypeScript:
- Service endpoint discovery: Express, Fastify, NestJS
- Database connection discovery: Mongoose, Prisma, TypeORM
- External service call discovery: axios, fetch, got, superagent
- Messaging pattern discovery: KafkaJS, amqplib, Bull/BullMQ
- Security configuration discovery: cors, helmet, passport, JWT middleware
- Test coverage discovery: Jest, Mocha, Vitest
- Project metadata: package.json extraction
Cross-language:
- Coding convention extraction: Naming patterns, import organization, documentation patterns
- Dependency usage extraction: Which types from external libraries are actually used in the code
- Error handling pattern extraction: Exception types, handling strategies, logging frameworks
- LLM integrations: Code comprehension at the method and class level, test summary generation
- Architecture visualization: CALM architecture diagrams and Mermaid architecture diagrams
What the OpenRewrite module provides
The org.openrewrite.recipe:rewrite-prethink module provides the building blocks for generating Prethink context:
- ExportContext: Exports data tables as CSV files to your repository
- UpdateAgentConfig: Updates AI agent configuration files with context references
- UpdateGitignore: Updates
.gitignoreto allow committing.moderne/context/while ignoring other.moderne/files - UpdatePrethinkContext: Orchestrates context generation from pre-populated data tables
- CALM architecture generation: Produces CALM-formatted architecture diagrams
This module provides the infrastructure but expects you to supply your own recipes for discovering CALM entities and producing the context you want to save.
Available recipes
Update Prethink context (with AI)
Generates Moderne Prethink context files with AI-generated code comprehension, test coverage mapping, dependency inventory, and FINOS CALM architecture diagrams. Maps tests to implementation methods and optionally generates AI summaries of what each test verifies when an LLM provider is configured.
- Recipe:
io.moderne.prethink.UpdatePrethinkContextStarter - Module:
io.moderne.recipe:rewrite-prethink
Options
| Option | Description | Example |
|---|---|---|
provider | LLM provider for generating summaries | openai, gemini, poolside |
apiKey | API key for the LLM provider | ps-... |
model | Model name to use | Malibu-v2.20251021 |
baseUrl | Custom base URL for the provider | https://divers.poolsi.de/openai/v1/ |
requestsPerMinute | Rate limit for LLM requests | 60 |
targetConfigFile | Which agent config file to update (updates all found files if not specified) | CLAUDE.md |
Update Prethink context (no AI)
Generates Moderne Prethink context files with architectural discovery, test coverage mapping, dependency inventory, and FINOS CALM architecture diagrams. This recipe does not require an LLM provider - use the Update Prethink context (with AI) recipe if you want AI-generated code comprehension and test summaries.
- Recipe:
io.moderne.prethink.UpdatePrethinkContextNoAiStarter - Module:
io.moderne.recipe:rewrite-prethink
This recipe includes the same architectural discovery, test coverage mapping, dependency inventory, and CALM architecture generation as the AI version, but skips AI-generated code comprehension. Instead, it estimates token usage for methods so you can evaluate AI costs before enabling comprehension.
Options
| Option | Description | Example |
|---|---|---|
targetConfigFile | Which agent config file to update. If not specified and no agent config files exist, will create a CLAUDE.md. If at least one agent config file exists, it will update each one it finds. | CLAUDE.md |
Update Prethink context (base recipe)
Generates a FINOS CALM architecture diagram and updates agent configuration files. This recipe expects CALM-related data tables (ServiceEndpoints, DatabaseConnections, ExternalServiceCalls, MessagingConnections, etc.) to be populated by other recipes in a composite.
- Recipe:
org.openrewrite.prethink.UpdatePrethinkContext - Module:
org.openrewrite.recipe:rewrite-prethink
Use this recipe when building custom Prethink configurations with your own discovery recipes. This recipe has no configurable options.
Supporting recipes
The OpenRewrite module also provides these building blocks:
| Recipe | Description |
|---|---|
org.openrewrite.prethink.ExportContext | Exports data tables to CSV files in .moderne/context/ with markdown documentation describing the schema. |
org.openrewrite.prethink.UpdateAgentConfig | Creates or updates agent configuration files (AGENTS.md, CLAUDE.md, .cursorrules, .github/copilot-instructions.md) to reference generated context. |
org.openrewrite.prethink.UpdateGitignore | Updates .gitignore to allow committing .moderne/context/ while ignoring other files in .moderne/. |
Creating custom Prethink recipes
If the built-in recipes don't meet your needs, you can create custom Prethink recipes. This is useful when you have custom frameworks, proprietary patterns, or want full control over what context is generated.
Customizing the starter recipes
The starter recipes (UpdatePrethinkContextStarter and UpdatePrethinkContextNoAiStarter) are composite recipes that bundle all of the Moderne module's discovery and analysis capabilities into a single recipe you can run out of the box.
You can customize what Prethink generates by creating your own Prethink recipe. Check out the recipe definition below for a starting point of what the base Prethink recipe looks like. From there, you can wrap it in a new recipe to add custom discovery, or you could copy and modify it to remove built-in recipes you don't need.
UpdatePrethinkContextNoAiStarter recipe definition
type: specs.openrewrite.org/v1beta/recipe
name: io.moderne.prethink.UpdatePrethinkContextNoAiStarter
displayName: Update Prethink context (no AI)
description: >-
Generate Moderne Prethink context files with architectural discovery,
test coverage mapping, dependency inventory, and FINOS CALM architecture
diagrams. This recipe does not require an LLM provider.
recipeList:
# Phase 1: Architectural Discovery
- io.moderne.prethink.FindProjectMetadata
- io.moderne.prethink.FindNodeProjectMetadata
- io.moderne.prethink.FindPythonProjectMetadata
- io.moderne.prethink.FindServiceEndpoints
- io.moderne.prethink.FindNestJSEndpoints
- io.moderne.prethink.FindExpressEndpoints
- io.moderne.prethink.FindDatabaseConnections
- io.moderne.prethink.FindTypeORMEntities
- io.moderne.prethink.FindMongooseSchemas
- io.moderne.prethink.FindPrismaUsage
- io.moderne.prethink.FindExternalServiceCalls
- io.moderne.prethink.FindNodeHttpClients
- io.moderne.prethink.FindMessagingConnections
- io.moderne.prethink.FindNodeMessaging
- io.moderne.prethink.FindServerConfiguration
- io.moderne.prethink.FindDataAssets
- io.moderne.prethink.FindDeploymentArtifacts
- io.moderne.prethink.FindSecurityConfiguration
- io.moderne.prethink.FindNodeSecurityConfig
- io.moderne.prethink.FindServiceComponents
- io.moderne.prethink.ExtractCodingConventions
- io.moderne.prethink.ExtractErrorPatterns
- io.moderne.prethink.FindNodeErrorPatterns
- io.moderne.prethink.ExtractDependencyUsage
# Context exports
- org.openrewrite.prethink.ExportContext:
displayName: Project Identity
shortDescription: Build system coordinates, names, and module structure
longDescription: >-
Project-level identification for each build module including artifact ID,
group ID, version, display name, and description.
dataTables:
- org.openrewrite.prethink.table.ProjectMetadata
- org.openrewrite.prethink.ExportContext:
displayName: Coding Conventions
shortDescription: Naming patterns, import organization, and coding style
longDescription: >-
Detected coding conventions including naming patterns, import organization,
and documentation coverage.
dataTables:
- org.openrewrite.prethink.table.CodingConventions
- org.openrewrite.prethink.ExportContext:
displayName: Error Handling
shortDescription: Exception handling strategies and logging patterns
longDescription: >-
Error handling patterns detected in the codebase including try-catch usage,
exception types, and handling strategies.
dataTables:
- org.openrewrite.prethink.table.ErrorHandlingPatterns
- org.openrewrite.prethink.ExportContext:
displayName: Library Usage
shortDescription: How external libraries and frameworks are used
longDescription: >-
Patterns of how external libraries are used throughout the codebase.
dataTables:
- org.openrewrite.prethink.table.DependencyUsage
# Phase 1.5: Relationship Discovery
- io.moderne.prethink.calm.FindCalmRelationships
# Phase 2: Token Estimation (no AI)
- io.moderne.prethink.ComprehendCodeTokenCounter
- org.openrewrite.prethink.ExportContext:
displayName: Token Estimates
shortDescription: Estimated input tokens for method comprehension
longDescription: >-
Estimated input token counts that would be sent to an LLM for method
comprehension.
dataTables:
- io.moderne.prethink.table.MethodDescriptions
# Phase 3: Test Coverage & Dependencies
- io.moderne.prethink.FindNodeTestCoverage
- io.moderne.prethink.FindTestCoverage
- org.openrewrite.prethink.ExportContext:
displayName: Test Coverage
shortDescription: Maps test methods to implementation methods they verify
longDescription: >-
Maps test methods to the implementation methods they exercise.
dataTables:
- io.moderne.prethink.table.TestMapping
- org.openrewrite.java.dependencies.DependencyList:
scope: TestRuntime
includeTransitive: true
validateResolvable: false
- org.openrewrite.prethink.ExportContext:
displayName: Dependencies
shortDescription: Project dependencies including transitive dependencies
longDescription: >-
Complete dependency tree including transitive dependencies.
dataTables:
- org.openrewrite.java.dependencies.table.DependencyListReport
- org.openrewrite.javascript.search.DependencyInsight:
namePattern: "*"
- org.openrewrite.prethink.ExportContext:
displayName: Node.js Dependencies
shortDescription: npm package dependencies with versions, scopes, and licenses
longDescription: >-
Node.js package dependencies from package.json including resolved versions
and dependency scopes.
dataTables:
- org.openrewrite.javascript.table.NodeDependenciesInUse
# Phase 4: CALM Architecture & Agent Configuration
- org.openrewrite.prethink.UpdatePrethinkContext
- io.moderne.prethink.calm.GenerateCalmMermaidDiagram
For example, if you want to add custom discovery on top of the starter, you could wrap it in your own recipe. Here's what that might look like if you wanted to extract service relationships from proprietary configuration or property files:
type: specs.openrewrite.org/v1beta/recipe
name: com.example.prethink.ExtendedPrethink
displayName: Extended Prethink context
description: >-
Extends the standard Prethink starter with custom discovery
for internal frameworks and configuration files.
recipeList:
# Include everything from the standard starter
- io.moderne.prethink.UpdatePrethinkContextNoAiStarter
# Add custom discovery for your proprietary patterns
- com.example.discovery.FindPropertyFileRelationships
- com.example.discovery.FindInternalFrameworkEndpoints
# Export custom data tables
- org.openrewrite.prethink.ExportContext:
displayName: Property File Relationships
shortDescription: Service relationships from property files
longDescription: >-
Relationships between services extracted from internal
property files that are not detected by standard discovery.
dataTables:
- com.example.table.PropertyFileRelationships
Setting up a recipe repository
If you want full control over what discovery runs, you can build a Prethink recipe from scratch using either the Moderne or OpenRewrite module. To get started:
-
Create a new recipe repository using either the rewrite-recipe-starter or your own internal recipe starter template.
-
Add a dependency on the Prethink modules in your
build.gradle:
dependencies {
// For pre-configured discovery (recommended)
implementation("io.moderne.recipe:rewrite-prethink:latest.release")
// Or for building blocks only
implementation("org.openrewrite.recipe:rewrite-prethink:latest.release")
}
The Moderne module includes all recipes from the OpenRewrite module plus framework-specific discovery and LLM integrations.
Recipe examples
Complete Prethink configuration
This example runs all discovery phases and generates comprehensive context:
type: specs.openrewrite.org/v1beta/recipe
name: com.example.prethink.UpdatePrethinkContext
displayName: Update Prethink context
description: >-
Generates comprehensive Prethink context for AI agents including
service endpoints, dependencies, test coverage, and architecture.
recipeList:
# Phase 1: Architectural Discovery
- io.moderne.prethink.calm.FindProjectMetadata
- io.moderne.prethink.calm.FindServiceEndpoints
- io.moderne.prethink.calm.FindDatabaseConnections
- io.moderne.prethink.calm.FindExternalServiceCalls
- io.moderne.prethink.calm.FindMessagingConnections
- io.moderne.prethink.calm.FindServerConfiguration
- io.moderne.prethink.calm.FindSecurityConfiguration
- io.moderne.prethink.calm.FindDeploymentArtifacts
- io.moderne.prethink.calm.FindDataAssets
- io.moderne.prethink.calm.FindServiceComponents
- io.moderne.prethink.calm.FindCalmRelationships
# Phase 2: Code Analysis
- io.moderne.prethink.ExtractCodingConventions
- io.moderne.prethink.ExtractDependencyUsage
- io.moderne.prethink.ExtractErrorPatterns
# Phase 3: Test Coverage
- io.moderne.prethink.FindTestCoverage
# Phase 4: Context Generation
- io.moderne.prethink.calm.GenerateCalmArchitecture
- io.moderne.prethink.calm.GenerateCalmMermaidDiagram
- org.openrewrite.prethink.UpdateAgentConfig
Minimal Prethink configuration
If you only need basic service endpoint discovery:
type: specs.openrewrite.org/v1beta/recipe
name: com.example.prethink.MinimalPrethink
displayName: Minimal Prethink context
description: >-
Generates basic Prethink context with service endpoints only.
recipeList:
- io.moderne.prethink.calm.FindProjectMetadata
- io.moderne.prethink.calm.FindServiceEndpoints
- org.openrewrite.prethink.ExportContext:
displayName: Service Endpoints
shortDescription: REST and HTTP endpoints
dataTables:
- io.moderne.prethink.table.ServiceEndpoints
- org.openrewrite.prethink.UpdateAgentConfig
Prethink with AI summaries
To enable AI-generated summaries, configure the LLM provider:
type: specs.openrewrite.org/v1beta/recipe
name: com.example.prethink.PrethinkWithAI
displayName: Prethink context with AI summaries
description: >-
Generates Prethink context with AI-enhanced test summaries.
recipeList:
- io.moderne.prethink.calm.FindProjectMetadata
- io.moderne.prethink.calm.FindServiceEndpoints
- io.moderne.prethink.FindTestCoverage:
provider: poolside
- io.moderne.prethink.calm.GenerateCalmArchitecture
- org.openrewrite.prethink.UpdateAgentConfig
Custom discovery with OpenRewrite module
When using the OpenRewrite module, you provide your own discovery recipes:
type: specs.openrewrite.org/v1beta/recipe
name: com.example.prethink.CustomPrethink
displayName: Custom Prethink context
description: >-
Generates Prethink context using custom discovery recipes.
recipeList:
# Your custom discovery recipe that populates a data table
- com.example.discovery.FindCustomEndpoints
# Export the custom data table to CSV
- org.openrewrite.prethink.ExportContext:
displayName: Custom Endpoints
shortDescription: Custom framework endpoints
longDescription: >-
Endpoints discovered from our internal framework.
dataTables:
- com.example.table.CustomEndpoints
# Update agent configuration files
- org.openrewrite.prethink.UpdateAgentConfig
Your custom discovery recipe would implement the logic to find architectural elements specific to your frameworks and populate a data table. See the OpenRewrite recipe development documentation for guidance on creating custom recipes.
Recipes do not have to be in the same file or even the same module. You can compose Prethink recipes by referencing recipes from other modules.
Data tables
Prethink recipes populate several data tables that capture different aspects of your codebase:
| Data table | Description |
|---|---|
ServiceEndpoints | REST/HTTP endpoints with HTTP methods, paths, and framework info |
DatabaseConnections | JPA entities, repositories, JDBC connections, and Node.js ORM models |
ExternalServiceCalls | Outbound HTTP calls to external services |
MessagingConnections | Kafka, RabbitMQ, JMS, and other messaging patterns |
TestMapping | Mapping of test methods to implementation methods |
SecurityConfiguration | Spring Security, CORS, OAuth2, and Node.js security middleware |
ServerConfiguration | Port, SSL, and context path settings |
DeploymentArtifacts | Dockerfile, Kubernetes, and docker-compose files |
DataAssets | Entities, records, and DTOs |
ProjectMetadata | Artifact ID, group ID, and project name |
ServiceComponents | Service layer components (@Service, @Component, @Named) |
CodingConventions | Naming patterns, import organization, and documentation conventions |
DependencyUsage | External library dependencies and how they are used in the codebase |
ErrorHandlingPatterns | Error/exception handling patterns, strategies, and logging frameworks |
CalmRelationships | Method call graph for discovering relationships between architectural entities |
ContextRegistry | Registry of available context files for coding agents |
SourceSetLanguageSummary | Language versions, file counts, and build tools per source set |
ClassDescriptions | AI-generated class descriptions (with AI recipe) |
MethodDescriptions | AI-generated method descriptions (with AI recipe) |
For the full schema definitions, see the data table source code in openrewrite/rewrite-prethink and moderneinc/rewrite-prethink.
What Prethink generates
After running a Prethink recipe, you'll find generated files in the .moderne/context/ directory (there will be a .moderne directory created inside of each repository):
.moderne/context/
├── calm-architecture.json
├── class-descriptions.csv
├── class-descriptions.md
├── coding-conventions.csv
├── coding-conventions.md
├── database-connections.csv
├── database-connections.md
├── dependencies.csv
├── dependencies.md
├── dependency-usage.csv
├── dependency-usage.md
├── error-handling.csv
├── error-handling.md
├── method-descriptions.csv
├── method-descriptions.md
├── service-endpoints.csv
├── service-endpoints.md
├── test-mapping.csv
├── test-mapping.md
└── architecture-diagram.md
- CSV files contain structured data that AI agents can parse directly
- Markdown files describe the context and schema for human and agent readability
- CALM architecture JSON can be visualized with CALM-compatible tools
- Mermaid architecture diagram can be rendered by GitHub, GitLab, and other platforms
Context export
The context export component saves structured data tables as files in your repository. This allows any AI agent to access resolved knowledge about your codebase without needing to parse and understand the code itself.
Each exported context file is accompanied by a markdown file that describes what the data contains and how to interpret it. This helps AI agents understand the schema and meaning of the data without additional prompting.

Code comprehension
The optional code comprehension component uses Moderne's LST analysis combined with your bring-your-own LLM to build a knowledge graph. This graph captures how software components, dependencies, and behaviors relate at a system level. Descriptions are cached based on SHA-256 checksums of the source code, so re-running Prethink only generates descriptions for code that has changed.
Architecture visualization
Prethink can export architecture information in CALM format, providing nodes and relationships that describe your system's structure. These can be visualized with CALM-compatible tools or consumed directly by AI agents for architectural reasoning. Prethink also generates a Mermaid architecture diagram in markdown format for easy rendering in GitHub, GitLab, and other platforms that support Mermaid.

How agents discover Prethink context
When Prethink runs, it updates the agent configuration files in your repository (such as AGENTS.md, CLAUDE.md, .cursorrules, or .github/copilot-instructions.md) to point AI agents to the generated context. This enables progressive discovery where agents first learn about the available context and then read the relevant files as needed.

The agent configuration includes a table of available context types with descriptions and file paths, along with instructions on how to use the context effectively. This means agents can immediately start reasoning over pre-resolved facts about your codebase.