Giter Club home page Giter Club logo

archref-react's Introduction

React Reference Architecture

Check Code CodeQL

Preview

preview image

BFF - Proxy Configurate

Often serve the front-end React app from the same host and port as their backend implementation.

Exemple:

/             - static server returns index.html with React app
/todos        - static server returns index.html with React app
/api/todos    - server handles any /api/* requests using the backend implementation

For that, it is only necessary to configure the file: src/setupProxy.js

example:

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  // ...
};

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://localhost:5000',
      changeOrigin: true,
    })
  );
};

Storybook

npm run storybook yarn storybook

Storybook is a development environment for React UI components. It allows you to browse a component library, view the different states of each component, and interactively develop and test components.

Storybook

Develop

npm start yarn start [https://localhost:3000]

Build

npm run build yarn build

Build Storybook

npm run build-storybook yarn build-storybook

Unit Tests

npm test yarn test

This is your source code tree:

src
|-- assets
|-- components
|-- config // all aplications configs, external services and interceptores
|-- hooks
|-- mocks
|-- models
|-- pages
|-- routes
|-- services // all query and functions request 
|-- utils
|-- Bootstrap.tsx
|-- App.tsx
|-- index.tsx
|-- react-app-env.d.ts
|-- reportWebVitals.ts
|-- service-worker.ts
|-- serviceWorkerRegistration.ts
|-- setupProxy.js
|-- setupTests.ts
...

This is your component structure:

...
components
|-- YourComponent
    |-- index.tsx
    |-- styles.ts
    |-- YourComponent.spec.ts
    |-- YourComponent.stories.ts
...

or

...
components
|-- YourComponent
    |-- index.tsx
    |-- styles.ts
    |-- interfaces.ts
    |-- YourComponent.ts
    |-- YourComponent.spec.ts
    |-- YourComponent.stories.ts
...

or

...
components
|-- YourContainerComponents
    |-- Component1
    |-- Component2
    |-- Component3
    |-- index.ts
...


This is your page structure:

...
Pages
|-- YourPage
    |-- index.tsx
    |-- styles.ts
    |-- interface.ts 
    |-- YourPage.spec.ts
    |-- YourPage.stories.ts
...

./assets

Here will be all your project assets as images, icons...

./components

Components are presentational only elements, grouping UI items

./configs

Here will be all configurations for external and internal services

./hooks

Services are responsible to handle the connection with all external elements, like APIs and global functions

./mocks

All mock data for your unit testes, examples and any mocks

./models

global interfaces and models that your project needs

./pages

Pages are mapped in routes and have all the containers needed to implement a functionality

./routes

Routes contains the react-router-dom implementation to map the project's routes to the respective pages

./services

Here will be all query and request funcions

./styles

Here will be all global and css(relatives)

./utils

Directory to keep all utils functions to share all over the project

Enviroments

Your project can consume variables declared in your environment as if they were declared locally in your JS files. By default you will have NODE_ENV defined for you, and any other environment variables starting with REACT_APP_.

WARNING: Do not store any secrets (such as private API keys) in your React app! Environment variables are embedded into the build, meaning anyone can view them by inspecting your app's files. Create .env.test.local and .env.local before run project

Adding Development Environment Variables In

To define permanent environment variables, create a file called .env in the root of your project:

``REACT_APP_NOT_SECRET_CODE=abcdef```

What other files can be used

  • .env: Default.
  • .env.local: Local overrides. This file is loaded for all environments except test.
  • .env.development, , : Environment-specific settings..env.test.env.production
  • .env.development.local, , : Local overrides of environment-specific settings..env.test.local.env.production.local

Files on the left have more priority than files on the right:

  • npm start: , , , .env.development.local .env.local .env.development .env
  • npm run build: , , , .env.production.local .env.local .env.production .env
  • npm test: , , (note is missing) .env.test.local .env.test.env .env.local

Example

REACT_APP_VERSION=$npm_package_version
# also works:
# REACT_APP_VERSION=${npm_package_version}

DOMAIN=www.example.com
REACT_APP_FOO=$DOMAIN/foo
REACT_APP_BAR=$DOMAIN/bar

More utils commands

Analyzer your build bundle npm run analyze yarn analyze

Find and fix Javascrit and TypeScript problems according to pre-defined rules npm run analyze yarn analyze

Find and fix code formatted npm run prettier yarn prettier

Advantages of using this react project template

The project is already configured with:

  • React
  • Typescript
  • Jest
  • Babel-root-import
  • unit testing example
  • Eslint
  • Prettier
  • Styled
  • Styled Theming
  • Husky
  • Storybook
  • PWA
  • Integration back-end proxy (http-proxy)

Getting Started with Create React App

This project was bootstrapped with Create React App.

Available Scripts

In the project directory, you can run:

yarn start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

yarn test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

yarn build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

yarn eject

Note: this is a one-way operation. Once you eject, you can’t go back!

If you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

You can learn more web develop tools web.dev

Main dependecies

Main dev dependecies

archref-react's People

Contributors

dependabot-preview[bot] avatar snyk-bot avatar victorcmarinho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.