Skip to content

Commit 5361070

Browse files
committed
fix: update links
1 parent 8244c18 commit 5361070

9 files changed

Lines changed: 154 additions & 158 deletions

File tree

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Best Practices
32

43
This document outlines the key principles, patterns, and practices for the Offchain department. It serves as a guide to ensure consistency, scalability, and maintainability in our projects, covering design patterns, architectural principles, TypeScript best practices, testing, scripting, and documentation standards.
@@ -8,21 +7,21 @@ By adhering to these guidelines, we ensure robust and modular development, foste
87
## Patterns
98

109
- Design Patterns:
11-
- **Factory**: Creates objects dynamically based on input or configuration without exposing the instantiation logic.
12-
- **Proxy**: Acts as a placeholder to control access, add caching, or optimize performance.
13-
- **Singleton**: Ensures a class has only one instance and provides a global point of access to it.
10+
- **Factory**: Creates objects dynamically based on input or configuration without exposing the instantiation logic.
11+
- **Proxy**: Acts as a placeholder to control access, add caching, or optimize performance.
12+
- **Singleton**: Ensures a class has only one instance and provides a global point of access to it.
1413

1514
## **Principles**
1615

1716
- Over-abstraction leads to tighter coupling in the code; avoid it.
1817
- Favor **composition over inheritance** to build reusable and flexible components.
1918
- Use **dependency injection** to decouple components and facilitate testing.
2019
- Follow **SOLID principles**:
21-
1. **Single Responsibility Principle**: A class should have one and only one reason to change.
22-
2. **Open/Closed Principle**: Software entities should be open for extension but closed for modification.
23-
3. **Liskov Substitution Principle**: Derived classes must be substitutable for their base classes.
24-
4. **Interface Segregation Principle**: Many specific interfaces are better than a single, general-purpose interface.
25-
5. **Dependency Inversion Principle**: Depend on abstractions, not concretions.
20+
1. **Single Responsibility Principle**: A class should have one and only one reason to change.
21+
2. **Open/Closed Principle**: Software entities should be open for extension but closed for modification.
22+
3. **Liskov Substitution Principle**: Derived classes must be substitutable for their base classes.
23+
4. **Interface Segregation Principle**: Many specific interfaces are better than a single, general-purpose interface.
24+
5. **Dependency Inversion Principle**: Depend on abstractions, not concretions.
2625

2726
### **Architectural Patterns**
2827

@@ -35,8 +34,8 @@ By adhering to these guidelines, we ensure robust and modular development, foste
3534
### **1. Module Structure**
3635

3736
- Follow the [Internal Module Pattern](https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de) to avoid circular dependencies:
38-
- Create an `external.ts` file to explicitly list exported components, types, and interfaces.
39-
- Import and re-export them in the entry `index.ts` file for easier access.
37+
- Create an `external.ts` file to explicitly list exported components, types, and interfaces.
38+
- Import and re-export them in the entry `index.ts` file for easier access.
4039

4140
### **2. Asynchronous Initialization**
4241

@@ -45,15 +44,15 @@ By adhering to these guidelines, we ensure robust and modular development, foste
4544
### **3. Runtime Type Checking**
4645

