A scalable, maintainable Node.js backend built with TypeScript, Express, MongoDB, and best practices for modern development.
- 📐 Architecture
- ⚙️ Tech Stack
- 🚀 Getting Started
- 🏗️ Project Structure
- 🔐 Environment Configuration
- 📦 API Versioning
- ✅ Code Quality
- 📈 Monitoring & Logging
- Monolithic
- Clean code separation: controllers, services, routes
- API versioning (
/api/v1,/api/v2) - Environment-based configuration (12-factor app)
| Layer | Tech |
|---|---|
| Runtime | Node.js (v18+) |
| Language | TypeScript (strict mode) |
| Server | Express.js |
| Database | MongoDB + Mongoose |
| Linting | ESLint + Prettier |
| Logging | Winston |
| Validation | Joi |
| Auth | JWT + Bcrypt |
- Node.js = 18.20.x
- MongoDB ≥ 6.x (local or Atlas)
- npm
git clone https://github.com/your-org/project-name.git
cd project-name
cp .env.example .env
npm installnpm run devRuns with ts-node-dev for hot-reloading.
npm run build
npm run startsrc/
├── api/
│ ├── v1/
│ │ ├── controllers/
│ │ ├── routes/
│ │ └── services/
├── config/ # Env config
├── constants/ # HTTP constants and messages
├── db/ # DB configuration and models
├── exceptions/ # HTTP Exceptions
├── interfaces/ # TypeScript interfaces
├── middleware/ # Auth, error handling, etc.
├── utils/ # Helpers/utilities
├── validations/ # Joi schemas
├── app.ts # Express app setup
└── server.ts # Entry pointCreate .env from .env.example:
NODE_ENV=development
PORT=3000
MONGODB_URI=mongodb://localhost:27017/app-db
JWT_SECRET=your_jwt_secret
JWT_EXPIRATION=1dUse a central env.ts to type-check all variables.
-
Support for multiple versions:
/api/v1/users /api/v2/users -
Controllers, routes, services separated per version.
-
Add a new version via:
cp -r src/api/v1 src/api/v2
- TypeScript strict mode
- ESLint + Prettier
- Linting and formatting scripts:
npm run lint
npm run prettierWinstonlogger with timestamps, context, and log levels