Appearance
Architecture
CDR
Framework is a set of tools and libraries that allow you to create a component driven application using Redux
and React
. CDR
Follows some Design Principles that are listed below:
Design Principles
Single Source of Truth
: The state of your whole application is stored in an object tree within a singleRedux
store.State is Read-Only
: The only way to change the state is to emit anaction
, an object describing what happened.Dependecy Injection
: The only way to get data fromserver
orbackend
orfirebase
is to inject it into thestore
usingmiddleware
.Pure Functions
: To specify how the state tree is transformed by actions, you write purereducers
.Single Responsibility
: Each component should have a single responsibility and should be independent of other components.Separation of Concerns
: Separate thestate
from theview
andactions
fromreducers
.Component Driven
: Each component should be independent of other components and should be able to be used in other projects.Reusable
: Each component should be reusable and should be able to be used in other projects.Testable
: Each component should be testable and should be able to be tested in other projects.Scalable
: Each component should be scalable and should be able to be scaled in other projects.Maintainable
: Each component should be maintainable and should be able to be maintained in other projects.Extensible
: Each component should be extensible and should be able to be extended in other projects.
Layers
Data
Data (Store)
Data (Reducer)
Data (Action)
API (Backend, Server, Firebase)
Service
Service (Middleware)
Service (Action)
Controller (React)
View (React)
Components
Data (Store)
: Thestore
is the redux store that holds the state of the application.Data (Reducer)
: Thereducer
is a pure function that takes the previous state and an action, and returns the next state. in simple terms it mutates the state.Data (Action)
: Theaction
is the only way to mutate the state. it is a plain object that describes what happened. this triggers thereducer
to mutate the state.Service (Middleware)
: Themiddleware
is a function that is able to intercept anaction
and do something with it before it reaches thereducer
. it is used to inject data fromserver
orbackend
orfirebase
into thestore
.API (Backend, Firebase)
: Theapi
is theserver
orbackend
orfirebase
that is used to get data from. This layer is optional and is used to inject data into thestore
usingmiddleware
.Service (Action)
: Theaction
is the only way to trigger the middleware. it is a plain object that describes what happened. this triggers themiddleware
to commiuicate with theapi
.Controller (React)
: Thecontroller
is a react component that is used to connect thestore
to theview
. it is used to pass thestate
andactions
to theview
.View (React)
: Theview
is a react component that is used to render thestate
and trigger theactions
. it is used to render thestate
and trigger theactions
.
Summary
First of all the user visits the page when the app is mounted the App
creates the Data (Store)
with the Data Structure. The only way to mutate the store
is Data (Reducer)
and to trigger reducer and make use of it we need to dispatch an Data (Action)
. The Data (Action)
is triggered by the Service (Middleware)
and the Service (Middleware)
is triggered by the Service (Action)
. The Service (Action)
is triggered by the Controller (React)
and the Controller (React)
is triggered by the View (React)
. The View (React)
is rendered by the Controller (React)
and the Controller (React)
is rendered by the App
. The Controller
is solely responsible to get the data handle events while the View
is only responsible to render the data.
Why it is important?
When Building Large Scalable Application working with react requires you to follow some design principles and patterns. But Following the Design Principle and creating managle component can be hard and time consuming. Even though it is possible to create managable components but making good folder structure and managing the state can be hard. It is proven that Redux
can handle state managemenet effeciently. So We Injected Redux
into React
and created a framework that follows the design principles and patterns and makes it easy to create managable components.