A TypeScript REST API for DevTinder β a developer networking platform designed to help software engineers discover, connect, and collaborate with peer developers based on skills, interests, and background.
| Layer | Technology | Purpose |
|---|---|---|
| Runtime & Language | Node.js (v20+) & TypeScript (v5+) | Strict type safety and modern JavaScript execution |
| Web Framework | Express 5 | Web framework with native async error handling |
| Database & ODM | MongoDB & Mongoose (v8) | Document database with schema definitions & indexes |
| Validation | Zod (v4) & validator.js | Strong request validation for body, params, and query |
| Authentication | JSON Web Tokens (jsonwebtoken) & bcrypt |
Secure HttpOnly cookie-based session management |
| Testing | Vitest, Supertest, MongoDB Memory Server | Isolated integration tests with v8 code coverage |
| Code Quality | ESLint 9 (Flat Config), Prettier | Linting and code formatting standards |
| CI/CD | GitHub Actions | Automated lint, test, and build pipeline |
- Authentication & Authorization: Cookie-based JWT sessions (
HttpOnly,SameSite), password hashing viabcrypt, and protected route middleware. - Developer Profiles: View, update allowed profile attributes (skills, bio, about, age, gender, profile picture), and change credentials securely.
- Feed & Discovery Engine: Filtered recommendation feed that excludes the authenticated user as well as anyone already interacted with (interested, ignored, accepted, or rejected), with pagination support (
page,limit). - Connection Request Lifecycle: Full state-machine support for sending (
interested,ignored) and reviewing (accepted,rejected) requests with strict relationship guards. - Connections & Pending Requests: Retrieve accepted connections and incoming pending connection requests with populated user summaries.
- Health & Diagnostics:
/healthendpoint for uptime monitoring and container orchestration health checks. - Robust Error Handling: Centralized error formatting that maps Mongoose validation errors, Zod validation issues, and HTTP status codes cleanly.
- Graceful Shutdown: Handles
SIGTERM,SIGINT, uncaught exceptions, and unhandled rejections with connection draining and database teardown.
dev-tinder-backend/
βββ .github/
β βββ workflows/
β βββ ci.yml # CI pipeline (lint, test, build)
βββ src/
β βββ app.ts # Express app configuration & server bootstrap
β βββ config/
β β βββ db.ts # MongoDB connection lifecycle
β β βββ env.ts # Environment variable loader & assertions
β β βββ shutdown.ts # Graceful termination handler
β βββ constant/
β β βββ enum.ts # Enums & constants (Gender, Status)
β β βββ index.ts # Re-exports
β β βββ responseMessage.ts # Centralized response and error messages
β βββ controller/
β β βββ auth.controller.ts # Signup, login, logout controllers
β β βββ user.controller.ts # Profile, feed, and connections controllers
β β βββ connectionRequests.controller.ts # Send and review request controllers
β β βββ index.ts # Re-exports
β βββ interfaceAndTypes/ # TypeScript types & DTO definitions
β βββ middleware/
β β βββ auth.middleware.ts # JWT authentication middleware
β β βββ validate.middleware.ts # Generic Zod request validator
β β βββ index.ts # Re-exports
β βββ models/
β β βββ user.model.ts # User Mongoose schema & indexes
β β βββ connectionRequest.model.ts # Connection request schema & compound indexes
β β βββ index.ts # Re-exports
β βββ routes/
β β βββ auth.ts # /api/auth routes
β β βββ user.ts # /api/user routes
β β βββ connectionRequests.ts # /api/connection-requests routes
β β βββ index.ts # Re-exports
β βββ SchemaValidator/ # Zod schemas for input validation
β βββ types/ # Express Request type augmentations
β βββ utils/
β βββ errorFormator.ts # Error formatting utility
β βββ htttpError.ts # Custom HTTP Error class
β βββ jwtToken.ts # JWT signing and verification
β βββ password.ts # Password hashing & comparison
β βββ queries.ts # Query string numeric validation helpers
β βββ index.ts # Re-exports
βββ tests/
β βββ env.ts # Test environment variable definitions
β βββ setup.ts # In-memory MongoDB setup/teardown helpers
β βββ auth.test.ts # Auth endpoint integration tests
β βββ user.test.ts # User & feed endpoint integration tests
β βββ connectionRequests.test.ts # Connection request integration tests
βββ eslint.config.cjs # ESLint 9 flat configuration
βββ vitest.config.ts # Vitest configuration & coverage thresholds
βββ tsconfig.json # TypeScript compiler options
βββ package.json
- Node.js: v20.x or higher
- npm: v10.x or higher
- MongoDB: Local instance or MongoDB Atlas URI (not required for running tests)
Clone the repository and install dependencies:
git clone https://github.com/Abhishekumar93/dev-tinder-backend.git
cd dev-tinder-backend
npm install --legacy-peer-depsCopy .env.example to .env and fill in your values:
cp .env.example .env| Variable | Type | Description | Example |
|---|---|---|---|
NODE_ENV |
String | Application runtime environment | development / production / test |
PORT |
Number | Server listening port | 8000 |
MONGO_URI |
String | MongoDB connection URI string | mongodb://localhost:27017/devtinder |
JWT_SECRET |
String | Secret key for signing JWTs (min 32 characters) | your_secure_32_character_secret_key |
JWT_EXPIRES_IN |
String | Lifetime of authentication token | 86400 (1 day in seconds) |
FRONTEND_ORIGIN |
String | CORS allowed origin | http://localhost:5173 |
| Command | Description |
|---|---|
npm run dev |
Starts server with live-reloading via tsx watch |
npm run build |
Compiles TypeScript into the dist/ directory |
npm start |
Runs the compiled production build from dist/app.js |
npm test |
Runs the complete integration test suite with Vitest |
npm run test:watch |
Runs test runner in interactive watch mode |
npm run test:coverage |
Generates a v8 code coverage report (enforces β₯85% thresholds) |
npm run lint |
Lints the codebase using ESLint 9 |
npm run format |
Auto-formats codebase using Prettier |
| Method | Endpoint | Auth Required | Description |
|---|---|---|---|
GET |
/health |
No | Returns server liveness status and timestamp |
| Method | Endpoint | Auth Required | Description |
|---|---|---|---|
POST |
/api/auth/signup |
No | Register a new user account |
POST |
/api/auth/login |
No | Authenticate with email + password (or OTP) and set JWT cookie |
POST |
/api/auth/logout |
No | Invalidate session by clearing JWT cookie |
All user endpoints require an authenticated session cookie.
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/user/ |
Fetch current logged-in user profile |
PATCH |
/api/user/ |
Update profile fields (firstName, lastName, age, gender, profilePic, about, bio) |
PATCH |
/api/user/update-password |
Update account password (enforces strong password policy) |
DELETE |
/api/user/ |
Delete the authenticated user account |
GET |
/api/user/feed |
Paginated feed of prospective developers (supports ?page=1&limit=10) |
GET |
/api/user/list |
Public directory listing of developers |
GET |
/api/user/connections |
List all accepted connections for current user |
GET |
/api/user/pending-requests |
List all incoming interested requests sent to current user |
All connection request endpoints require an authenticated session cookie.
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/connection-requests/send/:status/:receiverId |
Send a request to :receiverId. :status must be interested or ignored |
POST |
/api/connection-requests/review/:status/:senderId |
Review an incoming request from :senderId. :status must be accepted or rejected |
[ User A browses Feed ]
β
ββββββββββββββββββ΄βββββββββββββββββ
βΌ βΌ
"interested" "ignored"
(Saved to DB, visible to B) (Excluded from future feeds)
β
βΌ
[ User B checks Pending Requests ]
β
ββββββββββββββββββββββββββββββββββ
βΌ βΌ
"accepted" "rejected"
(Both are now Connections) (Request dismissed)
- Self-action guard: Users cannot send requests to or review requests from themselves.
- Duplicate guard: Compound index on
{ sender, receiver }ensures unique pairs. - Feed filtering: Feed queries query the
ConnectionRequestcollection for all interactions involving the user, excluding those IDs from recommendations.
Tests are executed with Vitest and run against an isolated MongoDB Memory Server for fast, zero-dependency testing without external database requirements.
# Run tests
npm test
# Run tests with coverage report
npm run test:coverage- Statements: β₯85% (Achieved: ~94%)
- Branches: β₯80% (Achieved: ~80.4%)
- Functions: β₯85% (Achieved: ~94.6%)
- Lines: β₯85% (Achieved: ~94%)
- Frontend Application: DevTinder Frontend
- OTP Authentication: The OTP login pathway is structured in the schema and controller for demonstration purposes and currently accepts mock values.
- Rate Limiting: Not currently enabled; recommended for high-throughput production environments using
express-rate-limit. - Real-Time Messaging: Real-time chat between accepted connections can be integrated via WebSockets/Socket.io.
Abhishek Kumar
- GitHub: @Abhishekumar93