nccasia / mezon-fe

0 stars 0 forks source link

MezonFe

This workspace has been generated by Nx, a Smart, fast and extensible build system.

Installing Nx Globally

npm install --global nx@latest

Notes

Prerequisites

Setup

Install the dependencies

Prepare the environment variables

Start the chat app

To start the development server run yarn dev:chat. Open your browser and navigate to http://localhost:4200/. Happy coding!

Linting

Format

Architecture Overview

Architecture Overview

Workspace Structure

Workspace Structure

We are using monorepo architecture to manage the codebase. The workspace is divided into multiple applications and libraries. Each application is a standalone application and each library is a reusable codebase.

Workspace will be managed by Nx which is a smart, fast and extensible build system.

Applications

All applications are located in the apps directory. Each application is a standalone React application and has its own codebase.

Currently, we only focus on the chat application.

Libraries

All libraries are located in the libs directory. Each library is a reusable codebase and can be used by multiple applications.

Dependencies

Codebase is divided into multiple dependencies which are managed by Nx. There are 2 types of modules:

the libraries are shared by multiple applications and could be reused by multiple applications.

There are several types of libraries:

The dependencies are depend on each other based on the following rules (<- = depend on):

Bad dependencies:

Dependency Graph

The dependency graph is managed by Nx and could be visualized by running the following command:

 npx nx graph

the output will be the dependency graph of the workspace.

Dependency Graph

how to read the dependency graph:

for example, we have bad dependencies between components and apps which are not allowed.

alt text

Data Flow

We are using one-way data flow architecture to manage the data flow of the application. The data flow is unidirectional follow the Redux pattern.

Data Flow

See more about the Redux pattern here.

The core concepts are one-way data flow and single source of truth.

Application data

Data Flow

The application data flow is managed by some packages:

Data concept

Data Flow for voice

Layouting

how to layout the components and pages

Layouting

We have sevaral layout components to handle layout based on the route:

Access Control

Access control is managed by the policies slice. each user has it own permissions to access the resources. The permission is managed by the policies slice.

There are several ways to manage the access control:

Toast Notification

Toast notification is managed by the toasts slice. each toast has it own message and type. The toast is managed by the toasts slice.

Actions

Toast are displayed in the <ToastContainer /> component.

There are several ways to manage the toast notification:

    // add toast notification to any action
    return thunkAPI.fulfillWithValue(
        value,
        withToast({
            message: 'Clan changed',
            type: 'success',
        })
    );

    // dispatch the addToast action directly
    thunkAPI.dispatch(
        addToast({
            message: 'Clan changed',
            type: 'success',
        });
    );

Error Handling

Error handling is managed by the errors slice. each error has it own message and code. The error is managed by the errors slice.

By default, the error is displayed as toast notification. in case you want to disable the toast notification, you could set the toast meta to false.

// No toast notification
return thunkAPI.rejectWithValue(
    error,
    withError({
        toast: false
    })
);

// toast with custom message
return thunkAPI.rejectWithValue(error, withError('Custom error message'));

// fully custom error
return thunkAPI.rejectWithValue(
    error,
    withError({
        toast: {
            message: 'Custom error message',
            type: 'error',
            theme: 'dark'
        }
    })
);

Building the application

For the desktop application, we are using electron to build the application. The application's dependencies are managed by the apps/desktop/package.json file. When building the application, the dependencies are installed in the apps/desktop/node_modules directory.

Performance Optimization

Performance Factors

The application performance is mostly affected by these factors:

Performance Tools

We use several tools to measure the performance of the application:

Conventions and Guidelines

Code Formatting

Using Prettier and ESLint to format the codebase. The codebase should be formatted before committing the code.

Naming Convention

See more about the naming convention here

🔔 Coding Rules

⚠ Notice

Troubleshooting

Debug desktop app

See: https://github.com/electron/electron/issues/3331