Skip to content

πŸ” Built with Node.js, Express.js, and MongoDB, this project follows DDD architecture and SOLID principles for a scalable and maintainable authentication system. It supports password-basedπŸ”‘ and OTP-based login, email verification, and JWT authentication for secure access.

Notifications You must be signed in to change notification settings

Mayankkamriya/UnihoxTask-Authentication-API-DDD-Architecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Authentication API (DDD & SOLID Architecture)

πŸ“Œ Overview

This project is a secure authentication system built using Node.js, Express, MongoDB, and JWT, following Domain-Driven Design (DDD) and adhering to SOLID principles. It provides multiple authentication methods, including password-based login and OTP-based login, with email verification via Nodemailer.


✨ Features

  • πŸ“ User Registration with email and password
  • πŸ“§ Email Verification through OTP
  • πŸ”‘ Secure Authentication with JWT
  • πŸ” Password-based Login
  • πŸ”’ OTP-based Login
  • πŸ”“ Token-based Authorization
  • πŸ” Resend OTP functionality
  • πŸ›‘οΈ Middleware for Protected Routes

πŸ›  Technology Stack

  • πŸš€ Backend: Node.js, Express.js
  • πŸ—„οΈ Database: MongoDB (Mongoose ODM)
  • πŸ”‘ Authentication: JWT, bcrypt for password hashing
  • πŸ“§ Email Service: Nodemailer with SMTP
  • πŸ›‘οΈ Validation: Zod
  • πŸ”’ Security: CORS, dotenv for environment configuration

πŸ“‚ Folder Structure (DDD)

/backend
 β”œβ”€β”€ /src
 β”‚   β”œβ”€β”€ /domain
 β”‚   β”‚   β”œβ”€β”€ services
 β”‚   β”‚   β”‚   β”œβ”€β”€ AuthService.js
 β”‚   β”œβ”€β”€ /infrastructure
 β”‚   β”‚   β”œβ”€β”€ models
 β”‚   β”‚   β”‚   β”œβ”€β”€ otp.js
 β”‚   β”‚   β”‚   β”œβ”€β”€ user.js
 β”‚   β”‚   β”œβ”€β”€ email
 β”‚   β”‚       β”œβ”€β”€ EmailService.js
 β”‚   β”‚   β”œβ”€β”€ db.js
 β”‚   β”œβ”€β”€ /presentation
 β”‚   β”‚   β”œβ”€β”€ middleware
 β”‚   β”‚       β”œβ”€β”€ auth.js
 β”‚   β”‚   β”œβ”€β”€ routes
 β”‚   β”‚       β”œβ”€β”€ otp.js
 β”‚   β”‚       β”œβ”€β”€ signin.js
 β”‚   β”‚       β”œβ”€β”€ signup.js
 β”‚   β”œβ”€β”€ index.js
/frontend
 β”œβ”€β”€ /src
 β”‚   β”œβ”€β”€ /components
 β”‚   β”‚   β”œβ”€β”€ Dashboard.jsx
 β”‚   β”‚   β”œβ”€β”€ MainPage.jsx
 β”‚   β”‚   β”œβ”€β”€ SignInOtp.jsx
 β”‚   β”‚   β”œβ”€β”€ SignInPassword.jsx
 β”‚   β”‚   β”œβ”€β”€ SignUp.jsx
 β”‚   β”œβ”€β”€ App.jsx

βš™οΈ Setup Instructions

πŸ“₯ Clone the Repository:

git clone https://github.com/Mayankkamriya/UnihoxTask.git

πŸ“Œ Install Backend Dependencies & Start Server:

cd backend
npm install
cd src
node index.js

πŸ“Œ Install Frontend Dependencies & Start App:

cd frontend
npm install
npm run dev

πŸ”‘ Environment Variables

Create a .env file in the backend folder:

MONGODB_URI=your-mongodb-connection-string
JWT_SECRET=your-secret-key
EMAIL=your-email
PASS=your-email-password
HOST=smtp.example.com

Create a .env file in the frontend folder:

VITE_API_URL=http://localhost:3000
VITE_JWT_SECRET=your-secret-key

🌍 Open the App at:

http://localhost:3000

πŸ”— API Endpoints

Method Endpoint Description
POST /api/v1/signup Register a new user
POST /api/v1/signin/password Login with email and password
POST /api/v1/signin/request-otp Request OTP for login
POST /api/v1/signin/otp Verify OTP and login
POST /api/v1/resendOTP Resend OTP
GET /api/v1/dashboard Protected route (requires authentication)

🌍 Deployment

πŸ”— Live Demo: https://unihox-task.vercel.app


πŸ‘¨β€πŸ’» Developer Details:

Mayank Kamriya
B.B.A. - Vikram University
🌐 LinkedIn πŸ“§ [email protected]
πŸ“ž +91 8253038815

Made with ❀️ by Mayank Kamriya

About

πŸ” Built with Node.js, Express.js, and MongoDB, this project follows DDD architecture and SOLID principles for a scalable and maintainable authentication system. It supports password-basedπŸ”‘ and OTP-based login, email verification, and JWT authentication for secure access.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages