Skip to content

Commit

Permalink
Rename to clean-architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Jan 23, 2024
1 parent a0f2c64 commit bfa6cec
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 13 deletions.
86 changes: 85 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,85 @@
# This package has been renamed [clean-architecture](https://www.npmjs.com/package/clean-architecture)
<p align="center">
<img src="https://user-images.githubusercontent.com/6702424/151054088-b21c1cd6-912a-4dcf-b54d-af74e8632620.png">
</p>
<p align="center">
<i>📐 TypeScript Clean Architecture Framework 📐</i>
<br>
<br>
<a href="https://github.com/garronej/clean-architecture/actions">
<img src="https://github.com/garronej/clean-architecture/workflows/ci/badge.svg?branch=main">
</a>
<a href="https://bundlephobia.com/package/clean-architecture">
<img src="https://img.shields.io/bundlephobia/minzip/clean-architecture">
</a>
<a href="https://github.com/garronej/clean-architecture/blob/main/LICENSE">
<img src="https://img.shields.io/npm/l/clean-architecture">
</a>
</p>

This is a Framework for building web application. It helps you decouple your UI component
and the core logic of your App.
It can be used both on the frontend and the backend and integrate well with any UI framework
but it's primary use case is for building SPAs (Vite Projects) with React.

- [Benefits](#benefits)
- [Install / Import](#install--import)
- [Examples setups](#examples-setups)
- [Example project](#example-project)
- [Canonical setup](#canonical-setup)
- [Enterprise grade app](#enterprise-grade-app)
- [Starting the demo app](#starting-the-demo-app)

# Benefits

- Clean architecture without [the object-orientedness](https://www.youtube.com/watch?v=QM1iUe6IofM).
- No need to explicitly call `dispatch()` on the UI side.
As a matter of fact, Redux being used
under the hood is an implementation detail that can as well be ignored by the dev working on the UI.
- Strict isolation between the Core and the UI. Port your web app to React Native or switch to another
UI framework without having to re-write a single line of the core logic.
- It's not specifically a React framework, it's not even specifically a frontend framework, it can and is be used on the backend.
- Names things once, it propagate through all the codebase via [TypeScript's template literal types](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html). No more hard to maintain stuttering.
Name things once then let intellisense guide you.
- The core can tell the UI to do thing imperatively. Like "Play a sound now" which is something that
is impossible to do cleanly with just states. (`isSoundShouldBePlayedNow: boolean` ?)

# Install / Import

```bash
$ yarn add clean-architecture evt
```

# Examples setups

## Example project

<img width="438" alt="image" src="https://github.com/garronej/snake-clean-architecture/assets/6702424/2cd5e5ee-0d5c-443b-95a7-b3c288da1233">

This is a very basic snake game implemented with Vite/TypeScript/React/Clean-Architecture.

[👉 `garronej/snake-clean-architecture`👈 ](https://github.com/garronej/snake-clean-architecture)

## Canonical setup

A canonical setup can be found here: [👉 `src/test/demo-app`👈 ](https://github.com/garronej/clean-architecture/tree/main/src/test/demo-app).

## Enterprise grade app

You can consult the source code of [onyxia-web](https://github.com/InseeFrLab/onyxia-web) to see how `clean-architecture` is used in a real world application.

<p align="center">
<a href="https://github.com/InseeFrLab/onyxia">
<i>Onyxia: A data science-oriented container launcher.</i>
<img src="https://user-images.githubusercontent.com/6702424/231329083-180fe7a2-22a8-470f-910a-ef66300b6f35.png">
</a>
</p>

# Starting the demo app

```bash
git clone https://github.com/garronej/clean-architecture
cd clean-architecture
yarn
yarn build
yarn start-demo-app
```
4 changes: 2 additions & 2 deletions demo-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ E.g. `import { ... } from "core";`.
that internally make uses of a library like [`axios`](https://axios-http.com) to make the HTTP requests to your REST API.
- The `src/core/usecases` directory should contains the method and states that will be needed to give the App an user interface.
- The `middlewareEvtAction` is optional. It provides an [`Evt`](https://evt.land) that posts every time an action is dispatched.
It allows, for example, [to wait for an other operation to complete before starting a new one](https://github.com/garronej/redux-clean-architecture/blob/1702d15b6ea395f2816734fe73a20fa4551ec679/src/test/demo-app/src/core/usecases/usecase1.ts#L51-L60).
It allows, for example, [to wait for an other operation to complete before starting a new one](https://github.com/garronej/clean-architecture/blob/1702d15b6ea395f2816734fe73a20fa4551ec679/src/test/demo-app/src/core/usecases/usecase1.ts#L51-L60).
Find a documented usecase [here](https://docs.onyxia.dev/architecture#how-to-deal-with-project-switching).
> WARNING: It doesn't play well with `createAsyncThunk()`. If it's a problem for you,
> please submit an issue.
Happy hacking!
Do not hesitate to [start a discussion](https://github.com/garronej/redux-clean-architecture/discussions)!.
Do not hesitate to [start a discussion](https://github.com/garronej/clean-architecture/discussions)!.
2 changes: 1 addition & 1 deletion demo-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"evt": "^2.5.3",
"react": "18.2.0",
"react-dom": "^18.2.0",
"redux-clean-architecture": "file:../dist",
"clean-architecture": "file:../dist",
"tsafe": "^1.6.5"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion demo-app/src/core/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Port2Config } from "./adapters/createProt2";
import type { Port1Config } from "./adapters/createPort1";
import type { Port1 } from "./ports/Port1";
import type { Port2 } from "./ports/Port2";
import { createCore, type GenericCore } from "redux-clean-architecture";
import { createCore, type GenericCore } from "clean-architecture";
import { usecases } from "./usecases";

type ParamsOfBootstrapCore = {
Expand Down
2 changes: 1 addition & 1 deletion demo-app/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
NOTE: Only here do we export the API for a specific framework (here react).
In the rest of the core directory everything is agnostic to React
*/
import { createReactApi } from "redux-clean-architecture/react";
import { createReactApi } from "clean-architecture/react";
import { bootstrapCore } from "./bootstrap";

export const { createCoreProvider, useCore, useCoreState } = createReactApi({ bootstrapCore });
2 changes: 1 addition & 1 deletion demo-app/src/core/usecases/usecase1.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Thunks } from "../bootstrap";
import type { State as RootState } from "../bootstrap";
import { id } from "tsafe/id";
import { createUsecaseActions, createSelector } from "redux-clean-architecture";
import { createUsecaseActions, createSelector } from "clean-architecture";

export type State = {
counter: number;
Expand Down
2 changes: 1 addition & 1 deletion demo-app/src/core/usecases/usecase2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Thunks, CreateEvt } from "../bootstrap";
import type { State as RootState } from "../bootstrap";
import { id } from "tsafe/id";
import { createUsecaseContextApi, createUsecaseActions, createSelector } from "redux-clean-architecture";
import { createUsecaseContextApi, createUsecaseActions, createSelector } from "clean-architecture";

export type State = {
counter2: number;
Expand Down
2 changes: 1 addition & 1 deletion demo-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7451,7 +7451,7 @@ recursive-readdir@^2.2.2:
dependencies:
minimatch "^3.0.5"

"redux-clean-architecture@file:../dist":
"clean-architecture@file:../dist":
version "3.7.4"
dependencies:
"@reduxjs/toolkit" "^1.9.6"
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "redux-clean-architecture",
"name": "clean-architecture",
"version": "4.3.2",
"description": "Utilities for implementing clean architecture using Redux",
"repository": {
"type": "git",
"url": "git://github.com/garronej/redux-clean-architecture.git"
"url": "git://github.com/garronej/clean-architecture.git"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -43,7 +43,7 @@
"typescript",
"react"
],
"homepage": "https://github.com/garronej/redux-clean-architecture",
"homepage": "https://github.com/garronej/clean-architecture",
"peerDependencies": {
"evt": "^2.5.3"
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/link-in-test-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ execYarnLink({ "cwd": pathJoin(projectRootDirPath, "dist") });
testAppNames.forEach(testAppName =>
execYarnLink({
"cwd": getTestAppPath(testAppName),
"targetModuleName": "redux-clean-architecture"
"targetModuleName": "clean-architecture"
})
);

0 comments on commit bfa6cec

Please sign in to comment.