mica-mqtt
AGENTS.md495 starsChanged 7 months agoApache-2.0View on GitHub
This file provides context, commands, and coding standards for AI agents to effectively and safely modify this codebase. --> Note: Always run tests after modifications to ensure no regressions.
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 32,671 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- CLAUDE.mdCLAUDE.md
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
21 rules. About 1 is common, 11 are distinctive, and 9 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 46
Indentation: Use TABS (not spaces).
- Very specific: line 60
Use the Builder pattern manually if complex object creation is needed (see MqttWillMessage).
- Distinctive: line 65
All new Java files must include the Apache License 2.0 header:
- Distinctive: line 86
Use SLF4J for logging.
- Very specific: line 88
Use appropriate log levels: debug for verbose info, info for important events, warn/error for issues.
- Very specific: line 89
Avoid excessive info logging in high-frequency code paths (e.g., message handling).
- Very specific: line 92
Avoid wildcard imports (import java.util.*;).
- Distinctive: line 97
Use import statements instead of fully qualified class names in code.
- Very specific: line 100
Use specific exception types rather than generic Exception.
- Distinctive: line 102
Avoid swallowing exceptions silently unless explicitly intended.
- Distinctive: line 114
Use primitive types where possible for performance.
- Very specific: line 115
Use List, Map, Set interfaces rather than concrete implementations in method signatures.
- Very specific: line 122
Serialization: Use the MqttSerializer interface for payload serialization.
- Distinctive: line 137
Write unit tests for new logic using JUnit (Jupiter).
- Very specific: line 138
Place tests in the src/test/java directory corresponding to the package structure.
- Distinctive: line 144
No Assumptions: Always verify file existence and content before editing.
- Distinctive: line 145
Minimal Changes: Only modify what is necessary to fulfill the request.
- Distinctive: line 146
Preserve Style: If you see a file using a specific style (even if it contradicts general rules), follow the file's local style (except for …
- Common: line 147
Safety: Do not commit secrets or breaking changes without user confirmation.
- Very specific: line 148
Verification: After making changes, always run mvn compile to verify the code compiles.
- Distinctive: line 149
Testing: Run relevant tests after modifications to ensure no regressions.
≈ “Common” is an estimate: at least 1 in 5 of the 41,581 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!--
AGENTS.md - Instructions for AI Agents working on mica-mqtt
This file provides context, commands, and coding standards for AI agents
to effectively and safely modify this codebase.
-->mica-mqtt Agent Guidelines
1. Environment & Build
- Language: Java 8 (
<java.version>1.8</java.version>). - Build Tool: Maven 3.x.
- Project Structure: Multi-module Maven project.
Modules
| Module | Description |
mica-mqtt-codec | MQTT protocol codec |
mica-mqtt-common | Common utilities and models |
mica-mqtt-core | Core server/client interfaces |
mica-mqtt-server | MQTT broker implementation |
mica-mqtt-client | MQTT client implementation |
mica-mqtt-broker | Enhanced broker with cluster support (t-io based) |
starter | Spring Boot, Solon, JFinal integrations |
example | Usage examples |
Key Commands
| Action | Command |
| Build Project | mvn clean install |
| Run All Tests | mvn test |
| Run Single Test Class | mvn -Dtest=TargetTestClass test |
| Run Single Test Method | mvn -Dtest=TargetTestClass#methodName test |
| Compile Only | mvn compile |
| Package | mvn package -DskipTests |
| Run Tests in Specific Module | cd mica-mqtt-broker && mvn test |
Note: Always run tests after modifications to ensure no regressions.
2. Code Style & Conventions
Formatting
- Indentation: Use TABS (not spaces).
- Encoding: UTF-8.
- Line Endings: LF (Unix-style).
Naming
- Classes:
PascalCase(e.g.,MqttServer,MqttConnectStatusListener). - Methods/Variables:
camelCase(e.g.,publishMessage,clientId). - Constants:
UPPER_SNAKE_CASE(e.g.,MAX_MESSAGE_SIZE). - Packages:
lowercase(e.g.,org.dromara.mica.mqtt.core).
Lombok Usage
- Core Modules (
mica-mqtt-server,mica-mqtt-client,mica-mqtt-common,mica-mqtt-codec,mica-mqtt-broker):- DO NOT USE LOMBOK.
- Manually implement
getters,setters,equals,hashCode,toString, andconstructors. - Use the Builder pattern manually if complex object creation is needed (see
MqttWillMessage).
- Starter/Example Modules:
- Lombok (e.g.,
@Data) is acceptable in these layers but prefer consistency with existing code.
- Lombok (e.g.,
License Header
All new Java files must include the Apache License 2.0 header:
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & dreamlu.net).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/Logging
- Use SLF4J for logging.
private static final Logger logger = LoggerFactory.getLogger(ClassName.class);- Use appropriate log levels:
debugfor verbose info,infofor important events,warn/errorfor issues. - Avoid excessive
infologging in high-frequency code paths (e.g., message handling).
Imports
- Avoid wildcard imports (
import java.util.*;). - Group imports in this order:
- Project specific imports (
org.dromara...) - Third-party libraries (
org.slf4j...,org.tio...) - Standard Java (
java...,javax...)
- Project specific imports (
- Use import statements instead of fully qualified class names in code.
Error Handling
- Use specific exception types rather than generic
Exception. - Log exceptions with appropriate context before rethrowing or handling.
- Avoid swallowing exceptions silently unless explicitly intended.
- Example:
try { // code } catch (IOException e) { logger.error("Failed to process message from node: {}", nodeId, e); return; }
Types
- Use primitive types where possible for performance.
- Use
List,Map,Setinterfaces rather than concrete implementations in method signatures. - Initialize collections with appropriate implementations (e.g.,
ArrayList,HashMap,HashSet).
3. Architecture & Patterns
- Asynchronous IO: The project is built on
t-io. Be careful with blocking operations in IO threads. - Thread Safety: Core classes like
MqttServerare often accessed concurrently. Ensure thread safety for shared state. - Serialization: Use the
MqttSerializerinterface for payload serialization. - Design Patterns:
- Builder: Used for complex configuration/message objects (e.g.,
MqttPublishMessage.builder()). - Listener: Heavily used for events (
MqttProtocolListener,IMqttMessageListener). - Decorator: Used in
mica-mqtt-brokerfor session management (ClusterMqttSessionManagerwrapsIMqttSessionManager).
- Builder: Used for complex configuration/message objects (e.g.,
Cluster Module (mica-mqtt-broker)
- Built on t-io cluster for node-to-node communication.
- Uses
MqttBroker.create()as entry point for cluster brokers. - Fluent API for configuration (
MqttClusterConfig.enabled(true).clusterPort(9001)). - Cluster messages inherit from
ClusterMessagebase class. - Session state is synchronized across nodes via
ClusterMqttSessionManager.
4. Testing
- Write unit tests for new logic using JUnit (Jupiter).
- Place tests in the
src/test/javadirectory corresponding to the package structure. - Mock external dependencies where possible to keep tests fast.
- Cluster integration tests may have Windows-specific cleanup issues with t-io; focus on test assertions passing.
5. Agent Behavior Rules
- No Assumptions: Always verify file existence and content before editing.
- Minimal Changes: Only modify what is necessary to fulfill the request.
- Preserve Style: If you see a file using a specific style (even if it contradicts general rules), follow the file's local style (except for clearly erroneous logic).
- Safety: Do not commit secrets or breaking changes without user confirmation.
- Verification: After making changes, always run
mvn compileto verify the code compiles. - Testing: Run relevant tests after modifications to ensure no regressions.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

