How idurar/mern-admin works
Project type and purpose
• This is a full-stack MERN (MongoDB, Express.js, React.js, Node.js) admin dashboard starter app with generic CRUD and JWT-based auth.
• Frontend: React + Ant Design + Redux (with thunk)
• Backend: Node.js + Express.js + Mongoose (MongoDB)
File structure
• Top-level:
• app.js / server.js – application entry points
• controllers/, models/, routes/ – classic MVC pattern on the server
• handlers/ – error-handling middleware
• public/uploads – file storage for uploads
• data/ – sample data loader scripts
• setup/ – one-time backend setup scripts
• frontend/ – complete React application with its own config, src/, public/
• Notice controllers are split into authController, adminController, clientController, leadController, productController, plus a generic crudController
• Frontend src/ is organized by features: components, forms, pages, modules, context (hooks + context API), redux (actions, reducers, selectors), router, service worker, utils, style
README for insights
• Confirms MERN + AntD + Redux, generic CRUD and auth modules, admin management
• Implies two servers at runtime: Node/Express API and React development server (or build artifact served by Express in production)
• Database: MongoDB Atlas
a. Main components
• Web Client (React Single Page App)
• HTTP API Server (Node.js + Express)
• Database (MongoDB)
• File Store (uploads in public/uploads)
• Third-party/Internal Services (e.g., MongoDB Atlas, possible external auth or analytics)
b. Relationships & data flow
1. Browser loads React frontend (served from its own dev server or from Express static middleware).
2. React Router dispatches client-side routes; Redux and Context manage state.
3. UI components call the API via request layer (frontend/src/request/request.js)
4. Express receives HTTP requests at /api/* or /auth/* (routes/api.js, routes/authApi.js)
5. Requests are handled by controllers (authController, crudController, etc.)
6. Controllers call models (Mongoose schemas) to read/write MongoDB
7. Responses flow back to React; state is updated; UI re-renders.
8. File uploads are written to public/uploads by Express (multer or similar) and stored on disk or cloud.
c. Architectural patterns
• Backend: MVC (Models, Views ≈ JSON responses, Controllers) + middleware chain + error handlers
• Frontend: Flux pattern via Redux + Context + Custom Hooks for data fetching and network status
• Generic CRUD module: reusable controllers, React components, context actions, Redux slices
• Auth flow: JWT tokens stored in cookies (auth.service.js + cookie.js), guarded routes (PrivateRoute, PublicRoute)
d. Key technologies
• Frontend: React, React-Redux, Redux-Thunk, @ant-design, CRACO, Babel, Webpack, React Router
• Backend: Node.js, Express, Mongoose, JSON Web Token, environment config (.variables.env), setup scripts
• Infrastructure: MongoDB Atlas, optional cloud hosting (DigitalOcean, etc.)
Detailed separation of components
• In the frontend container:
• Components, Forms, Modules, Hooks, Context, Redux store, Router
• In the backend container:
• Routes layer → Controllers layer → Models layer → Database
• Setup scripts and sample data loader as pre-deployment steps
• Static file serving subcomponent