When beginners open a clean architecture project, they feel scared.
Too many packages.
Too many folders.
Nothing makes sense.
You start thinking:
- How does this work?
- Where do I start?
- Why is this so complicated?
If you have felt this before, you are not alone.
Clean architecture looks complex at first. But the reason is simple. You are looking at the full structure before building anything.
Let’s break it down in a simple way.
Watch step-by-step video down below:
The Real Confusion
When you open a clean architecture project, you usually see folders like:
-
data
-
domain
-
presentation
-
di
-
core
-
common
-
model
-
mapper
It feels like you must understand everything at once.
That is the first mistake.
You are not supposed to build the whole structure on the first day.
Clean architecture is not about creating many files.
It is about separating responsibilities.
The folders are there to give direction. They are not there to scare you.
How to Start Clean Architecture
Here is the simple truth.
You do not start with files.
You start with empty packages.
Create only four packages:
-
Data
-
Domain
-
Presentation
-
DI
That’s it.
Do not create 20 classes.
Do not create repository implementations.
Do not create use cases immediately.
Just create the structure.
Think of it like drawing boundaries before building a house.
Start small.
What Are the Clean Architecture Layers
Now let’s understand what each layer does.
Domain
Domain is the business logic.
It contains pure Kotlin code.
No Android framework.
No UI code.
For example:
-
Listing products
-
Adding a product
-
Validating data
Domain explains what the app does.
Data
Data is where information comes from.
For example:
-
Database
-
Remote API
-
Firebase
-
Local storage
Data layer talks to outside systems.
It gives data to the domain layer.
Presentation
Presentation is the UI.
It contains:
-
Compose screens
-
ViewModels
-
UI state
For example:
-
Login screen
-
Product list screen
-
Settings screen
This layer shows data to the user.
DI
DI means Dependency Injection.
It is not a real layer.
It is just wiring.
It connects data, domain, and presentation together.
Data sends information to domain.
Domain sends information to presentation.
Each layer has one job.
Nothing more.
Common Beginner Mistake
Here is what beginners usually do.
They create everything at once:
-
Repository
-
Repository implementation
-
Use case
-
Mapper
-
DTO
-
Entity
-
UI state
Events
But there is no feature yet.
This creates confusion.
Instead, build feature by feature.
One feature.
One use case.
One repository.
One screen.
Architecture should grow with your app.
Not before your app.
Why Are There Models in Both Data and Domain
This is another common confusion.
People ask:
Why do we have models in data and models in domain?
Is that duplication?
No.
They have different purposes.
Data Model
Represents API or database structure.
For example:
It may contain:
-
id_with_underscore
-
stock
-
brand
-
extra fields from API
This model matches the server response.
Domain Model
Represents business meaning.
It only contains what your app needs.
Maybe:
-
id
-
name
-
price
No extra fields.
Even if both models have the same name, they are not the same.
They serve different purposes.
If the API changes, only the data model changes.
Your business logic stays safe.
This separation gives flexibility.
What To Do When Starting a New Project
If you are starting clean architecture today, follow this simple plan:
Step 1
Create empty packages.
Step 2
Build your first feature normally.
Step 3
Only create files when needed.
Step 4
Move logic to domain if it becomes business logic.
That’s it.
You do not need to overthink.
Final Thoughts
Clean architecture is not complex.
It is organized thinking.
It feels heavy at first because you see the full structure.
But once you build one feature at a time, it becomes natural.
Start small.
Build real features.
Let the structure grow slowly.
And you will see that clean architecture is simple.
No comments:
Post a Comment
Share your thoughts ...