A clean project structure helps keep your code organized, scalable, and easy to maintain. Here’s how to structure a Node.js app with JWT-based authentication applied selectively.

πŸ—‚οΈ Folder Structure

project-root/
β”œβ”€β”€ config/
β”‚   └── env.js               # Environment config
β”œβ”€β”€ controllers/
β”‚   └── authController.js     # Login, logout, and token logic
β”œβ”€β”€ middlewares/
β”‚   └── authMiddleware.js     # JWT token validation
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ protectedRoutes.js    # Routes requiring authentication
β”‚   └── publicRoutes.js       # Open-access routes
β”œβ”€β”€ utils/
β”‚   └── jwtUtils.js           # JWT utility functions
β”œβ”€β”€ .env                      # Environment variables
β”œβ”€β”€ app.js                    # Main app configuration
└── server.js                 # Server setup

πŸ“ Folder Contents

1. config/

2. controllers/

3. middlewares/

4. routes/

5. utils/

6. .env

7. app.js