Best Practices

How to Structure a react-admin App That Can Grow

Reactreact-adminArchitecture
A practical guide to files and folders, from the first resource to the fiftieth

Every react-admin project starts the same way. You scaffold the app, wire up a data provider, add a <Resource> for users and another for posts, and within an afternoon you have a working back office. The framework does so much for you that folder structure feels like a question for later.

Later arrives quickly. Admin panels grow in an unusual way: they rarely get deeper, but they get much wider. A customer-facing product might have a dozen screens that are polished for years. An admin app picks up a new entity every sprint, each with a list, a create form, an edit form, filters, bulk actions, and a handful of custom fields. Two years in, you have sixty resources, four teams committing to the same repository, and a components folder that nobody can navigate.

This article describes the problems that appear as a react-admin codebase grows, the principles that prevent them, and four concrete structures you can adopt in sequence. You do not need the most advanced one on day one. You do need to know where you are heading, so each step is a small move and never a rewrite.

The examples use react-admin v5 with TypeScript and Vite, but the ideas apply to v4 and to any bundler.

Why folder structure becomes a problem

A folder structure is the answer to two questions every developer asks many times a day: "where is the code for this?" and "where do I put this new thing?" When the answers are obvious, nobody thinks about structure. When they are not, the cost shows up in several places at once.

Finding code gets slow

The default instinct is to group files by technical type: components/, hooks/, utils/, pages/. This works with five resources. With forty, components/ holds two hundred files and the code for a single screen is spread over four directories. To change the order edit form you open pages/OrderEdit.tsx, components/OrderItemsInput.tsx, hooks/useOrderTotals.ts, and utils/orderHelpers.ts. Nothing in the file tree tells you those four files belong together.

Changes have an unknown blast radius

When everything is allowed to import everything, you cannot tell what a change will break. A developer adjusts StatusField for the invoices screen and the shipments list changes too, because someone reused it there a year ago. Shared code that was never designed to be shared is the most common source of regressions in large admin apps.

Teams collide

In a type-based structure, every feature touches the same few directories. Merge conflicts cluster in App.tsx, the data provider, the translation file, and the menu. Code ownership is impossible to express, because no directory maps to a team.

Inconsistency compounds

Without a convention, each developer solves the same problem in their own way. One resource exports its views from an index.ts, another registers them directly in App.tsx. One keeps filters inside the list file, another in a filters/ folder at the root. Each variation is harmless alone. Together they mean a new team member has to learn every resource separately, and code review turns into a debate about placement.

Tests have no natural home

This is the factor most often ignored at the start. If tests live in a separate __tests__ tree that mirrors src, the mirror drifts. If there is no shared test setup, every test file rebuilds its own react-admin context with slightly different mocks. When writing a test requires more setup than writing the feature, people stop writing tests. Structure decides whether testing is cheap or expensive.

The bundle grows with the app

An admin with sixty resources that are all imported eagerly in App.tsx ships every screen to every user on first load. Code splitting is easy when each resource is a self-contained unit and painful when resources are tangled across shared folders.

The provider files become monoliths

This one is specific to react-admin. The data provider, the auth provider, and the i18n messages are central by design. If you leave them as single files, the data provider turns into a thousand-line switch on resource names, and the English translation file turns into the most conflicted file in the repository.

What react-admin gives you to work with

The good news is that react-admin already has a strong opinion about how your domain is divided. It is called the resource.

A resource has a name, up to four standard views (list, create, edit, show), an icon, and a representation. The <Resource> component accepts all of these as props. This means a resource can be described by a single object, and that object is a natural public interface for a folder.

Around the resources sit a small number of global concerns:

  • The data provider, which translates react-admin's queries into API calls.
  • The auth provider, which handles login, identity, and access control.
  • The i18n provider, which supplies translated messages.
  • The layout, which includes the menu, the app bar, and the theme.
  • Custom routes, for pages that are not CRUD views, such as a dashboard or a settings screen.

A good react-admin structure follows these seams. Resources become folders. Global concerns each get one clear location. Everything else is either shared on purpose or private to a resource.

Five principles before any folders

The structures below are applications of a few rules. If you remember the rules, you can adapt the folders to your own project.

