A robust backend system demonstrating how to apply Object-Oriented Programming (OOP) principles and Layered Architecture to modern Node.js applications.
This repository serves as a reference for building scalable Node.js applications. Unlike typical functional-style Express apps, this project uses a Class-Based Architecture with Manual Dependency Injection.
It separates concerns strictly between:
- Routes: Definition of endpoints.
- Controllers: Handling HTTP Request/Response lifecycle.
- Services: Pure business logic and database interaction.
- Middlewares: JWT validation and ID verification.
The application follows a Layered Architecture to ensure maintainability and testability.
- Manual Dependency Injection: Controllers receive their Services via constructor injection, making the code modular and easier to mock for testing.
// Example from AuthRoutes.ts
const authService = new AuthService();
const authController = new AuthController(authService); // 💉 Injection-
Express 5 (Modern Standard): Utilizes the latest Express version for improved promise handling and performance.
-
Strict Typing: Full TypeScript implementation with DTOs (Data Transfer Objects) to validate data flow.
- 🔐 Secure Authentication: Full JWT flow including Login, Register, and Token Renewal (
/renew). - 🛡️ Guarded Routes: Custom
AuthMiddlewareprotects sensitive endpoints. - 📅 Event Management: Complete CRUD operations for calendar events.
- ⚙️ ID Validation:
MongoidMiddlewareensures MongoDB ObjectIDs are valid before hitting the controller. - 🐳 Dockerized Dev: Includes Docker Compose configuration for instant MongoDB setup.
- Runtime: Node.js
- Language: TypeScript 5.9
- Framework: Express 5.1.0
- Database: MongoDB (via Mongoose 8)
- Security:
bcryptjs(Hashing),jsonwebtoken(JWT) - Utilities:
dayjs(Date manipulation),env-var(Strict Environment Config) - Dev Tools:
tsx(TypeScript Execution), Docker
src/
├── auth/ # Auth Module (Routes, Controller)
├── event/ # Event Module (Routes, Controller)
├── services/ # Business Logic Layer
├── middlewares/ # Interceptors (Auth, Validation)
├── models/ # Mongoose Schemas
└── app.ts # App Entry Point & Server Config
- Node.js v18+
- Docker (for Database)
- Clone the repository:
git clone https://github.com/huderdcv/calendar-app-backend.git- Start Database:
docker-compose up -d- Install Dependencies:
npm install-
Configure Environment:
Rename.env.templateto.envand add your JWT Seed. -
Run in Development Mode:
npm run dev