Skip to content

A backend service providing secure authentication, role-based access, and RESTful APIs for managing users, products, and a dashboard.

Notifications You must be signed in to change notification settings

vermaharsha/user-management-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Management API

Project Summary

A backend service built with Node.js, Express, and MongoDB (using Mongoose). The service provides a robust RESTful API for managing users and products while ensuring secure authentication and role-based access control. A simple dashboard is also included to help manage data visually.

Features

  • User & Product Management:
    • Full CRUD operations for users and products.
  • Secure Authentication:
    • Uses JSON Web Tokens (JWT) for authentication.
    • Passwords are securely hashed with bcrypt.
  • Role-Based Access Control:
    • Enforces different access levels (Admin, Seller, Customer) for various endpoints.
  • Clean and Modular Architecture:
    • Easy to extend and maintain.

Tech Stack

  • Backend: Node.js, Express.js
  • Frontend: Ejs
  • Database: MongoDB with Mongoose
  • Authentication: JWT, bcrypt.js
  • Utilities: dotenv, nodemon, morgan, cors

Installation & Setup

  1. Clone the Repository:

    git clone https://github.com/yourusername/BlueMedix.git
    cd BlueMedix
  2. Install Dependencies:

    npm install
  3. Configure Environment Variables: Create a .env file in the root directory with the following:

    PORT=3000
    MONGO_URI=mongodb://localhost:27017/bluemedix
    JWT_SECRET=your_jwt_secret
  4. Run the Application:

    npm run dev

    The server should now run on http://localhost:3000 and connect to your MongoDB instance.

API Endpoints

Authentication

  • Register User:

    • Method: POST
    • URL: /api/auth/register
    • Description: Creates a new user.
  • Login User:

    • Method: POST
    • URL: /api/auth/login
    • Description: Authenticates a user and returns a JWT token.

User Management (Admin & Authenticated Users)

  • Get All Users:

    • Method: GET
    • URL: /api/users
    • Description: Retrieves a list of all users (admin-only).
  • Get Single User:

    • Method: GET
    • URL: /api/users/:id
    • Description: Retrieves details of a specific user.
  • Update User:

    • Method: PUT
    • URL: /api/users/:id
    • Description: Updates user information.
  • Delete User:

    • Method: DELETE
    • URL: /api/users/:id
    • Description: Deletes a user (admin-only).

Product Management

  • Get All Products:

    • Method: GET
    • URL: /api/products
    • Description: Retrieves all products.
  • Create Product:

    • Method: POST
    • URL: /api/products
    • Description: Creates a new product (accessible to sellers/admins).
  • Update Product:

    • Method: PUT
    • URL: /api/products/:id
    • Description: Updates product details.
  • Delete Product:

    • Method: DELETE
    • URL: /api/products/:id
    • Description: Deletes a product.

Note: For protected routes, include the following header:

Authorization: Bearer <your_jwt_token>

Visual Overview

User Register

Register

User Login

Login

MongoDB

Screenshot 2025-03-05 184019

Future Enhancements

  • Implement Caching: Add Redis for caching frequent queries.
  • Automated Testing: Integrate unit and integration tests.
  • Enhanced Error Handling: Improve logging and error responses.

About

A backend service providing secure authentication, role-based access, and RESTful APIs for managing users, products, and a dashboard.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published