1. Colocate by domain, not by type. Code that changes together should live together. Everything about products belongs in one folder: views, inputs, hooks, translations, tests.

2. Give every module a public interface. A resource folder exposes one index.ts. Other parts of the app import from that file and nowhere deeper. What is not exported is private, and private code can be refactored freely.

3. Dependencies point in one direction. The app shell depends on resources. Resources depend on shared code. Shared code depends on nothing in the app. Resources do not import from each other's internals.

4. Share deliberately. Code moves to a shared folder when a second consumer actually needs it, and at that point it gets a general name, a stable API, and tests. Duplication between two resources is cheaper than a premature abstraction.

5. Keep tests next to the code. A test file sits beside the file it tests. Test infrastructure, such as render helpers and fixtures, lives in one shared place.

Level 1: The starter structure

Fits: prototypes, internal tools, one or two developers, up to about five resources.

1src/
2├── App.tsx
3├── main.tsx
4├── dataProvider.ts
5├── authProvider.ts
6├── i18nProvider.ts
7├── Layout.tsx
8├── posts.tsx
9├── users.tsx
10└── Dashboard.tsx

One file per resource, holding its list, edit, and create components. This is close to what create-react-admin generates, and for a small app it is the right choice. There is nothing to navigate, so there is nothing to organize.

src/App.tsx
1import { Admin, Resource } from 'react-admin';
2import { dataProvider } from './dataProvider';
3import { authProvider } from './authProvider';
4import { PostList, PostEdit, PostCreate } from './posts';
5import { UserList } from './users';
6
7export const App = () => (
8  <Admin dataProvider={dataProvider} authProvider={authProvider}>
9    <Resource name="posts" list={PostList} edit={PostEdit} create={PostCreate} />
10    <Resource name="users" list={UserList} />
11  </Admin>
12);

When to move on: a resource file passes roughly three hundred lines, you add a custom input that only one resource uses, or a second developer joins. Any of these means the single file is now hiding structure that should be visible.

Level 2: One folder per resource

Fits: most production apps, small teams, five to twenty resources.

This is the structure used by react-admin's own e-commerce demo, and it is the single most valuable step you can take.

1src/
2├── App.tsx
3├── main.tsx
4├── providers/
5│   ├── dataProvider.ts
6│   ├── authProvider.ts
7│   └── i18nProvider.ts
8├── layout/
9│   ├── Layout.tsx
10│   ├── Menu.tsx
11│   ├── AppBar.tsx
12│   └── theme.ts
13├── resources/
14│   ├── products/
15│   │   ├── index.ts
16│   │   ├── ProductList.tsx
17│   │   ├── ProductEdit.tsx
18│   │   ├── ProductCreate.tsx
19│   │   └── ProductForm.tsx
20│   ├── orders/
21│   │   ├── index.ts
22│   │   ├── OrderList.tsx
23│   │   ├── OrderEdit.tsx
24│   │   └── OrderTotals.tsx
25│   └── customers/
26│       └── ...
27├── dashboard/
28│   └── Dashboard.tsx
29├── components/
30│   └── PriceField.tsx
31└── types.ts

The key is the index.ts in each resource folder. It exports an object whose shape matches the props of <Resource>:

src/resources/products/index.ts
1import ProductIcon from '@mui/icons-material/Inventory2';
2import { ProductList } from './ProductList';
3import { ProductEdit } from './ProductEdit';
4import { ProductCreate } from './ProductCreate';
5
6export default {
7  list: ProductList,
8  edit: ProductEdit,
9  create: ProductCreate,
10  icon: ProductIcon,
11  recordRepresentation: 'name',
12};

App.tsx then becomes a table of contents:

src/App.tsx
1import { Admin, Resource } from 'react-admin';
2import { dataProvider, authProvider, i18nProvider } from './providers';
3import { Layout } from './layout/Layout';
4import products from './resources/products';
5import orders from './resources/orders';
6import customers from './resources/customers';
7
8export const App = () => (
9  <Admin
10    dataProvider={dataProvider}
11    authProvider={authProvider}
12    i18nProvider={i18nProvider}
13    layout={Layout}
14  >
15    <Resource name="products" {...products} />
16    <Resource name="orders" {...orders} />
17    <Resource name="customers" {...customers} />
18  </Admin>
19);

