This is a simple React project to demostrate how libraries like Mobx and Inversify works with the purpose of creating a scalable and maintainable architecture.
Intall the dependencies:
npm installCreate a .env file in the root of the project with the following content:
VITE_API_URL=https://your-api-url.com
VITE_API_USER=your-api-user
VITE_API_PASSWORD=your-api-passwordnpm run devOpen http://localhost:3000 to view it in the browser.
npm run previewnpm run buildnpm run version:patch
npm run version:minor
npm run version:majornpm run test
nmp run test:watchgraph TD
App[Src] ---> Components
App ---> Core
App ---> Features
Core ---> Di
Core ---> Hooks
Core ---> Services
App ---> Styles
Features ---> featurecomponents[Components]
Features ---> featurehooks[Hooks]
Features ---> featureservices[Services]
Core ---> Features
Styles ----> Features
Styles ----> Components
The project is divided into the following folders:
Components: Contains the shared components of the application.Core: Contains the core of the application, like the dependency injection container, hooks, services, etc.Features: Contains the features of the application, each feature has its own components, hooks, and services.Styles: Contains the global styles of the application.
Ideally Core must be independent of the Features and Components folders, so it can be eventually extracted to a separate package.
The dependency injection container is created using InversifyJS, it is initialized in the di folder and exported as a singleton.
The hooks are created in the hooks folder, they are used to abstract the logic from the components.
The services are created in the services folder, they are used to abstract the logic from the components and hooks.
Each feature has its own components, hooks, and services, they are created in the features folder.
Each feature represents a smart component that is responsible for the business logic of the feature.
The shared components are created in the components folder, they are used by the features, must be isolated and reusable.
The global styles are created in the styles folder, they are used by the features and components.