## Description Closes: #9404 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
100 lines
4.5 KiB
Markdown
100 lines
4.5 KiB
Markdown
<!--
|
||
order: 12
|
||
-->
|
||
|
||
# Recommended Folder Structure
|
||
|
||
This document outlines the recommended structure of Cosmos SDK modules. These ideas are meant to be applied as suggestions. Application developers are encouraged to improve upon and contribute to module structure and development design. {synopsis}
|
||
|
||
## Structure
|
||
|
||
A typical Cosmos SDK module can be structured as follows:
|
||
|
||
```shell
|
||
proto
|
||
└── {project_name}
|
||
└── {module_name}
|
||
└── {proto_version}
|
||
├── {module_name}.proto
|
||
├── event.proto
|
||
├── genesis.proto
|
||
├── query.proto
|
||
└── tx.proto
|
||
```
|
||
|
||
* `{module_name}.proto`: The module's common message type definitions.
|
||
* `event.proto`: The module's message type definitions related to events.
|
||
* `genesis.proto`: The module's message type definitions related to genesis state.
|
||
* `query.proto`: The module's Query service and related message type definitions.
|
||
* `tx.proto`: The module's Msg service and related message type definitions.
|
||
|
||
```shell
|
||
x/{module_name}
|
||
├── client
|
||
│ ├── cli
|
||
│ │ ├── query.go
|
||
│ │ └── tx.go
|
||
│ └── testutil
|
||
│ ├── cli_test.go
|
||
│ └── suite.go
|
||
├── exported
|
||
│ └── exported.go
|
||
├── keeper
|
||
│ ├── genesis.go
|
||
│ ├── grpc_query.go
|
||
│ ├── hooks.go
|
||
│ ├── invariants.go
|
||
│ ├── keeper.go
|
||
│ ├── keys.go
|
||
│ ├── msg_server.go
|
||
│ └── querier.go
|
||
├── module
|
||
│ └── module.go
|
||
├── simulation
|
||
│ ├── decoder.go
|
||
│ ├── genesis.go
|
||
│ ├── operations.go
|
||
│ └── params.go
|
||
├── spec
|
||
│ ├── 01_concepts.md
|
||
│ ├── 02_state.md
|
||
│ ├── 03_messages.md
|
||
│ └── 04_events.md
|
||
├── {module_name}.pb.go
|
||
├── abci.go
|
||
├── codec.go
|
||
├── errors.go
|
||
├── events.go
|
||
├── events.pb.go
|
||
├── expected_keepers.go
|
||
├── genesis.go
|
||
├── genesis.pb.go
|
||
├── keys.go
|
||
├── msgs.go
|
||
├── params.go
|
||
├── query.pb.go
|
||
└── tx.pb.go
|
||
```
|
||
|
||
* `client/`: The module's CLI client functionality implementation and the module's integration testing suite.
|
||
* `exported/`: The module's exported types - typically interface types. If a module relies on keepers from another module, it is expected to receive the keepers as interface contracts through the `expected_keepers.go` file (see below) in order to avoid a direct dependency on the module implementing the keepers. However, these interface contracts can define methods that operate on and/or return types that are specific to the module that is implementing the keepers and this is where `exported/` comes into play. The interface types that are defined in `exported/` use canonical types, allowing for the module to receive the keepers as interface contracts through the `expected_keepers.go` file. This pattern allows for code to remain DRY and also alleviates import cycle chaos.
|
||
* `keeper/`: The module's `Keeper` and `MsgServer` implementation.
|
||
* `module/`: The module's `AppModule` and `AppModuleBasic` implementation.
|
||
* `simulation/`: The module's [simulation](./simulator.html) package defines functions used by the blockchain simulator application (`simapp`).
|
||
* `spec/`: The module's specification documents outlining important concepts, state storage structure, and message and event type definitions.
|
||
* The root directory includes type definitions for messages, events, and genesis state, including the type definitions generated by Protocol Buffers.
|
||
* `abci.go`: The module's `BeginBlocker` and `EndBlocker` implementations (this file is only required if `BeginBlocker` and/or `EndBlocker` need to be defined).
|
||
* `codec.go`: The module's registry methods for interface types.
|
||
* `errors.go`: The module's sentinel errors.
|
||
* `events.go`: The module's event types and constructors.
|
||
* `expected_keepers.go`: The module's [expected keeper](./keeper.html#type-definition) interfaces.
|
||
* `genesis.go`: The module's genesis state methods and helper functions.
|
||
* `keys.go`: The module's store keys and associated helper functions.
|
||
* `msgs.go`: The module's message type definitions and associated methods.
|
||
* `params.go`: The module's parameter type definitions and associated methods.
|
||
* `*.pb.go`: The module's type definitions generated by Protocol Buffers (as defined in the respective `*.proto` files above).
|
||
|
||
## Next {hide}
|
||
|
||
Learn about [Errors](./errors.md) {hide}
|