Adding a resource is now a predictable recipe: create a folder, export the object, add one line to App.tsx. Removing a resource means deleting a folder and a line. ProductForm.tsx, shared by the create and edit views, sits beside both of them and is invisible to the rest of the app.

Two rules keep this level healthy:

  • components/ at the root is only for code used by two or more resources. PriceField qualifies if products and orders both render it. OrderTotals does not, so it stays in orders/.
  • Files are named after what they export, in the same case: ProductList.tsx exports ProductList. Folders are plural and lowercase, matching the resource name the API uses.

When to move on: the data provider and translation files become merge-conflict hot spots, a resource folder holds more than ten or twelve files, you start adding tests in earnest, or more than one team works in the repository.

Level 3: Self-contained feature modules

Fits: multiple developers or teams, twenty or more resources, an app expected to live for years.

At this level each resource folder owns everything about its domain, including its slice of the global concerns. The central provider files stop holding resource-specific logic and become thin assemblers.

1src/
2├── app/
3│   ├── App.tsx
4│   ├── resources.tsx
5│   └── routes.tsx
6├── providers/
7│   ├── data/
8│   │   ├── index.ts
9│   │   ├── httpClient.ts
10│   │   └── baseDataProvider.ts
11│   ├── auth/
12│   │   ├── index.ts
13│   │   ├── authProvider.ts
14│   │   └── permissions.ts
15│   └── i18n/
16│       ├── index.ts
17│       ├── en.ts
18│       └── fr.ts
19├── layout/
20│   ├── Layout.tsx
21│   ├── Menu.tsx
22│   ├── AppBar.tsx
23│   └── theme/
24├── resources/
25│   ├── products/
26│   │   ├── index.ts
27│   │   ├── views/
28│   │   │   ├── ProductList.tsx
29│   │   │   ├── ProductList.test.tsx
30│   │   │   ├── ProductEdit.tsx
31│   │   │   ├── ProductCreate.tsx
32│   │   │   └── ProductShow.tsx
33│   │   ├── components/
34│   │   │   ├── ProductForm.tsx
35│   │   │   ├── ProductForm.test.tsx
36│   │   │   ├── ProductFilters.tsx
37│   │   │   └── StockBadge.tsx
38│   │   ├── hooks/
39│   │   │   ├── useStockLevel.ts
40│   │   │   └── useStockLevel.test.ts
41│   │   ├── data/
42│   │   │   ├── lifecycle.ts
43│   │   │   └── fixtures.ts
44│   │   ├── i18n/
45│   │   │   ├── en.ts
46│   │   │   └── fr.ts
47│   │   ├── validation.ts
48│   │   └── types.ts
49│   └── orders/
50│       └── ...
51├── pages/
52│   ├── dashboard/
53│   └── settings/
54├── shared/
55│   ├── components/
56│   ├── fields/
57│   ├── inputs/
58│   ├── hooks/
59│   └── utils/
60└── test/
61    ├── setup.ts
62    ├── renderWithAdmin.tsx
63    └── server.ts

Several things changed. Each deserves an explanation.

Sub-folders inside a resource

Once a resource has more than a dozen files, split it by role: views/ for the components registered on <Resource>, components/ for the pieces those views are built from, hooks/ for logic, and data/ for anything related to the API. This is type-based grouping, but applied inside a domain boundary, where it helps. Small resources can stay flat. Do not create empty sub-folders for symmetry.

Resource-specific data logic lives with the resource

A central data provider should know how to talk to your API in general. It should not know that products need their images uploaded before saving. React-admin's withLifecycleCallbacks lets each resource declare its own behavior:

src/resources/products/data/lifecycle.ts
1import type { ResourceCallbacks } from 'react-admin';
2import { uploadImages } from './uploadImages';
3
4export const productLifecycle: ResourceCallbacks = {
5  resource: 'products',
6  beforeSave: async (data) => ({
7    ...data,
8    images: await uploadImages(data.images),
9  }),
10};
src/providers/data/index.ts
1import { withLifecycleCallbacks } from 'react-admin';
2import { baseDataProvider } from './baseDataProvider';
3import { productLifecycle } from '@/resources/products';
4import { orderLifecycle } from '@/resources/orders';
5
6export const dataProvider = withLifecycleCallbacks(baseDataProvider, [
7  productLifecycle,
8  orderLifecycle,
9]);

If different resources are served by different backends, combineDataProviders does the same job at a higher level, routing each resource name to its own provider. Either way, the central file is a list, not a switch.

Translations are split per resource

React-admin looks up resource labels under resources.<name>. Each resource can own that subtree:

src/resources/products/i18n/en.ts
1export default {
2  name: 'Product |||| Products',
3  fields: {
4    name: 'Name',
5    price: 'Unit price',
6    stock: 'In stock',
7  },
8  actions: {
9    restock: 'Restock',
10  },
11};
src/providers/i18n/en.ts
1import englishMessages from 'ra-language-english';
2import products from '@/resources/products/i18n/en';
3import orders from '@/resources/orders/i18n/en';
4
5export default {
6  ...englishMessages,
7  resources: { products, orders },
8};

Two developers adding fields to two different resources no longer edit the same file.

Resource registration moves out of App.tsx

With thirty resources, the list of <Resource> elements deserves its own file. app/resources.tsx holds it, app/routes.tsx holds the <CustomRoutes>, and App.tsx only composes providers and layout. This keeps the most frequently edited list separate from the rarely edited app configuration.

Pages that are not resources

A dashboard, a reports screen, or a settings page has no CRUD views and no entry in the data provider. Put these in pages/ and register them with <CustomRoutes>. They follow the same rules as resources: one folder each, a public index.ts, private internals.

The shared folder has structure of its own

shared/ is split by kind because its contents are general by definition. A useful convention is to mirror react-admin's own vocabulary: fields/ for components that display a record value, inputs/ for components that edit one, and components/ for everything else. A developer looking for a reusable money input knows to check shared/inputs/ before writing a new one.

Avoid a catch-all utils.ts or helpers.ts. Name files after what they contain: formatCurrency.ts, dateRanges.ts. A file with a specific name resists becoming a dumping ground.

Path aliases

Deep relative imports such as ../../../shared/fields/PriceField are hard to read and break when files move. Configure one alias in tsconfig.json and in your bundler:

1{
2  "compilerOptions": {
3    "baseUrl": ".",
4    "paths": { "@/*": ["src/*"] }
5  }
6}

Use the alias for imports that cross a module boundary and relative paths for imports within a module. The import style then tells you at a glance whether a dependency is internal or external.

Where tests belong

Structure determines how expensive tests are to write, so it is worth being explicit about each kind.

Unit and component tests: next to the source

ProductForm.test.tsx sits beside ProductForm.tsx. When the component moves, the test moves with it. When the component is deleted, the orphaned test is obvious. Reviewers can see in the file tree which files have tests and which do not.

Shared test infrastructure: one folder

React-admin components need context: a data provider, a query client, a router, a resource name. Rebuilding that in every test file is the main reason admin tests feel heavy. Write it once:

src/test/renderWithAdmin.tsx
1import type { ReactElement } from 'react';
2import { render } from '@testing-library/react';
3import {
4  AdminContext,
5  ResourceContextProvider,
6  testDataProvider,
7  type DataProvider,
8} from 'react-admin';
9
10interface Options {
11  resource?: string;
12  dataProvider?: Partial<DataProvider>;
13}
14
15export const renderWithAdmin = (
16  ui: ReactElement,
17  { resource = 'test', dataProvider = {} }: Options = {},
18) =>
19  render(
20    <AdminContext dataProvider={testDataProvider(dataProvider)}>
21      <ResourceContextProvider value={resource}>{ui}</ResourceContextProvider>
22    </AdminContext>,
23  );

A component test is now short enough that people write it:

src/resources/products/views/ProductList.test.tsx
1import { screen } from '@testing-library/react';
2import { renderWithAdmin } from '@/test/renderWithAdmin';
3import { ProductList } from './ProductList';
4import { products } from '../data/fixtures';
5
6it('lists products returned by the API', async () => {
7  renderWithAdmin(<ProductList />, {
8    resource: 'products',
9    dataProvider: {
10      getList: async () => ({ data: products, total: products.length }),
11    },
12  });
13
14  expect(await screen.findByText(products[0].name)).toBeInTheDocument();
15});

Fixtures: owned by the resource

Sample records live in resources/products/data/fixtures.ts. Unit tests, integration tests, Storybook stories, and a local fake API can all import the same data. When the product type gains a field, TypeScript flags one fixtures file, not thirty inline objects.

Integration tests: one per user flow

An integration test covers a path through several components, such as "create a product, see it in the list, edit its price." Two approaches work well, and the structure supports both:

  • Run the real views against an in-memory data provider such as ra-data-fakerest, seeded from the resource fixtures. This is fast and tests everything above the provider.
  • Run the real data provider against a mocked network using Mock Service Worker, with handlers defined in src/test/server.ts. This also tests your provider's request and response mapping, which is where many real bugs live.

Name these files *.integration.test.tsx and keep them in the resource folder they primarily exercise. The suffix lets you run them as a separate CI step.

End-to-end tests: outside src

Playwright or Cypress tests drive a built app in a real browser. They are not tied to one module and they use different tooling, so they live in a top-level e2e/ directory, organized by user journey and not by resource:

1e2e/
2├── auth.spec.ts
3├── order-fulfilment.spec.ts
4└── fixtures/

Keep this suite small. It should cover login, permissions, and a few critical journeys. The bulk of your confidence should come from the faster layers.

Level 4: Enforced boundaries and beyond

Fits: several teams, fifty or more resources, or multiple admin apps that share code.

Level 3 relies on convention. Conventions hold in a team of five and erode in a team of twenty-five. Level 4 keeps the same shape and makes the rules mechanical.

Lint the boundaries

The rule "import a resource only through its index.ts" can be enforced with ESLint's built-in no-restricted-imports:

eslint.config.js
1{
2  rules: {
3    'no-restricted-imports': ['error', {
4      patterns: [{
5        group: ['@/resources/*/*'],
6        message: 'Import from the resource index, not from its internals.',
7      }],
8    }],
9  },
10}

Because code inside a resource uses relative imports, this rule only catches crossings. For finer control, such as "shared may not import from resources" or "resources may not import from other resources at all," eslint-plugin-boundaries and dependency-cruiser let you declare the allowed dependency graph and fail CI when it is violated.

Decide how resources talk to each other

Resources are related. An order form needs a customer selector. There are three acceptable answers, in order of preference:

  1. Use react-admin's reference components. <ReferenceInput source="customer_id" reference="customers"> needs no import from the customers folder at all. The resource name is the contract.
  2. Export the needed component from the other resource's index.ts, making it part of that module's public API on purpose.
  3. If three or more resources need it, promote it to shared/.

What you should never do is reach into resources/customers/components/ from orders. That one import makes every file in customers part of an implicit public API.

Lazy-load resources

Self-contained resources split cleanly. Change the index to load its views on demand:

src/resources/products/index.ts
1import { lazy } from 'react';
2import ProductIcon from '@mui/icons-material/Inventory2';
3
4export default {
5  list: lazy(() => import('./views/ProductList')),
6  edit: lazy(() => import('./views/ProductEdit')),
7  create: lazy(() => import('./views/ProductCreate')),
8  icon: ProductIcon,
9};

React.lazy requires each view to be a default export. The initial bundle now contains the shell and the first screen, and every other resource arrives when the user navigates to it. In a large admin this is often the biggest performance improvement available, and it costs a few lines per resource once the boundaries exist.

Generate new resources

When the recipe for a resource is fixed, script it. A generator such as Plop or Hygen can produce the folder, the index, the four views, the translation file, a fixtures file, and a first test from templates. Consistency stops depending on memory, and a new developer's first resource looks exactly like the fiftieth.

Assign ownership

Because a directory now maps to a domain, a CODEOWNERS file can map directories to teams:

1/src/resources/orders/     @acme/fulfilment
2/src/resources/products/   @acme/catalog
3/src/shared/               @acme/admin-platform
4/src/providers/            @acme/admin-platform

Changes to shared code get reviewed by the people responsible for it. Changes inside a resource stay within the owning team.

Extract packages when there is a second consumer

