

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
1<!--2Licensed to the Apache Software Foundation (ASF) under one3or more contributor license agreements. See the NOTICE file4distributed with this work for additional information5regarding copyright ownership. The ASF licenses this file6to you under the Apache License, Version 2.0 (the7"License"); you may not use this file except in compliance8with the License. You may obtain a copy of the License at910 http://www.apache.org/licenses/LICENSE-2.01112Unless required by applicable law or agreed to in writing,13software distributed under the License is distributed on an14"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15KIND, either express or implied. See the License for the16specific language governing permissions and limitations17under the License.18-->1920# Flink AI Agent Instructions2122This file provides guidance for AI coding agents working with the Apache Flink codebase.2324## Prerequisites2526- Java 11, 17 (default), or 21. Java 11 syntax must be used in all modules. Java 17 syntax (records, sealed classes, pattern matching) is only permitted in the `flink-tests-java17` module.27- Maven 3.8.6 (Maven wrapper `./mvnw` included; prefer it)28- Git29- Unix-like environment (Linux, macOS, WSL, Cygwin)3031## Commands3233### Build3435- Fast dev build: `./mvnw clean install -DskipTests -Dfast -Pskip-webui-build -T1C`36- Full build (Java 17 default): `./mvnw clean package -DskipTests -Djdk17 -Pjava17-target`37- Java 11: `./mvnw clean package -DskipTests -Djdk11 -Pjava11-target`38- Java 21: `./mvnw clean package -DskipTests -Djdk21 -Pjava21-target`39- Full build with tests: `./mvnw clean verify`40- Single module: `./mvnw clean package -DskipTests -pl flink-core-api`41- Single module with tests: `./mvnw clean verify -pl flink-core-api`4243### Testing4445- Single test class: `./mvnw -pl flink-core-api -Dtest=MemorySizeTest test`46- Single test method: `./mvnw -pl flink-core-api -Dtest=MemorySizeTest#testParseBytes test`4748### Code Quality4950- Format code (Java + Scala): `./mvnw spotless:apply`51- Check formatting: `./mvnw spotless:check`52- Checkstyle: `./mvnw checkstyle:check -T1C`53- Checkstyle config: `tools/maven/checkstyle.xml`5455## Repository Structure5657Every module from the root pom.xml, organized by function. Flink provides three main user-facing APIs (recommended in this order: SQL, Table API, DataStream API) plus a newer DataStream v2 API.5859### Core Infrastructure6061- `flink-annotations` — Stability annotations (`@Public`, `@PublicEvolving`, `@Internal`, `@Experimental`) and `@VisibleForTesting`62- `flink-core-api` — Core API interfaces (functions, state, types) shared by all APIs63- `flink-core` — Core implementation (type system, serialization, memory management, configuration)64- `flink-runtime` — Distributed runtime (JobManager, TaskManager, scheduling, network, state)65- `flink-clients` — CLI and client-side job submission66- `flink-rpc/` — RPC framework67 - `flink-rpc-core` — RPC interfaces68 - `flink-rpc-akka`, `flink-rpc-akka-loader` — Pekko-based RPC implementation6970### SQL / Table API (recommended API for most users)7172- `flink-table/`73 - `flink-sql-parser` — SQL parser (extends Calcite SQL parser)74 - `flink-table-common` — Shared types, descriptors, catalog interfaces75 - `flink-table-api-java` — Table API for Java76 - `flink-table-api-scala` — Table API for Scala77 - `flink-table-api-bridge-base`, `flink-table-api-java-bridge`, `flink-table-api-scala-bridge` — Bridges between Table and DataStream APIs78 - `flink-table-api-java-uber` — Uber JAR for Table API79 - `flink-table-planner` — SQL/Table query planning and optimization (Calcite-based)80 - `flink-table-planner-loader`, `flink-table-planner-loader-bundle` — Classloader isolation for planner81 - `flink-table-runtime` — Runtime operators for Table/SQL queries82 - `flink-table-calcite-bridge` — Bridge to Apache Calcite83 - `flink-sql-gateway-api`, `flink-sql-gateway` — SQL Gateway for remote SQL execution84 - `flink-sql-client` — Interactive SQL CLI85 - `flink-sql-jdbc-driver`, `flink-sql-jdbc-driver-bundle` — JDBC driver for SQL Gateway86 - `flink-table-code-splitter` — Code generation utilities87 - `flink-table-test-utils` — Test utilities for Table/SQL8889### DataStream API (original streaming API)9091- `flink-streaming-java` — DataStream API and stream processing operator implementations9293### DataStream API v2 (newer event-driven API)9495- `flink-datastream-api` — DataStream v2 API definitions96- `flink-datastream` — DataStream v2 API implementation9798### Connectors (in-tree)99100- `flink-connectors/`101 - `flink-connector-base` — Base classes for source/sink connectors102 - `flink-connector-files` — Unified file system source and sink103 - `flink-connector-datagen` — DataGen source for testing104 - `flink-connector-datagen-test` — Tests for DataGen connector105 - `flink-hadoop-compatibility` — Hadoop InputFormat/OutputFormat compatibility106 - `flink-file-sink-common` — Common file sink utilities107- Most connectors (Kafka, JDBC, Elasticsearch, etc.) live in separate repos under [github.com/apache](https://github.com/apache); see README.md for the full list108109### Formats110111- `flink-formats/`112 - `flink-json`, `flink-csv`, `flink-avro`, `flink-parquet`, `flink-orc`, `flink-protobuf` — Serialization formats113 - `flink-avro-confluent-registry` — Avro with Confluent Schema Registry114 - `flink-sequence-file`, `flink-compress`, `flink-hadoop-bulk`, `flink-orc-nohive` — Hadoop-related formats115 - `flink-format-common` — Shared format utilities116 - `flink-sql-json`, `flink-sql-csv`, `flink-sql-avro`, `flink-sql-parquet`, `flink-sql-orc`, `flink-sql-protobuf` — SQL-layer format integrations117 - `flink-sql-avro-confluent-registry` — SQL-layer Avro with Confluent Schema Registry118119### State Backends120121- `flink-state-backends/`122 - `flink-statebackend-rocksdb` — RocksDB state backend123 - `flink-statebackend-forst` — ForSt state backend (experimental; a fork of RocksDB)124 - `flink-statebackend-heap-spillable` — Heap-based spillable state backend125 - `flink-statebackend-changelog` — Changelog state backend126 - `flink-statebackend-common` — Shared state backend utilities127- `flink-dstl/flink-dstl-dfs` — State changelog storage (DFS-based persistent changelog for incremental checkpointing)128129### File Systems130131- `flink-filesystems/`132 - `flink-hadoop-fs` — Hadoop FileSystem abstraction133 - `flink-s3-fs-native`, `flink-s3-fs-hadoop`, `flink-s3-fs-presto`, `flink-s3-fs-base` — S3 file systems134 - `flink-oss-fs-hadoop` — Alibaba OSS135 - `flink-azure-fs-hadoop` — Azure Blob Storage136 - `flink-gs-fs-hadoop` — Google Cloud Storage137 - `flink-fs-hadoop-shaded` — Shaded Hadoop dependencies138139### Queryable State140141- `flink-queryable-state/`142 - `flink-queryable-state-runtime` — Server-side queryable state service143 - `flink-queryable-state-client-java` — Client for querying operator state from running jobs144145### Deployment146147- `flink-kubernetes` — Kubernetes integration148- `flink-yarn` — YARN integration149- `flink-dist`, `flink-dist-scala` — Distribution packaging150- `flink-container` — Container entry-point and utilities for containerized deployments151152### Metrics153154- `flink-metrics/`155 - `flink-metrics-core` — Metrics API and core implementation156 - Reporter implementations: `flink-metrics-jmx`, `flink-metrics-prometheus`, `flink-metrics-datadog`, `flink-metrics-statsd`, `flink-metrics-graphite`, `flink-metrics-influxdb`, `flink-metrics-slf4j`, `flink-metrics-dropwizard`, `flink-metrics-otel`157158### Libraries159160- `flink-libraries/`161 - `flink-cep` — Complex Event Processing162 - `flink-state-processing-api` — Offline state access (savepoint reading/writing)163164### Other165166- `flink-models` — AI model integration (sub-modules: `flink-model-openai`, `flink-model-triton`)167- `flink-python` — PyFlink (Python API)168- `flink-runtime-web` — Web UI for JobManager dashboard169- `flink-external-resources` — External resource management (e.g., GPU)170- `docs/` — Documentation content (Hugo site). This is where user-facing docs are written.171- `flink-docs` — Documentation build module (auto-generated config reference docs)172- `flink-examples` — Example programs173- `flink-quickstart` — Maven archetype for new projects174- `flink-walkthroughs` — Tutorial walkthrough projects175176### Testing177178- `flink-tests` — Integration tests179- `flink-end-to-end-tests` — End-to-end tests180- `flink-test-utils-parent` — Test utility classes181- `flink-yarn-tests` — YARN-specific tests182- `flink-fs-tests` — FileSystem tests183- `flink-architecture-tests` — ArchUnit architectural boundary tests184- `tools/ci/flink-ci-tools` — CI tooling185186## Architecture Boundaries1871881. **Client** submits jobs to the cluster. Submission paths include the CLI (`bin/flink run` via `flink-clients`), the SQL Client (`bin/sql-client.sh` via `flink-sql-client`), the SQL Gateway (`flink-sql-gateway`, also accessible via JDBC driver), the REST API (direct HTTP to JobManager), programmatic execution (`StreamExecutionEnvironment.execute()` or `TableEnvironment.executeSql()`), and PyFlink (`flink-python`, wraps the Java APIs).1892. **JobManager** (`flink-runtime`) orchestrates execution: receives jobs, creates the execution graph, manages scheduling, coordinates checkpoints, and handles failover. Never runs user code directly.1903. **TaskManager** (`flink-runtime`) executes the user's operators in task slots. Manages network buffers, state backends, and I/O.1914. **Table Planner** (`flink-table-planner`) translates SQL/Table API programs into DataStream programs. The planner is loaded in a separate classloader (`flink-table-planner-loader`) to isolate Calcite dependencies.1925. **Connectors** communicate with external systems. Source connectors implement the `Source` API (FLIP-27); sinks implement the `Sink` API (package `sink2`). Most connectors are externalized to separate repositories.1936. **State Backends** persist keyed state and operator state. RocksDB is the primary backend for production use.1947. **Checkpointing** provides exactly-once guarantees. The JobManager coordinates barriers through the data stream; TaskManagers snapshot local state to a distributed file system.195196Key separations:197198- **Planner vs Runtime:** The table planner generates code and execution plans; the runtime executes them. Changes to planning logic live in `flink-table-planner`; changes to runtime operators live in `flink-table-runtime` or `flink-streaming-java`.199- **Codegen vs hand-written operators:** Per-record expression logic (casts, projections, filters, function calls) is generated at planning time by cast rules in `flink-table-planner/.../functions/casting/` and call generators in `flink-table-planner/.../codegen/calls/`, then compiled by Janino into the surrounding operator class. Operators with fixed structure (joins, aggregations, source/sink runtime) are hand-written Java in `flink-table-runtime` or `flink-streaming-java`. New scalar functions usually only need a `BuiltInFunctionDefinitions` entry plus a `BuiltInScalarFunction` subclass - the planner wires up codegen automatically. New cast behaviour or a custom call shape needs a cast rule or call generator.200- **API vs Implementation:** Public API surfaces (`flink-core-api`, `flink-datastream-api`, `flink-table-api-java`) are separate from implementation modules. API stability annotations control what users can depend on.201- **ArchUnit enforcement:** `flink-architecture-tests/` contains ArchUnit tests that enforce module boundaries. New violations should be avoided; if unavoidable, follow the freeze procedure in `flink-architecture-tests/README.md`.202203## Common Change Patterns204205This section maps common types of Flink changes to the modules they touch and the verification they require.206207### Adding a new SQL built-in function2082091. Register in `flink-table-common` in `BuiltInFunctionDefinitions.java` (definition, input/output type strategies, runtime class reference)2102. Implement in `flink-table-runtime` under `functions/` (extend the appropriate base class: `BuiltInScalarFunction`, `BuiltInTableFunction`, `BuiltInAggregateFunction`, or `BuiltInProcessTableFunction`)2113. Add tests in `flink-table-planner` and `flink-table-runtime`2124. Extend Table API support2135. Document in `docs/`2146. See [flink-table/flink-table-planner/AGENTS.md](flink-table/flink-table-planner/AGENTS.md) and [flink-table/flink-table-runtime/AGENTS.md](flink-table/flink-table-runtime/AGENTS.md) for detailed patterns215216### Adding a new configuration option2172181. Define `ConfigOption<T>` in the relevant config class (e.g., `ExecutionConfigOptions.java` in `flink-table-api-java`)2192. Use `ConfigOptions.key("table.exec....")` builder with type, default value, and description2203. Add `@Documentation.TableOption` annotation for auto-generated docs2214. Document in `docs/` if user-facing2225. Verify: unit test for default value, ITCase for behavior change223224### Adding a new table operator (e.g., join type, aggregate)2252261. Involves `flink-table-runtime` (operator), `flink-table-planner` (ExecNode, physical/logical rules), and tests across both2272. See [flink-table/flink-table-planner/AGENTS.md](flink-table/flink-table-planner/AGENTS.md) and [flink-table/flink-table-runtime/AGENTS.md](flink-table/flink-table-runtime/AGENTS.md) for detailed development order and testing patterns228229### Adding a new connector (Source or Sink)2302311. Implement the `Source` API (`flink-connector-base`): `SplitEnumerator`, `SourceReader`, `SourceSplit`, serializers (`SimpleVersionedSerializer`)2322. Or implement the `Sink` API (package `sink2`) for sinks2333. Most new connectors go in separate repos under `github.com/apache`, not in the main Flink repo2344. Verify: unit tests + ITCase with real or embedded external system235236### Modifying state serializers2372381. Changes to `TypeSerializer` require a corresponding `TypeSerializerSnapshot` for migration2392. Bump version in `getCurrentVersion()`, handle old versions in `readSnapshot()`2403. Snapshot must have no-arg constructor for reflection-based deserialization2414. Implement `resolveSchemaCompatibility()` for upgrade paths2425. Verify: serializer snapshot migration tests, checkpoint restore tests across versions243244### Introducing or changing user-facing APIs (`@Public`, `@PublicEvolving`, `@Experimental`)2452461. New user-facing API requires a voted FLIP (Flink Improvement Proposal); this applies to `@Public`, `@PublicEvolving`, and `@Experimental` since users build against all three2472. Every user-facing API class and method must carry a stability annotation2483. Changes to existing `@Public` or `@PublicEvolving` API must maintain backward compatibility2494. `@Internal` APIs can be changed freely; users should not depend on them2505. Update JavaDoc on the changed class/method2516. Add to release notes2527. Verify: ArchUnit tests pass, no new architecture violations253254## Coding Standards255256- **Format Java files with Spotless immediately after editing:** `./mvnw spotless:apply`. Uses google-java-format with AOSP style.257- **Scala formatting:** Spotless + scalafmt (config at `.scalafmt.conf`, maxColumn 100).258- **Checkstyle:** `tools/maven/checkstyle.xml` (version defined in root `pom.xml` as `checkstyle.version`). Some modules (flink-core, flink-optimizer, flink-runtime) are not covered by checkstyle enforcement, but conventions should still be followed.259- **No new Scala code.** All Flink Scala APIs are deprecated per FLIP-265. Write all new code in Java.260- **Apache License 2.0 header** required on all new files (enforced by Apache Rat). Use an HTML comment for markdown files.261- **API stability annotations:** Every user-facing API class and method must have a stability annotation. `@Public` (stable across minor releases), `@PublicEvolving` (may change in minor releases), `@Experimental` (may change at any time). These are all part of the public API surface that users build against. `@Internal` marks APIs with no stability guarantees that users should not depend on.262- **Logging:** Use parameterized log statements (SLF4J `{}` placeholders), never string concatenation.263- **No Java serialization** for new features (except internal RPC message transport).264- **Use `final`** for variables and fields where applicable.265- **Comments:** Do not add unnecessary comments that restate what the code does. Add comments that explain "the why" where relevant.266- **Reuse existing code.** Before implementing new utilities or abstractions, search for existing ones in the codebase. Prioritize architecture consistency and code reusability.267- Full code style guide: https://flink.apache.org/how-to-contribute/code-style-and-quality-preamble/268269## Testing Standards270271- Add tests for new behavior, covering success, failure, and edge cases.272- Use **JUnit 5** + **AssertJ** assertions. Do not use JUnit 4 or Hamcrest in new test code.273- Prefer real test implementations over Mockito mocks where possible.274- **Integration tests:** Name classes with `ITCase` suffix (e.g., `MyFeatureITCase.java`).275- **Red-green verification:** For bug fixes, verify that new tests actually fail without the fix before confirming they pass with it.276- **Test location** mirrors source structure within each module.277- Follow the testing conventions at https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing278279## Commits and PRs280281### Commit message format282283- `[FLINK-XXXX][component] Description` where FLINK-XXXX is the JIRA issue number284- `[hotfix][component] Description` for typo fixes without JIRA285- Each commit must have a meaningful message including the JIRA ID. If you don't know the ticket number, ask.286- Separate cleanup/refactoring from functional changes into distinct commits287- When AI tools were used: add `Generated-by: <Tool Name and Version>` trailer per [ASF generative tooling guidance](https://www.apache.org/legal/generative-tooling.html)288289### Pull request conventions290291- Title format: `[FLINK-XXXX][component] Title of the pull request`292- A corresponding JIRA issue is required (except hotfixes for typos)293- Fill out the PR template completely but concisely: describe purpose, change log, testing approach, impact assessment294- Each PR should address exactly one issue295- Ensure `./mvnw clean verify` passes before opening a PR296- Always push to your fork, not directly to `apache/flink`297- Rebase onto the latest target branch before submitting298- For user-visible behaviour changes, breaking changes, new SQL features, or new config options: fill in the **Release Notes** field on the JIRA ticket. The release manager consolidates these when cutting a release. The next version's `docs/content/release-notes/flink-X.Y.md` will be generated based of the jira tickets, so make sure to fill them in properly.299300### AI-assisted contributions301302- Disclose AI usage by checking the AI disclosure checkbox and uncommenting the `Generated-by` line in the PR template303- Add `Generated-by: <Tool Name and Version>` to commit messages304- Never add `Co-Authored-By` with an AI agent as co-author; agents are assistants, not authors305- You must be able to explain the design, code, and tests, debug them, and respond to review feedback substantively306- Reviewer-ready quality bar: the author owns PR quality. PRs that look AI-generated without author refinement (walls of unreviewed prose, scaffolding without behaviour, tests that do not exercise the change, padded commit messages) will be closed without review307308## Code Review Guidelines309310When reviewing a PR or diff against this repo:311312- Look for opportunities to simplify the code, scoped to the diff itself (not pre-existing code outside the change).313- Flag comments that are obvious (restate what the code already says) or overly verbose.314- In test code, look for potential flakiness — e.g. `Thread.sleep` used outside a retry/poll loop, or similar timing-dependent, non-deterministic patterns. Where applicable, suggest clock injection (e.g. a manually-advanced `Clock`/`ManualClock`) instead of relying on wall-clock time, or waiting for the actual condition in a loop with a timeout, for deterministic tests.315- Check that each commit message conforms to Flink conventions: it must start with `[FLINK-XXXX]` or `[hotfix]`, and must specify a subsystem/component (e.g. `[FLINK-XXXX][runtime] Description`).316- If a change introduces a new feature controlled by a config option/flag, check that the resolved state (enabled/disabled, and the effective value) is logged at INFO level when the feature initializes/activates.317- Consider whether a change should be hidden behind a feature flag, especially if it's non-trivial (touches core paths, changes default behavior, or is hard to reason about in isolation). This is mandatory if the change is risky (correctness, performance, backward-compatibility, or data-safety risk) and no flag/kill-switch already exists.318- For changes to configuration options, check if the corresponding documentation has been regenerated (this should be covered by tests but flagging it earlier speeds up development)319320## Boundaries321322### Ask first323324- Adding or changing `@Public`, `@PublicEvolving`, or `@Experimental` annotations (these are user-facing API commitments requiring a FLIP)325- Large cross-module refactors326- New dependencies327- Changes to serialization formats (affects state compatibility)328- Changes to checkpoint/savepoint behavior329- Changes that could impact performance on hot paths (per-record processing, serialization, state access)330331### Never332333- Commit secrets, credentials, or tokens334- Push directly to `apache/flink`; always work from your fork335- Mix unrelated changes into one PR336- Use Java serialization for new features337- Edit generated files by hand when a generation workflow exists338- Use the legacy `SourceFunction` or `SinkFunction` interfaces for connectors; use the `Source` API (FLIP-27) and `Sink` API (package `sink2`) instead339- Add `Co-Authored-By` with an AI agent as co-author in commit messages; AI agents are assistants, not authors. Use `Generated-by: <Tool Name and Version>` instead.340- Suppress or bypass checkstyle rules (no `CHECKSTYLE:ON`/`CHECKSTYLE:OFF` comments, no adding entries to `tools/maven/suppressions.xml`, no `@SuppressWarnings`). Fix the code to satisfy checkstyle instead.341- Add, change, or remove classes outside the `org.apache.flink.*` package (for example, classes copied from Calcite)342- Modify `Parser.jj` (Calcite's generated parser grammar; expected to be removed in future Calcite upgrades)343- Use destructive git operations unless explicitly requested344345## References346347- [README.md](README.md) — Build instructions and project overview348- [DEVELOPMENT.md](DEVELOPMENT.md) — IDE setup and development environment349- [.github/CONTRIBUTING.md](.github/CONTRIBUTING.md) — Contribution process350- [.github/PULL_REQUEST_TEMPLATE.md](.github/PULL_REQUEST_TEMPLATE.md) — PR checklist351- [Code Style Guide](https://flink.apache.org/how-to-contribute/code-style-and-quality-preamble/) — Detailed coding guidelines352- [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) — AI tooling policy353
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| apache/flinkflink-table/flink-table-planner/AGENTS.md · 26k | AGENTS.md | buildteststylearch+1 | 61/100 | today | |
| apache/flinkflink-table/flink-table-runtime/AGENTS.md · 26k | AGENTS.md | teststylearch | 60/100 | today |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| vllm-project/vllmAGENTS.md · 89k | AGENTS.md | setuptestlint-formatstyle+5 | 100/100 | 14 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 14 days ago | |
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 68k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 13 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | today | |
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 201k | AGENTS.md | buildteststylearch+3 | 100/100 | 14 days ago | |
| deepseek-ai/deepseek-harnessnative/landlock-run/AGENTS.md · 104k | AGENTS.md | setupteststylearch+3 | 100/100 | today | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 14 days ago | |
| elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+2 | 100/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/apache-flink-agents)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.