Kafka Cartographer is a static analysis tool designed to map Kafka topic definitions and usages across your Java projects. It scans your codebase to identify where topics are defined (as constants), where they are consumed (via @KafkaListener), and where they are produced (via send() methods).
In large distributed systems, tracking Kafka topic dependencies can be difficult. This tool helps visualize and audit the flow of messages by generating a JSON report linking topic definitions to their producers and consumers.
- Static Analysis: Uses
JavaParserto safely parse and analyze source code without compiling. - Definition Detection: Finds static string constants that look like topic definitions.
- Usage Detection: Identifies topic usages in:
- Spring
@KafkaListenerannotations. KafkaTemplate.send()orProducer.send()method calls.
- Spring
- Symbol Resolution: Attempts to link usages back to their original constant definitions.
- JSON Reporting: Outputs a clear
topic_map.jsonfile containing found links and literals.
- Docker
- Bash (Linux/macOS)
The easiest way to use the tool is via the included CLI script, which handles Docker commands for you.
-
Make the script executable (first time only):
chmod +x run.sh
-
Run the script:
./run.sh
-
Select an option from the menu:
- 1. Scan a project: Prompts for a directory path (absolute) and generates the
topic_map.json. - 2. Visualize results: Builds and starts the web server to view the map at
http://localhost:8080.
- 1. Scan a project: Prompts for a directory path (absolute) and generates the
You can build and run the application easily using Docker, without needing to install Java or Maven locally.
Run the following command in the project root:
docker build -t kafka-cartographer .To scan a directory on your local machine, you must mount it as a volume into the container. The tool will generate the report inside that directory.
Syntax:
docker run --rm -v <HOST_PATH_TO_SCAN>:/scan kafka-cartographer /scanExample: To scan your current directory:
docker run --rm -v $(pwd):/scan kafka-cartographer /scanTo scan a specific project path:
docker run --rm -v /home/user/my-projects:/scan kafka-cartographer /scanThe repository includes a sample folder with a dummy Java project to test the scanner.
docker run --rm -v $(pwd)/sample:/scan kafka-cartographer /scanThe project includes an index.html file to visualize the generated topic_map.json. You can serve this using a Docker container.
docker build -f Dockerfile.visualization -t kafka-cartographer-web .docker run --rm -p 8080:80 kafka-cartographer-webHere is an example of the generated topic map:
