Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize modules stucture #4438

Closed
4 tasks
fedekunze opened this issue May 29, 2019 · 7 comments
Closed
4 tasks

Standardize modules stucture #4438

fedekunze opened this issue May 29, 2019 · 7 comments
Labels
good first issue help wanted Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity.

Comments

@fedekunze
Copy link
Collaborator

fedekunze commented May 29, 2019

Summary

Standardize folders and location of files across SDK modules.

Problem Definition

This allows for other features to be created from this standard (eg #4191, Swagger file autogenerated from module, etc).

Some modules don't follow the structure as described by @alexanderbez

x/
├── alias.go
├── app.go
├── module.go
├── client/
│   ├── cli/
│   └── rest/
|       └─ swagger.yaml                  // defines the internal types and endpoints
├── exported/                            // exported internal interfaces
├── genesis.go
├── handler.go
├── keeper/
│   ├── keeper.go
│   ├── keys.go
|   └── querier.go  
├── invariants/
└── types/
     ├── tags.go
     ├── msgs.go
     ├── keys.go
     └── expected_keepers.go

Proposal

Ensure modules follow and comply the proposed standard tree. Maybe add check with CI


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@fedekunze fedekunze added help wanted good first issue Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. labels May 29, 2019
@fedekunze fedekunze changed the title Standarize modules stucture Standardize modules stucture May 29, 2019
@alexanderbez
Copy link
Contributor

Looks good to me! Although I think we should rename app.go to abci.go 👍

@shanev
Copy link

shanev commented Jun 2, 2019

This looks reasonable to me, but a couple questions:

  • app.go could get confused for the top-level app.go. Maybe abci_app.go?
  • What exactly is the purpose of /exported?
  • Would /keeper and /querier have a file for each stored type?

i.e: for a module named "claim":

x/claim
├── keeper/
    └── claim.go
├── querier/
    └── claim.go
└── types/
    └── claim.go
  • What is in expected_keepers.go?

Also, with this layout, a simple dapp could be implemented as a single module. When is it preferable to go with multiple modules over a single one? I'm guessing if a module provides general functionality and could be re-used, then it should be it's own thing.

@alexanderbez
Copy link
Contributor

@shanev

1.) I agree, hence I recommended abci.go as you're fulfilling ABCI methods for that module.
2.) /exported contains exported types (mainly interfaces) that other module's /expected_types imports -- it's to keep code DRY and prevent varying modules having to redefine a common interface (e.g. Validator).
3.) This isn't a bad idea, but I would not say it's necessary.
4. expected_keepers is a way for a module to define the contract (interface) it's keeper and other components needs without having to the import a module directly (e.g. using the validator interface defined in staking without having to import staking). This goes hand-in-hand with exported

Also, with this layout, a simple dapp could be implemented as a single module. When is it preferable to go with multiple modules over a single one? I'm guessing if a module provides general functionality and could be re-used, then it should be it's own thing.

This depends on the context of the app/module. Ideally, all modules should as extensible and modular as possible. Even if an app could be implemented using a single module -- it should be a module.

@alexanderbez
Copy link
Contributor

Updated. Querier will exist in keeper/ and it's types constructors will exist in `types/

@alessio
Copy link
Contributor

alessio commented Jun 9, 2019

We should use Golang's special internal package to hide module's internal structure and all those types and functions that are not meant to be exported rather than instead of an exported package.

@alexanderbez
Copy link
Contributor

app.go => abci.go
handler.go and genesis.go should not live in internal.

@fedekunze
Copy link
Collaborator Author

Closing via #4618.

Please refer to the updated module spec for the most updated version of the standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue help wanted Type: Code Hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity.
Projects
None yet
Development

No branches or pull requests

4 participants