All Projects → eduardomoroni → React Clean Architecture

eduardomoroni / React Clean Architecture

Licence: mit
A realistic approach to implement clean architecture on react codebases

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Clean Architecture

Shiftscheduler
A boilerplate ASP.NET Core project, including a sample employee shift scheduler app
Stars: ✭ 5 (-99.3%)
Mutual labels:  clean-architecture, boilerplate
Node Api Boilerplate
DDD/Clean Architecture inspired boilerplate for Node web APIs
Stars: ✭ 2,797 (+292.29%)
Mutual labels:  clean-architecture, boilerplate
Clean Architecture Components Boilerplate
A fork of our clean architecture boilerplate, this time using the Android Architecture Components
Stars: ✭ 1,241 (+74.05%)
Mutual labels:  clean-architecture, boilerplate
Boilerplate
Clean Architecture Solution Template for ASP.NET Core 5.0. Built with Onion/Hexagonal Architecture and incorporates the most essential Packages your projects will ever need. Includes both WebApi and Web(MVC) Projects.
Stars: ✭ 243 (-65.92%)
Mutual labels:  clean-architecture, boilerplate
Android Base
Android Clean Architecture MVP RESTful client template app
Stars: ✭ 87 (-87.8%)
Mutual labels:  clean-architecture, boilerplate
Android Clean Architecture Boilerplate
An android boilerplate project using clean architecture
Stars: ✭ 3,534 (+395.65%)
Mutual labels:  clean-architecture, boilerplate
React Isomorphic Boilerplate
🌟 An universal React isomorphic boilerplate for building server-side render web app.
Stars: ✭ 653 (-8.42%)
Mutual labels:  boilerplate
Boilerform
Boilerform is a little HTML and CSS boilerplate to take the pain away from working with forms.
Stars: ✭ 679 (-4.77%)
Mutual labels:  boilerplate
Vortigern
A universal boilerplate for building web applications w/ TypeScript, React, Redux, Server Side Rendering and more.
Stars: ✭ 647 (-9.26%)
Mutual labels:  boilerplate
React Redux Universal Hot Example
A starter boilerplate for a universal webapp using react, redux, express and feathers
Stars: ✭ 639 (-10.38%)
Mutual labels:  boilerplate
Akka Http Microservice
Example of http (micro)service in Scala & akka-http
Stars: ✭ 701 (-1.68%)
Mutual labels:  boilerplate
Rebar
Multi-tenant SaaS boilerplate + examples for universal web application with React, Material-UI, Relay, GraphQL, JWT, Node.js, C* DB - Cassandra/Elassandra/Scylla.
Stars: ✭ 690 (-3.23%)
Mutual labels:  boilerplate
Python Project Blueprint
Blueprint/Boilerplate For Python Projects
Stars: ✭ 670 (-6.03%)
Mutual labels:  boilerplate
Base
A starting point for Meteor apps.
Stars: ✭ 654 (-8.27%)
Mutual labels:  boilerplate
Aws Boilerplate
Opinionated full stack web app's boilerplate, ready to be deployed to AWS platform.
Stars: ✭ 682 (-4.35%)
Mutual labels:  boilerplate
Offlinesampleapp
Sample Offline-First MVVM app that uses Android Priority Job Queue, Room, Retrofit2, LiveData, LifecycleObserver, RxJava2, Dagger Android
Stars: ✭ 653 (-8.42%)
Mutual labels:  clean-architecture
React Native Web Monorepo
Code sharing between iOS, Android & Web using monorepo
Stars: ✭ 697 (-2.24%)
Mutual labels:  boilerplate
Practical.cleanarchitecture
Asp.Net Core 5 Clean Architecture (Microservices, Modular Monolith, Monolith) samples (+Blazor, Angular 11, React 17, Vue 2.6), Domain-Driven Design, CQRS, Event Sourcing, SOLID, Asp.Net Core Identity Custom Storage, Identity Server 4 Admin UI, Entity Framework Core, Selenium E2E Testing, SignalR Notification, Hangfire Tasks Scheduling, Health Checks, Security Headers, ...
Stars: ✭ 639 (-10.38%)
Mutual labels:  clean-architecture
React Starterify
A minimal React JS application starter kit
Stars: ✭ 669 (-6.17%)
Mutual labels:  boilerplate
Bozon
🛠 Command line tool for building, testing and publishing modern Electron applications
Stars: ✭ 687 (-3.65%)
Mutual labels:  boilerplate

