devfractal is a library for creating web applications using react and
node. It has the following goals.
-
to help you write good software by default; software that's simple, correct, generic and fast.
-
to be kind to developers of all skill levels.
-
best practices must be simpler to follow than to break. Best practices will be based on the current wisdom of the react community.
-
Do not reinvent the wheel unless necessary. Most of the utilities are thin wrappers over popular modern libraries.
-
state: Use this when you have complex state management.
- You will avoid a lot of pitfalls with
reactlike stale closures. - state management is separated from the component, allowing components to be simpler.
- event handlers are safer, simpler and faster(avoid rerenders).
- based on useReducer.
- uses immer.
- You will avoid a lot of pitfalls with
-
useEvent: no need to worry about useCallback or dependency array.
-
tree: same as state, except you could share state within a tree. Avoids all pitfalls of using
Context. -
hooks for collections:
useArray,useSet,useMapfor rare occasions where performance is everything.- Internally maintains a mutable collection. It behaves similar to an immutable collection and works well with the react model.
-
useUpdatewhen you need state but doesn't have any logic. -
hooks for simpler scenarios:
useInt,useBooleanetc
-
Simple atom/computed/action abstraction remaining closer to the true reactive model. For advanced scenarios can use
derived. -
slice: similar to state above, only global.
-
Avoids lots of issues with atom-based libraries like
jotai. -
hooks-based API: You could easily construct an excellent hook-based API, where state could be
- shared in a tree of components
- used for a complex reusable component
- global
path and endpoints as zod specifications would allow making router, server-side API and client-side API access functions safer(static as well as runtime typesafe) and simpler. These abstractions will help you in the following libraries.
-
Uses
@tanstack/react-query, so comes with all of its advantages. -
No need to worry about spinners/loaders or error handling in every component. Just worry about the happy path.
-
Safe http operations, currently using
redaxiosandzod. -
Safe query operations.
-
Optimistic updates: Supports mutations by returning descriptions.
-
queryState: similar to but for queries/mutations.
-
Good defaults for queryClient and QueryProvider.
-
Integrates
react-router's loader and query so that you get all of the benefits of loader as well asreact-query. -
queries and mutations based on endpoint abstraction.
-
rest API abstraction using path, and endpoint abstraction. Allows declarative API access
-
pageabstraction. Allows safe and declarative configuration of pages. -
public and protected routes.
-
safe access to params and search.
-
routerStateis similar toslice/state. -
queries and mutations using endpoint abstraction.
simplified and generic validation helpers using zod where strict validation is
usually not suitable.
-
Integrate state, validation and above UI components.
-
Support common patterns for forms.
-
client-side table with client-side pagination etc.
-
server-side table with server-side pagination etc.
-
Support most common operations like filtering, ordering, selection, and actions etc.
-
Allow both paging and infinite scrolling.
-
Fast rendering, even with thousands of rows.
-
Fast data manipulation, even with hundreds of thousands of rows.
-
Support lazy evaluation of higher-order functions.
-
Support most common functions including database-like operations.
-
Support for internalization of dates through adobe date library*.
-
Common abstractions to use specifications using
zod. Small helpers which will allow you to write robust software based on principles from Eiffel. -
Makes your pure functions safer by allowing you to satisfy the specification accurately.
-
Helpers for creating actions.
-
forms and form validations helpers.
-
Abstractions for responses and json transformers.
-
Almost all abstractions are designed with error handling in mind and strive to be safe using
zodspecifications. -
Wrap up almost every external system to allow for zod specification validations. All of your code will be typesafe.
-
Support
Resultabstraction from the functional world for complex error handling scenarios. -
Integrate exception handling with result using Scala like abstraction Try.
Lots of examples are available and are planned for all of the above abstractions.
-
Use
endpointabstraction to implement server-side calls using express. -
query/path and body validation.
-
Automatic Error handling similar to Java/C# frameworks.
-
Typsafe client code which always remains in sync with the server API. Similar to
trpc.
-
Use headless components for accessible components: radix-ui.
-
Integrate with
tailwindfor themeable and extensible components. -
Use shadcn/ui for most
uicomponents.
Integration of form and ui library.
Integration of table and ui libraries.
-
Support authentication and authorization.
-
Support abstractions for both server-side as well as client-side.
-
RBAC: role-based authorization and control.
-
All of the above libraries and best practices will be made available through starter projects, including vite, express, remix, and next.
-
Have a single configuration file to configure all libraries. Think theme but for code.