This is a simple expense manager API.
Initially, this API will serve as a simple expense tracker. With the following features:
- Add, edit, and delete expenses.
- Group and filter expenses based on period, cost center & expense tag/type.
- Provide a monthly expense report per user.
- Export expenses to CSV.
This project use npm 8.11.0 and node 16.15.1.
src/
β
βββ components/
β β
β βββ FooComponent/
β β βββ index.tsx
β β βββ styles.ts
β β
β βββ BarComponent/
β βββ index.tsx
β βββ styles.ts
β
β
βββ core/
β β
β βββ store/
β β
β βββ ducks/
β β βββ foo.ts
β β βββ bar.ts
β β
β βββ sagas/
β β βββ foo.tsx
β β βββ bar.tsx
β β βββ rootSaga.tsx
β β
β βββ hooks.ts
β βββ store.ts
β
β
βββ infra/
β β
β βββ adapter/
β β β
β β βββ fooAPI/
β β β βββ index.ts
β β β
β β βββ http.ts
β β
β βββ errors/
β βββ errorTypes.ts
β
β
βββ pages/
β β
β βββ Foo/
β β βββ components/
β β β βββ FooMeter
β β β βββ index.tsx
β β β βββ styles.tsx
β β βββ index.tsx
β β βββ styles.ts
β β
β βββ Bar/
β βββ index.tsx
β βββ styles.ts
β
β
βββ router/
β βββ index.tsx
β
βββ styles/
β βββ colors.ts
β βββ globalStyles.ts
β βββ themes.ts
β
βββ tests/
β βββ mockAPI.ts
β
βββ types/
β βββ reduxAction.ts
β
βββ index.tsx
Right above is a diagram showing how the project is designed. We have some main folders on the src root that encapsulate main concepts:
- components: Here is where we keep all reusable components, they need to be decoupled and preferred extensible. Each component folder have a JSX file separated from the styles file.
- core: This is the place where you want to keep all your business related objects/DTOs, domain methods/services (redux actions & sagas). It's preferred to keep all the complex logic here instead of inside pages or components.
- infra: Here we want to keep all the app configs & external dependency management like http clients, indexedDB libs, errors, external adapters...
- pages: All the pages accessed by the router can be found here, if a page have unique components that only exists inside them and are not shared to other pages you can keep inside a
componentsfolder here. - router: All accessible routes, access rules and how they are configured, can be found here.
- tests: Here you can maintain and configure all test related features.
- React CRA with typescript initial template
- Routing: react-router-dom
- App State: redux-toolkit (could be replaced by ContextAPI)
- Side Effects: redux-saga (could be replaced by ContextAPI)
- Style: styled-components + material-ui
- HTTP Client: axios
- Localization: i18next
- Testing: Jest
Disclaimer: As of now jul-06-2022, with the React version 17 and react-router-dom v6, there isn't a safe way to access history inside redux in order to navigate throughout the middle of an async saga/thunk like we used to do in older versions of this lib, so if you need to make this kind of actions I suggest replacing this state management with ContextAPI, because then you will be able to call getNavigate hook.
- Author - Stefano Soro