Introduction
The Cosmos SDK is a modular framework for building application-specific blockchains. It follows a layered architecture that separates concerns and enables developers to build complex applications through composition of modules.Architectural Layers
The Cosmos SDK architecture consists of several key layers:Application Layer (BaseApp)
At the core is BaseApp, which implements the ABCI (Application Blockchain Interface) and serves as the foundation for all Cosmos SDK applications.BaseApp is responsible for managing the application state machine, routing messages, and coordinating ABCI method calls from CometBFT.
Module Layer
Modules are self-contained units of functionality that encapsulate state, message handlers, and business logic. Each module:- Defines its own state schema using Collections
- Implements message and query handlers
- Registers routes with BaseApp’s routers
- Can depend on other modules through keeper interfaces
State Layer
The state layer provides:- CommitMultiStore: Root store containing all module substores
- KVStore: Key-value store interface for state access
- Collections: Type-safe state management abstractions
- IAVL: Merkle tree for state commitments and proofs
Consensus Integration
Cosmos SDK integrates with CometBFT (formerly Tendermint) consensus engine through ABCI:Design Principles
Modularity
The SDK uses a modular architecture where each module is independent and composable:- Modules interact through well-defined keeper interfaces
- Dependencies are managed through dependency injection (depinject)
- Modules can be added, removed, or upgraded independently
State Machine Replication
The SDK implements a deterministic state machine:- Transactions modify state through message handlers
- State changes are committed atomically per block
- All nodes execute the same transactions in the same order
- State root hashes prove consistency across the network
Object Capability Model
Security through capabilities:- Modules receive only the capabilities they need
- Store keys are capabilities for accessing state
- Keepers are capabilities for accessing module functionality
- No global state access - everything is explicit
Execution Modes
The SDK supports multiple execution contexts:| Mode | Purpose | State Changes |
|---|---|---|
CheckTx | Validate transactions before mempool | No (discarded) |
PrepareProposal | Proposer prepares block | No |
ProcessProposal | Validators verify block | No |
FinalizeBlock | Execute and commit transactions | Yes |
Simulate | Estimate gas and test execution | No |
Component Interaction
Key Architecture Files
Explore the implementation:baseapp/baseapp.go:86- BaseApp struct definitionbaseapp/abci.go- ABCI method implementationstypes/context.go:41- Context struct for request handlingstore/types/store.go- Store interfacescore/appmodule/module.go- Module interfaces
Next Steps
BaseApp
Dive into BaseApp architecture
Modules
Learn about the module system
Transactions
Understand transaction flow
Related Documentation
- State Management - State storage and collections
- Consensus Integration - ABCI and CometBFT
- Module Development - Building custom modules