Getting Started with Archer
Welcome to Archer - a lightweight framework for Functional Clean Architecture (FCA) built on top of Arrow.
What is Archer?
Archer is designed to reduce the boilerplate typically associated with Clean Architecture while maintaining its core benefits:
- Abstraction - Clear separation of concerns
- Reusability - Composable components
- Scalability - Easy to extend and maintain
The Problem with Traditional Clean Architecture
Clean Architecture offers great benefits, but it comes with significant tradeoffs:
- Excessive Boilerplate - Multiple interfaces and implementations for each layer
- Maintainability Issues - More code to maintain and update
A typical Clean Architecture implementation requires:
- UseCase interface + implementation
- Repository interface + implementation
- Multiple DataSource interfaces + implementations (network, local, etc.)
- Multiple Mappers for data transformation
Archer's Solution
Archer provides contractual DataSources and Repositories that eliminate the need for creating all this boilerplate, while still maintaining the architectural benefits. You only need to implement the mapping logic - Archer handles the rest.
Installation
Add Archer to your project:
dependencies {
implementation("com.m2f-kt:archer-core:{version}")
}
Replace {version} with the latest version from Maven Central.
Quick Example
Here's a simple example of using Archer:
// Define a remote data source
val remoteDataSource = getDataSource<Int, String> { param: Int ->
"$param"
}
// Define a local storage data source
val store: StoreDataSource<Int, String> = InMemoryDataSource()
// Create a repository strategy with caching
val repositoryStrategy = remoteDataSource cacheWith store expiresIn 5.minutes
// Use the repository with different result wrappers
val resultIce = ice {
repository.get(StoreSync, 0)
}
// resultIce: Ice.Content("0")
val resultEither = either {
repository.get(StoreSync, 0)
}
// resultEither: Either.Right("0")
val resultNullable = nullable {
repository.get(StoreSync, 0)
}
// resultNullable: "0"
Result Types
Archer supports multiple result types through Arrow:
- Ice (Idle | Content | Error) - Three-state result type
- Either - Classic functional error handling
- Nullable - Simple null-based error handling
Next Steps
- Core Concepts - Understand Clean Architecture with Archer
- DataSources - Learn about data sources
- Repositories - Explore repository patterns
- Examples - See practical examples