React Clean Architecture

Applying clean architecture to a react codebase brings lots of benefits, most of them you can find by simply googling what's clean architecture and what should we adopt architectural patterns. One advantage that strikes me is having business rules isolated from framework-specific things. This means that our core logic is not coupled to React, React Native, Express, etc...
This gives you enough flexibility to, for example, move specific parts of the application to a backend, change libraries without too much pain, test once and reuse as many times as you want, share code between React and React Native applications, among others.
This is a realistic approach, what I mean by that is: It's simple enough to be applicable and Robust enough to have it in a production environment. Although I have greatly simplified it, for educational purposes, I believe that this example is of great value to get you started with applying architectural patterns and adapting them to your own needs.

Detailed explanation

I've been pretty busy lately, so I'll write as much as possible.
I'll write three blog posts explaining better what is Clean Architecture, why adopt it and how. Portuguese version of How to implement clean architecture for React codebases can be found HERE

Philosophy

high-level-diagram

The nomenclature may vary, but the concept behind this architectural pattern is: the domain dictates how tools should be organized and not the other way around. What I mean by that is that we should organize our codebase around the business rules and not around the frameworks we use to achieve business rules. The diagram above shows how the dependency rule works, the inner circles must not know about the outer circles. That is, there cannot be an import of a use case within an entity, or import of a framework within a use case. Another important rule is: entities and use cases should not rely on external libraries. The explanation is simple, the core of our application must be robust enough and malleable enough to meet the demands of the business without needing any external intervention. If by chance, an essential part of the application core MUST BE an external dependency. Dependency needs to be modeled following dependency inversion principle.

Communication flow

communication-flow-diagram

A brief explanation of each responsibility

  • Entity: Application independent business rules
  • Interactor: Application-specific business rules
  • Adapter: Glue code from/to Interactors and Presenter, most of the time implementing a framework-specific behaviour. e. g.: We have to connect Interactor with react container, to do so, we have to connect Interactor with redux (framework) and then connect redux to container components.
  • Presenter: Maps data from/to Adapter to/from Components.
  • Components: Simplest possible unit of presentation. Any mapping, conversion, MUST be done by the Presenter.

Sample apps DEMO

Talk is cheap, don't you think? That's why I'm sharing two sample apps to facilitate your digestion.
A great advantage of following clean architecture is having all business logic self-contained and closer, in a readable way.
Take a look at core/entities/ and core/useCases/ folders and see for yourself.

Counter

The counter app is a simple example of how to apply clean architecture to react world, it uses only synchronous actions and has no external dependencies.
It contains 2 use case rules:

  • The count must not be negative.
  • The count must not be greater than 10.

counter-gif


Authentication

An authentication app is a simple example, but not that simple, of how to apply clean architecture to a realistic scenario. It contains some shared business rules:

  • Users must have a valid email.
  • Users password must comprises only numbers and/or letters.
  • Users name must have a full name, and it must to be lowercased.
  • The App cannot sign up two users with the same email address.
  • The App must use an external dependency to persist user register.

authentication-gif


Folder Structure

This repository contains 2 examples of how to implement react following clean architecture, represented by the diagram above, and both follow the same folder structure:

./counter
├── core
│   └── lib
│       ├── adapters
│       │   └── redux
│       ├── entities
│       ├── frameworks
│       └── useCases
├── native
│   └── src
│       ├── components
│       └── stylesheets
└── web
    └── src
        ├── assets
        ├── components
        └── stylesheets

Note: the frameworks folder comprises framework-specific setups to have it available to the adapters.

Running the apps

run npm install under the project you'd like to run, and then run npm start.

Running on Windows

There's an issue related to how yarn/npm symlink file dependencies on windows. Due to this issue, you should first go under the core module and run npm install and npm run build. This will make the core module ready to be installed on the other modules.

References

Thanks

Feedback

If something looks odd, don't hesitate to reach me out or opening an issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].