🧱 A Proper MERN Stack File Structure (Backend + Frontend) A clean structure today saves hours tomorrow. File structure is not just organization; it’s maintainability, scalability, and clarity. Here’s a real-world, production-ready MERN setup 👇 Backend Structure (Node.js + Express + MongoDB) backend/ ├─ src/ │ ├─ config/ │ │ ├─ db.js # MongoDB connection │ │ └─ env.js # environment config │ │ ├─ models/ │ │ └─ user.model.js # Mongoose schemas │ │ ├─ controllers/ │ │ └─ user.controller.js # request logic │ │ ├─ routes/ │ │ └─ user.routes.js # API routes │ │ ├─ middlewares/ │ │ ├─ auth.middleware.js │ │ └─ error.middleware.js │ │ ├─ services/ │ │ └─ user.service.js # business logic │ │ ├─ utils/ │ │ └─ helpers.js │ │ ├─ app.js # express app config │ └─ server.js # server entry point │ ├─ .env # environment variables ├─ .gitignore ├─ package.json 🧠 Why this backend structure works • Routes only handle endpoints • Controllers handle request/response • Services hold business logic • Models manage database structure • Middleware stays reusable and clean • server.js starts the app, app.js configures it 👉 Easy to scale, test, and debug. Frontend Structure (React App) frontend/ ├─ src/ │ ├─ assets/ # images, icons │ ├─ components/ # reusable UI components │ ├─ pages/ # route-level pages │ ├─ hooks/ # custom hooks │ ├─ services/ # API calls (axios) │ ├─ context/ # global state │ ├─ utils/ # helpers │ ├─ styles/ # global styles │ │ ├─ App.jsx │ ├─ main.jsx │ └─ index.css │ ├─ public/ │ └─ index.html │ ├─ package.json 🧠 Why this frontend structure works • Clear separation of UI, logic, and data • Pages stay clean and readable • API logic doesn’t mix with components • Scales smoothly as features grow 🚀 Final Thought A good file structure: • improves collaboration • reduces bugs • makes onboarding easier • keeps projects future-proof Good code is important. Good structure makes good code last. 💬 How do you structure your MERN projects — layer-based or feature-based? #WebDevelopment #FullStackDeveloper #MERNStack #Laravel #JavaScript #ReactJS #NodeJS #PHP #SoftwareEngineering #TechCommunity #CodingLife #DeveloperJourney
This articles are about structure – might interest you: https://www.garudax.id/posts/andreas-wagner-9b0684384_domain-composite-rootcomposition-activity-7420668400789549056-kWZx? This spring-boot approach of a folder structure that follows the business context, not technical layers: https://www.garudax.id/posts/andreas-wagner-9b0684384_decoratorpattern-softwareengineering-cleancode-activity-7423025189745225728-QnEE?utm_source=share&utm_medium=member_desktop&rcm=ACoAAF7IsJQBJrzCuyzSrNEQroUVFBQUNJiu-0s
This structure helps not realy - or it helps to expand the Abstraction Gap (see the image): I think a better frontend/backend should only reflect business-concepts, not technical ones and look like this: [app-name] ├── src/ | ├─ application/ | ├─ customer/ | ├─ payment/ | ├─ inventory/ | ├─ shipping/ | ├─ user/ | ├─ Customer.ts | ├─ Product.ts | ├─ Products.ts | ├─ Order.ts | ├─ Orders.ts | ├─ Payment.ts | ├─ Shipment.ts | └─ ShopApplication.ts Can you see what the above app is about? Try this 3 golden Rules - to achieves the next level of readability - so that your code tells a customer story. 1. Packages should never depend on sub-packages. 2. Sub-packages should not introduce new concepts, just more details. 3. Packages should reflect business-concepts, not technical ones. It's fine to use subpackages within other packages, as long as they aren't at the same hierarchy level. Be mindful of cyclic dependencies. The trick is to focus on the level "0" by placing the classes (interfaces/abstract classes/value objects/entities) of the main concepts there (without technical clutter). The packages then provide the implementations for these concepts.