This project is a cryptocurrency listing application built with SwiftUI and following MVVM architecture combined with Clean Architecture principles. The project includes fetching data from an API, local persistence, and unit testing.
- List of Cryptocurrencies: Displays a list of cryptocurrencies fetched from a remote API (CoinMarketCap).
- Favorite Management: Users can mark cryptocurrencies as favorites, stored locally using SwiftData.
- Detail View: Detailed information for each cryptocurrency, including description, price, and website links.
- Error Handling: Proper error handling for network and decoding issues.
- Unit Tests: Simple unit tests for Use Cases, Repositories, and ViewModels.
The project is organized into layers following Clean Architecture:
Cryptocurrencies/
│
├── Features/ # Feature Modules
│ ├── Data/ # Data Layer (API and Decodables)
│ │ ├── CryptoList/
│ │ │ ├── Decodables/ # API Response Models
│ │ │ │ ├── CryptoDecodable
│ │ │ │ ├── QuoteDecodable
│ │ │ │ └── CryptoDetailsDecodable
│ │ │ ├── CryptoListRepository
│ │ │ └── CryptoListRepositoryError
│ │
│ ├── Domain/ # Domain Layer (Business Logic)
│ │ ├── CryptoList/
│ │ │ ├── CryptoListUseCase
│ │ │ └── CryptoEntity
│ │
│ ├── Presentation/ # Presentation Layer (Views, ViewModels and Models)
│ │ ├── Detail/
│ │ │ └── DetailView
│ │ ├── Home/
│ │ │ ├── Components/
│ │ │ ├── HomeView
│ │ │ ├── HomeViewModel
│ │ │ └── CryptoModel
│
├── Base/ # Base Layer (Reusable Core Logic)
│ ├── Network/ # Network Services
│ │ ├── NetworkSession
│ │ ├── APIRequest
│ │ ├── APIConfig
│ │ └── NetworkClient
│ │
│ ├── SwiftData/ # Persistence
│ │ ├── PersistenceManager
│ │ ├── GlobalModelContainer
│ │ └── CryptoDataStore
│
├── App/
│ └── CryptocurrenciesApp # Entry Point
This project follows Clean Architecture, dividing responsibilities into layers:
-
Data Layer:
- Handles API requests and data persistence.
- Example:
CryptoListRepository
fetches cryptocurrency data from the API.
-
Domain Layer:
- Contains business logic encapsulated into Use Cases.
- Example:
CryptoListUseCase
manages fetching and transforming data.
-
Presentation Layer:
- Contains SwiftUI Views and ViewModels.
- Views are dumb components; ViewModels manage state and interact with Use Cases.
HomeViewModel
callsCryptoListUseCase
to fetch cryptocurrency data.CryptoListUseCase
requests data fromCryptoListRepository
.- The data is passed back to the
HomeViewModel
and displayed inHomeView
.
This project includes unit tests for Use Cases, Repositories, and ViewModels using Swift Testing.
- Success and Failure Mocks: Simulates successful and failed API responses.
- Error Handling Tests: Ensures proper handling of network and decoding errors.
- Favorite Management Tests: Verifies that adding and removing favorites works correctly.
HOME VIEW | FAV ACTION | DETAIL VIEW | HOME VIEW (with FAVs) |