cosmos-sdk/docs/building-modules/structure.md
Marie Gauthier 589835dd98
Update Building Modules documentation (#7473)
* Update module-manager.md

* Update modules #messages doc

* Fix typo

* Update message implementation example link

* Update messages-and-queries.md#queries doc

* Update querier.md

* Update handler.md

* Update links in beginblock-endblock.md

* Update keeper.md

* Update invariants.md

* Update genesis.md

* Update module-interfaces.md#transaction-commands

* Update module-interfaces.md#query-commands

* Update module-interfaces.md#flags

* Update module-interfaces.md#rest

* Update structure.md

* Update module-interfaces.md#grpc

* Update errors.md

* Update module-interfaces.md#grpc-gateway-rest

* Add more info on swagger

* Address comments

* Fix go.sum

* Fix app-anatomy.md

* Update docs/building-modules/module-interfaces.md

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update docs/building-modules/querier.md

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update docs/building-modules/querier.md

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update docs/building-modules/module-interfaces.md

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update docs/building-modules/module-interfaces.md

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Address part of review comments

* Update old ref of RegisterQueryService

* Add example code for Manager

* Update queriers.md to query-services.md and refs

* Add new query-services.md

* Revert "Update old ref of RegisterQueryService"

This reverts commit 1ea1ea8559604d5c0aa13951b3016967438da2a5.

* Update keeper.md

* Update handler.md

* Update handler.md

* Update messages-and-queries.md

* Update docs/basics/app-anatomy.md

Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>

* Update docs/building-modules/intro.md

Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>

* Fix typo

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
2020-10-14 12:38:14 +00:00

3.0 KiB

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:

x/{module}
├── client
│   ├── cli
│   │   ├── query.go
│   │   └── tx.go
│   └── rest
│       ├── query.go
│       └── tx.go
├── exported
│   └── exported.go
├── keeper
│   ├── invariants.go
│   ├── genesis.go
│   ├── keeper.go
│   ├── ...
│   └── querier.go
│   └── grpc_query.go
├── types
│   ├── codec.go
│   ├── errors.go
│   ├── events.go
│   ├── expected_keepers.go
│   ├── genesis.go
│   ├── keys.go
│   ├── msgs.go
│   ├── params.go
│   ├── types.proto
│   ├── ...
│   └── querier.go
│   └── {module_name}.pb.go
│   └── query.pb.go
│   └── genesis.pb.go
├── simulation
│   ├── decoder.go
│   ├── genesis.go
│   ├── operations.go
│   ├── params.go
│   └── proposals.go
├── abci.go
├── handler.go
├── ...
└── module.go
  • abci.go: The module's BeginBlocker and EndBlocker implementations (if any).
  • client/: The module's CLI and REST client functionality implementation and testing.
  • exported/: The module's exported types -- typically type interfaces. If a module relies on other module keepers, it is expected to receive them as interface contracts through the expected_keepers.go (which are detailed below) design to avoid having a direct dependency on the implementing module. However, these contracts can define methods that operate on and/or return types that are specific to the contract's implementing module and this is where exported/ comes into play. Types defined here allow for expected_keepers.go in other modules to define contracts that use single canonical types. This pattern allows for code to remain DRY and also alleviates import cycle chaos.
  • handler.go: The module's message handlers.
  • keeper/: The module's keeper implementation along with any auxiliary implementations such as the querier and invariants.
  • types/: The module's type definitions such as messages, KVStore keys, parameter types, Protocol Buffer definitions, and expected_keepers.go contracts.
  • module.go: The module's implementation of the AppModule and AppModuleBasic interfaces.
  • simulation/: The module's simulation package defines all the required functions used on the blockchain simulator: randomized genesis state, parameters, weighted operations, proposal contents and types decoders.

Next {hide}

Learn about Errors {hide}