Skip to content

Commit 7b62cc1

Browse files
committed
Update README with Mermaid diagrams and enhance content structure
1 parent 04b56bd commit 7b62cc1

1 file changed

Lines changed: 126 additions & 11 deletions

File tree

README.md

Lines changed: 126 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
![Compose](https://img.shields.io/badge/Jetpack_Compose-Latest-green.svg?logo=jetpackcompose)
55
![Decompose](https://img.shields.io/badge/Decompose-2.1.0-purple.svg)
66

7-
A comprehensive tutorial project showcasing Decompose for reactive UI component architecture in Kotlin Android development.
7+
A comprehensive tutorial project showcasing **Decompose** for building reactive, component-based architectures in Kotlin Android development. This project demonstrates how to create modular, maintainable, and testable applications with proper separation of concerns.
88

99
## 🚀 Overview
1010

11-
Decompose is a powerful Kotlin library for building component-based UIs with clean separation of concerns. This tutorial demonstrates how to create modular, maintainable Android applications using Decompose with Jetpack Compose.
11+
Decompose provides powerful tools for creating independent UI components with their own lifecycle, state management, and navigation capabilities. This tutorial walks through implementing a Todo application with clean architecture principles and Decompose integration.
12+
13+
<!-- TODO: Add screenshot of the app here -->
14+
![App Screenshot](screenshots/app_screenshot.png)
1215

1316
## ✨ Key Features
1417

@@ -22,7 +25,37 @@ Decompose is a powerful Kotlin library for building component-based UIs with cle
2225

2326
This project follows Clean Architecture principles with a feature-based package structure combined with Decompose component architecture. This approach allows for better separation of concerns, high cohesion, and easier maintainability.
2427

25-
![Architecture Diagram](https://raw.githubusercontent.com/abd3lraouf/decompose-tutorial/master/assets/architecture.svg)
28+
### Component Architecture
29+
30+
```mermaid
31+
graph TD
32+
A[Application] --> B[Root Component]
33+
B --> C[TodoList Component]
34+
B --> D[TodoDetail Component]
35+
C --> E[Todo Items]
36+
D --> F[Todo Edit]
37+
38+
style A fill:#f9f,stroke:#333,stroke-width:2px
39+
style B fill:#bbf,stroke:#333,stroke-width:2px
40+
style C fill:#dfd,stroke:#333,stroke-width:2px
41+
style D fill:#dfd,stroke:#333,stroke-width:2px
42+
style E fill:#ffd,stroke:#333,stroke-width:1px
43+
style F fill:#ffd,stroke:#333,stroke-width:1px
44+
```
45+
46+
### Clean Architecture Layers
47+
48+
```mermaid
49+
graph TB
50+
A[UI Layer<br>Compose/Components] --> B[Domain Layer<br>Use Cases]
51+
B --> C[Data Layer<br>Repositories]
52+
C --> D[Data Sources<br>Local/Remote]
53+
54+
style A fill:#bbf,stroke:#333,stroke-width:2px
55+
style B fill:#dfd,stroke:#333,stroke-width:2px
56+
style C fill:#ffd,stroke:#333,stroke-width:2px
57+
style D fill:#fcc,stroke:#333,stroke-width:2px
58+
```
2659

2760
### Package Structure
2861

@@ -76,18 +109,39 @@ app/src/main/java/dev/abd3lraouf/learn/decompose/
76109
- Implements Decompose components for UI logic
77110
- Follows the MVU (Model-View-Update) pattern with Decompose
78111

79-
### Navigation with Decompose
80-
81-
The app uses Decompose's navigation capabilities:
82-
83-
1. **Root Navigation**: Managed by `RootComponent` that handles the highest level navigation
84-
2. **Tab Navigation**: Managed by `TabNavigationComponent` for switching between features
85-
3. **Stack Navigation**: Each feature (like TodoList) has its own stack navigation for its screens
112+
## 🧭 Navigation with Decompose
113+
114+
Decompose handles navigation through a component hierarchy:
115+
116+
```mermaid
117+
graph TD
118+
A[Root Navigation<br>RootComponent] --> B[Tab Navigation<br>TabComponent]
119+
B --> C[Todo Stack<br>TodoStackComponent]
120+
B --> D[Statistics Stack<br>StatisticsComponent]
121+
C --> E[Todo List]
122+
C --> F[Todo Details]
123+
C --> G[Todo Creation]
124+
125+
style A fill:#bbf,stroke:#333,stroke-width:2px
126+
style B fill:#dfd,stroke:#333,stroke-width:2px
127+
style C fill:#ffd,stroke:#333,stroke-width:2px
128+
style D fill:#ffd,stroke:#333,stroke-width:2px
129+
```
86130

87131
## 📋 Todo App Implementation
88132

89133
This tutorial implements a Todo application with a three-stage workflow:
90134

135+
```mermaid
136+
stateDiagram-v2
137+
[*] --> Todo
138+
Todo --> InProgress: Click Play Button
139+
InProgress --> Done: Check Checkbox
140+
Done --> Todo: Uncheck Checkbox
141+
```
142+
143+
### Stage Implementation
144+
91145
1. **Todo Stage**:
92146
- Display: Play button (no checkbox)
93147
- Action: Clicking play button moves todo to "In Progress" stage
@@ -100,18 +154,79 @@ This tutorial implements a Todo application with a three-stage workflow:
100154
- Display: Checkbox (checked)
101155
- Action: Unchecking the box moves todo back to "Todo" stage
102156

157+
<!-- TODO: Add screenshots for each stage -->
158+
![Todo Stages](screenshots/todo_stages.png)
159+
160+
## 💻 Component Implementation
161+
162+
A simple Decompose component looks like:
163+
164+
```kotlin
165+
interface TodoListComponent {
166+
val models: Value<Model>
167+
168+
fun onTodoClicked(id: String)
169+
fun onAddTodoClicked()
170+
171+
data class Model(
172+
val todos: List<TodoItem>,
173+
val isLoading: Boolean
174+
)
175+
}
176+
177+
class DefaultTodoListComponent(
178+
private val todoRepository: TodoRepository,
179+
private val componentContext: ComponentContext,
180+
private val onTodoSelected: (String) -> Unit,
181+
private val onAddTodo: () -> Unit
182+
) : TodoListComponent, ComponentContext by componentContext {
183+
// Implementation
184+
}
185+
```
186+
103187
## 🛠️ Setup Instructions
104188

105189
1. Clone the repository
190+
```bash
191+
git clone https://github.com/abd3lraouf/decompose-tutorial.git
192+
```
193+
106194
2. Open the project in Android Studio
107-
3. Build and run the app
195+
196+
3. Build and run the app on a device or emulator
108197

109198
## 📚 Technologies
110199

111200
- **Kotlin**: Modern programming language
112201
- **Jetpack Compose**: UI toolkit
113202
- **Decompose**: Component architecture
114203
- **Kotlin Coroutines**: Asynchronous programming
204+
- **Koin**: Dependency injection
205+
206+
## 🧪 Testing
207+
208+
Decompose's component-based architecture makes testing more straightforward:
209+
210+
```kotlin
211+
@Test
212+
fun `when todo is clicked, it navigates to details screen`() {
213+
// Create test component
214+
val component = DefaultTodoListComponent(
215+
mockRepository,
216+
TestComponentContext(),
217+
onTodoSelected = { selectedId ->
218+
// Verify correct ID is passed
219+
assertEquals("todo-1", selectedId)
220+
},
221+
onAddTodo = {}
222+
)
223+
224+
// Trigger action
225+
component.onTodoClicked("todo-1")
226+
}
227+
```
228+
229+
<!-- TODO: Add more test examples -->
115230

116231
## 👨‍💻 About the Author
117232

0 commit comments

Comments
 (0)