Git Product home page Git Product logo

falsy / react-with-clean-architecture Goto Github PK

View Code? Open in Web Editor NEW
660.0 13.0 114.0 4.2 MB

Clean architecture based react project sample code.

License: Do What The F*ck You Want To Public License

JavaScript 3.17% HTML 0.24% TypeScript 53.37% Starlark 0.81% Java 20.92% Ruby 2.17% Objective-C 3.20% CMake 0.36% C++ 9.78% Objective-C++ 5.99%
clean-architecture typescript react react-native sample-code

react-with-clean-architecture's Introduction

Sample code of React with Clean architecture

This project is a sample code of one small idea to introduce a clean architecture to web services in a large sense, and a clean architecture to a project using React in a small sense. With minimal library and service functions, we are concentrating on overall project composition.

if you leave an issue or a pull request, we will reflect the insufficient part or improvement. ☺️
(+ i am not good at English.)

Language

πŸ‡°πŸ‡· πŸ‡ΊπŸ‡²

Use Stack

Typescript, Webpack, React, React-Native, Recoil, Styled-Components

(Previous single repo configuration)
https://github.com/falsy/react-with-clean-architecture/tree/v1.9.0

Clean Architecture

Alt Clean architecture As with various architectures, the primary purpose of a clean architecture is to separate concerns. Divide the hierarchy according to each interest, design domain-centric rather than detailed implementation, and make sure that the internal area does not depend on external elements such as the framework or database UI.

  • Distinguish between detailed implementation areas and domain areas.
  • Architecture does not depend on the framework.
  • The outer zone can depend on the inner zone, but the inner zone cannot depend on the outer zone.
  • Both high-level and low-level modules rely on abstraction..

Monorepo

Alt Monorepo The monorepo package consists of the above. The domain area, adapter area, and framework area are each configured as a package and designed to be more clearly distinguished. New services can be configured by adding packages from the framework area.

Communitaction Flow

Alt Communitaction Flow in simple diagram, it is as above.

Session

After the user logs in, the issued authentication token is stored and used in the web storage. web storage is accessible globally, but the sample code follows the flow above and is controlled by 'Storage' in 'Infrastructures'. this is part of a detailed implementation that can change, and is positioned according to its role to improve maintenance.

Board

Board posts and comments are fetched through http communication from 'Infrastructures', encapsulated as Board Root Entity including Comment Entity in 'Use Case' and delivered to 'Presenter', and 'Presenter' returns Entity data.
in 'Components', 'Entity' data or 'View Model' encapsulated data is stored in the state management manager, and the view is redrawn according to the state change of the data.

Inversion of Control

Alt Communitaction Flow In the case of 'Repository', it is an adapter layer, so you should not know about 'Repository' in 'Use Case'. Therefore, in 'Use Case', it is implemented through the Repository Interface located in the domain layer, which is then operated through Dependency Injection.

Directory Structure

/packages
β”œβ”€ adapter
β”‚  └─ src
β”‚     β”œβ”€ infrastructures
β”‚     β”œβ”€ presenters
β”‚     └─ repositories
β”œβ”€ domain
β”‚  └─ src
β”‚     β”œβ”€ aggregates
β”‚     β”œβ”€ entities
β”‚     β”œβ”€ useCases
β”‚     β”‚  └─ repository-interfaces
β”‚     └─ dto
β”œβ”€ mobile(React Native)
β”‚  β”œβ”€ android
β”‚  β”œβ”€ ios
β”‚  └─ src
β”‚     β”œβ”€ components
β”‚     β”œβ”€ di
β”‚     β”œβ”€ hooks
β”‚     └─ vm
└─ web
   └─ src
      β”œβ”€ components
      β”œβ”€ di
      β”œβ”€ hooks
      └─ vm
  • The package structure of the monorepo is based on the layers of the clean architecture.
    [ adapter / domain(useCases/entities) / mobile(react-native) / web ]
  • The component's directory structure is freely structured in the form promised between services or members.

Screenshots

Alt Screenshot 1 Alt Screenshot 2

Settings

Package

Lerna

/lerna.json

{
  "packages": ["packages/*"],
  "npmClient": "yarn",
  "useWorkspaces": true,
  "version": "0.0.1"
}

Package

/package.json

{
  ...
  "workspaces": {
    "packages": [
      "packages/**"
    ],
    "nohoist": [
      "**/mobile",
      "**/mobile/**"
    ]
  }
  ...
}

Mobile(React Native)

Metro

/packages/mobile/metro.config.js

const path = require('path')

module.exports = {
  projectRoot: path.resolve(__dirname, "../../"),
  ...
}

iOS

xcode

open packages/mobile/ios/mobile.xcodeproj

AppDelegate.m

#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];

Modify as below.

#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"packages/mobile/index"];

Android

/packages/mobile/android/app/src/main/java/com/mobile/MainApplication.java

@Override
protected String getJSMainModuleName() {
  return "index";
}

Modify as below.

@Override
protected String getJSMainModuleName() {
  return "packages/mobile/index";
}

/packages/mobile/android/app/build.gradle

project.ext.react = [
  enableHermes: true, // clean and rebuild if changing
];

Modify as below.

project.ext.react = [
  enableHermes: true, // clean and rebuild if changing
  cliPath: "../../node_modules/react-native/local-cli/cli.js",
  entryFile: "packages/mobile/index.js",
];

Run Projects

1. install

Install

$ yarn install

2. Mock Server

Start

$ yarn run mock-server

3. Web

Start

$ yarn run web

4-1. Mobile(iOS)

Install

# $ cd /packages/mobile/ios
$ pod install
# $ cd ../../../

Start

$ yarn run ios

4-2. Mobile(Android)

Start

$ yarn run android

Version

v2.0.0 - ChangeLog

react-with-clean-architecture's People

Contributors

chanhyuk-im avatar dependabot[bot] avatar falsy avatar parkhojeong avatar zainnqureshii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-with-clean-architecture's Issues

IDE can't recognize module including webpack alias

webstorm version: 2022.02

in my IDE, it cannot find module including alias of webpack or babel.
how do you set up with this problem?

image

i tried below setting. it also doesn't work by preference setting

image

i think one solution is that put webpack.config file in root directory like below image
in web development, src/web/di/, in mobile development src/mobile/di

image

between mobile babel and web webpack, are you switch setting by target environment between mobile and web?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.