-
Notifications
You must be signed in to change notification settings - Fork 1
Code structure
Guillem Puche edited this page Aug 31, 2022
·
3 revisions
The Skia Wallet's code is organized as a monorepo and layer architecture.
We use the methodology monorepo (used in Google, Facebook...). It helps Skia Wallet to decouple the multiple parts of the code and to scale the project easily.
Learn more about monorepos on this video of Google and Nx.dev.
These are the benefits of the monorepo (taken from Nex.dev and ACM):
- Shared code and visibility. Keeps your code across your entire organization. Reuse validation code, UI components, and types across the codebase. Reuse code between the backend, the frontend, and utility libraries.
- Atomic changes. Change a server API and modify the downstream applications that consume that API in the same commit. You can change a button component in a shared library and the applications that use that component in the same commit. A monorepo saves the pain of trying to coordinate commits across multiple repositories.
- Developer mobility. Get a consistent way of building and testing applications written using different tools and technologies. Developers can confidently contribute to other teams’ applications and verify that their changes are safe.
- Single set of dependencies. Use a single version of all third-party dependencies, reducing inconsistencies between applications. Less actively developed applications are still kept up-to-date with the latest version of a framework, library, or build tool.
- Unified versioning, one source of truth
You can read about Nx folder structure here
Hint: We don't use the folder
apps
, all the code is in the folderpackages
.
The code of the wallet is a layer architecture (specifically Domain-Driven Design architecture & Clean architecture).
All layers are decoupled. How? Each one is in one or more packages in the folder packages
of the current Github project:
- Common: general resources that are used on all projects.
-
Entities: defines how the data of the others layers will use. It contains entities (each entity is unique because it has at least one unique property) and value objects (it isn't unique). Part of the code in the entities is inspired by Khalil Stemmler.
- Example of an entity: a User's Wallet, the unique properties are the mnemonic phrase, the private key or the public address.
- Example of a value object: an address with only one property (the
value
as a type string), it can be private, public address, etc.
- Repositories: connects to external services (APIs, storage, smart contracts, blockchain providers...). It gets the data from a smart contract and transforms it to fit the layer entities, then the data it will be ready to be used on the layer ui.
- UI: presents to the user interface (UI) like components and the whole website. It depends on the rest of the layers. Skia Wallet has two UI packages: ui-components and ui-wallet