4746
- Validate environment variables at runtime using libraries like:
48-
- [Zod](https://zod.dev/)
49-
- [t3-env](https://github.com/t3-oss/t3-env)
50-
- [envalid](https://github.com/af/envalid).
47+
- [Zod](https://zod.dev/)
48+
- [t3-env](https://github.com/t3-oss/t3-env)
49+
- [envalid](https://github.com/af/envalid).
5150

5251
### **4. Type Safety**
5352

5453
- Avoid the use of `any`; prefer `unknown` and use type narrowing to ensure safety.
5554
- Leverage Branded types pattern for adding clarity, safety and correctness to our code:
56-
https://egghead.io/blog/using-branded-types-in-typescript
55+
https://egghead.io/blog/using-branded-types-in-typescript
5756

5857
## Naming conventions
5958

@@ -62,9 +61,9 @@ By adhering to these guidelines, we ensure robust and modular development, foste
6261
A `Service` typically encapsulates a broader business logic or workflow. It might orchestrate various components or interact with multiple data sources or APIs to fulfill a specific domain-related task.
6362
A `Provider` usually focuses on supplying a specific type of data or resource. It’s often more narrowly scoped, providing access to a particular piece of data, a configuration, or a service needed by other parts of the application.
6463

65-
Ex:
64+
Ex:
6665

67-
- Classes that interacts with a metadata source like `Github` ,`JsonFile` &`Ipfs` should implement the interface `IMetadataProvider` and should be called `GithubProvider,JsonFileProvider` &`IpfsProvider`.
66+
- Classes that interacts with a metadata source like `Github` ,`JsonFile` &`Ipfs` should implement the interface `IMetadataProvider` and should be called `GithubProvider,JsonFileProvider` &`IpfsProvider`.
6867
- A class that aggregates multiple sources like `Metadata` ,`Pricing` &`BlockchainEvents` , should be called, for example, `AgreggatorService` the word aggregator might change, based on the bussiness logic. Could be, for example, `MetricsService` .
6968

7069
If we look at it from composability a `Service` can be made up of `Providers` and the service works on applying the business and orchestration logic
@@ -73,40 +72,40 @@ If we look at it from composability a `Service` can be made up of `Providers` an
7372

7473
- Enable the `useUnknownInCatchVariables` flag in your `tsconfig.json`
7574
- Enable the `noUncheckedIndexedAccess` flag for safe object access
76-
- Avoid throwing literals like, enforce it with an ESLint rule (https://typescript-eslint.io/rules/no-throw-literal/
75+
- Avoid throwing literals like, enforce it with an ESLint rule https://eslint.org/docs/latest/rules/no-throw-literal
7776
- Write custom error classes
78-
- Use declarative and descriptive names
79-
- Avoid the usage of suffixes like `Exception` or `Error` :
80-
- Ex: Don’t write `EmptyArrayException`, write `EmptyArray`
77+
- Use declarative and descriptive names
78+
- Avoid the usage of suffixes like `Exception` or `Error` :
79+
- Ex: Don’t write `EmptyArrayException`, write `EmptyArray`
8180

8281
## **Testing**
8382

8483
- Avoid usage of `should` each time you are writing an `it` statement.
85-
- Ex: Don’t write `it('should run successfully'`), write `it('runs successfully')`.
84+
- Ex: Don’t write `it('should run successfully'`), write `it('runs successfully')`.
8685

8786
### **Key points:**
8887

8988
1. **Purpose of Tests**:
90-
1. Use tests to clearly state the expected behavior for core business scenarios. Well-written tests can often be more clarifying than code comments.
89+
1. Use tests to clearly state the expected behavior for core business scenarios. Well-written tests can often be more clarifying than code comments.
9190
2. **Mindset**:
92-
1. Approach testing with the mindset of, "I've considered how this situation impacts the business and I expect the code to behave as indicated by the test." This confirms that the implemented code functions as intended.
91+
1. Approach testing with the mindset of, "I've considered how this situation impacts the business and I expect the code to behave as indicated by the test." This confirms that the implemented code functions as intended.
9392
3. **Efficiency**:
94-
1. Avoid blind testing, which is time-consuming. Instead, focus on testing the most critical business scenarios.
95-
2. For example, if the business cares about a scenario where an action as a consequence of one of many sub-actions (Promise all for example) , write a test that expects failure when any operation fails. This approach efficiently communicates the expected behavior.
93+
1. Avoid blind testing, which is time-consuming. Instead, focus on testing the most critical business scenarios.
94+
2. For example, if the business cares about a scenario where an action as a consequence of one of many sub-actions (Promise all for example) , write a test that expects failure when any operation fails. This approach efficiently communicates the expected behavior.
9695
4. **Clarity:**
97-
1. Aim for a test suite that clearly indicates the intended behavior of the code. Reading the test results should provide a clear understanding of what the code is supposed to do.
96+
1. Aim for a test suite that clearly indicates the intended behavior of the code. Reading the test results should provide a clear understanding of what the code is supposed to do.
9897

9998
## **Scripting**
10099

101100
### **Monorepo Projects**
102101

103102
- Use `process.cwd()` to reference the root directory within scripts.
104103
- Organize scripts in the `package.json` file using the format:
105-
- Infrastructure scripts: `script:infra:{name}`
106-
- Utility scripts: `script:util:{name}`
104+
- Infrastructure scripts: `script:infra:{name}`
105+
- Utility scripts: `script:util:{name}`
107106
- Create a `scripts` folder with the following structure:
108-
- `infra/` for infrastructure scripts.
109-
- `utilities/` for utility scripts.
107+
- `infra/` for infrastructure scripts.
108+
- `utilities/` for utility scripts.
110109

111110
### **Package Management**
112111

@@ -119,4 +118,4 @@ If we look at it from composability a `Service` can be made up of `Providers` an
119118

120119
## **Discord**
121120

122-
- We use Discord for communication—whenever you have a PR ready for review make sure to drop it in the pr-reviews channel!
121+
- We use Discord for communication—whenever you have a PR ready for review make sure to drop it in the pr-reviews channel!

sites/wonderland/docs/development/offchain/onboarding/challenge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Create the challenge repo using the [Wonder's Repo Creator](https://github.com/d
3838
- Utilize monorepo template
3939
- Pricing Module:
4040
- Fetch prices from Coingecko and DeFiLlama
41-
- Implement [factory pattern](https://refactoring.guru/design-patterns/singleton) for provider selection
41+
- Implement [factory pattern](https://refactoring.guru/design-patterns/factory-method) for provider selection
4242
- Add caching with 60-second TTL
4343
- Logger:
4444
- Implement using [singleton pattern](https://refactoring.guru/design-patterns/singleton)

0 commit comments

Comments
 (0)