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