If your organization runs more than one admin app, or if build and test times in a single package become a bottleneck, the Level 3 folders map directly onto a monorepo using pnpm workspaces, Turborepo, or Nx:

1apps/
2├── backoffice/
3└── partner-portal/
4packages/
5├── admin-ui/           # was shared/
6├── data-provider/      # was providers/data/
7├── auth/               # was providers/auth/
8├── catalog/            # was resources/products, categories, ...
9└── fulfilment/         # was resources/orders, shipments, ...

Each package has its own package.json, its own tests, and an explicit list of dependencies. Build tools can cache and skip packages that did not change.

Do not start here. A monorepo adds real overhead in tooling, versioning, and CI configuration. It pays off when the boundaries are already proven inside one app, and moving a well-isolated folder into a package is mostly a matter of moving it.

Conventions that keep a codebase consistent

Structure is half of consistency. The other half is a short list of written conventions. These work well for react-admin projects:

  • Resource folders are plural and match the API resource name exactly: products/, order-items/.
  • Component files use PascalCase and match their export: ProductList.tsx.
  • View names follow the pattern <Singular><View>: ProductList, ProductEdit, ProductCreate, ProductShow.
  • Hooks use camelCase with a use prefix: useStockLevel.ts.
  • Tests share the name of their subject with a .test suffix. Integration tests use .integration.test.
  • One component per file, apart from small private helpers used only in that file.
  • Named exports everywhere except where a tool requires a default, such as the resource index and lazy-loaded views.
  • Types for a resource's records live in the resource's types.ts and are exported through its index. Types shared across the app, such as an Identifier alias or a paginated response, live in shared/types.ts.
  • Permissions are checked with react-admin's own hooks (useCanAccess, usePermissions) and the rules themselves are defined in one place, providers/auth/permissions.ts. Views ask "can the user do this?" and never inspect roles directly.

Write these down in a CONTRIBUTING.md at the root of the repository, together with a tree diagram of the structure and the steps to add a resource. A convention that is not written down is only a habit of whoever joined first.

Common mistakes

Moving code to shared too early. A component used by one resource and "probably useful elsewhere" stays where it is. Shared code is harder to change, so it should earn its place.

Barrel files everywhere. An index.ts at the boundary of a resource is a public interface. An index.ts in every sub-folder that re-exports everything is noise, slows down tooling, and can cause circular imports. Use one per module.

A global state folder. React-admin already manages server state through React Query and UI state through its own store. A top-level store/ or redux/ directory in a react-admin app usually means data is being fetched outside the data provider. Before adding one, check whether useGetList, useGetOne, or useStore already solves the problem.

Fetching outside the data provider. A fetch call inside a component bypasses caching, authentication headers, error handling, and every test helper you built. Add a custom method to the data provider and call it with useDataProvider.

Structuring by view type. Folders named lists/, edits/, and creates/ group files that have nothing in common except their shape. This is the type-based problem again under a react-admin vocabulary.

Restructuring everything at once. A branch that moves three hundred files conflicts with every open pull request and is impossible to review.

Migrating an existing app

If you already have a large app in a type-based layout, move incrementally:

  1. Agree on the target structure and write it down.
  2. Add the path alias and the shared test helper. Neither moves any existing file.
  3. Build every new resource in the new structure from now on.
  4. Migrate existing resources one at a time, each in its own pull request, ideally when you are already working on that resource for another reason.
  5. Once most resources are migrated, split the data provider and the translation files.
  6. Add the lint rules last, when the code already complies, so that they protect the structure and do not block the migration.

During the transition the codebase holds two styles. That is acceptable as long as the direction is documented and each change moves toward it.

Summary

React-admin makes the first version of an admin app fast to build. Keeping the fiftieth resource as easy as the first depends on decisions the framework leaves to you.

Start flat while the app is small. Move to one folder per resource with an index that mirrors the <Resource> props as soon as the app has real users. As teams and resources multiply, make each resource own its views, data logic, translations, fixtures, and tests, and reduce the central provider files to short lists. When convention is no longer enough, enforce the boundaries with lint rules, generate new resources from templates, load them lazily, and assign owners.

At every level the test is the same. A developer who has never seen the codebase should be able to answer "where is this?" and "where does this go?" from the folder tree alone. If they can, the structure is doing its job.