Skip to content

drnsmith/SQLtoAPI-RBAC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL to API: Functional APIs with Role-Based Access Control

A modular and scalable backend system integrating secure authentication, role-based access control, and PostgreSQL database-driven RESTful APIs.

Motivation

The increasing complexity of modern web applications necessitates secure and efficient ways to manage data and user access. Traditional applications often face challenges such as:

  • Security Gaps: Insufficient or improperly implemented user authentication and role-based access control can lead to vulnerabilities.
  • Scalability Issues: Poorly designed APIs can become bottlenecks as applications grow.
  • Time-Consuming Integration: Developers often need to spend significant time integrating databases with APIs and implementing security layers.

This project addresses these challenges by creating a modular and scalable API framework that integrates robust authentication and role-based access control (RBAC) with a PostgreSQL database. The goal is to provide a foundational solution that developers can easily adapt and extend for real-world applications, ensuring security, performance, and scalability.


Project Overview

SQL to API: Functional APIs with Role-Based Access Control is a full-stack project aimed at building a secure and scalable backend system using Node.js and PostgreSQL. It showcases the integration of database-driven RESTful APIs with advanced access management features, making it an excellent foundation for enterprise-grade applications.

Key Objectives:

  1. Security First:

    • Implement industry-standard authentication with hashed passwords and JWTs.
    • Incorporate role-based access control to regulate resource access based on user roles.
  2. Database-Centric Design:

    • Use PostgreSQL as the relational database for storing user data and permissions.
    • Ensure efficient database queries and data handling.
  3. Modularity & Scalability:

    • Structure the project for easy extension and scalability.
    • Provide a clean and reusable codebase for future enhancements.
  4. Practical Use Cases:

    • Demonstrate the ability to create, read, update, and delete (CRUD) operations with role-based access restrictions.
    • Serve as a robust backend framework for any application requiring secure data handling.

Features

  • Authentication and Authorisation:

    • User registration and login with encrypted passwords.
    • JWT-based stateless authentication.
    • Role-based middleware to enforce permissions.
  • Database Management:

    • Centralised data storage with a well-defined schema in PostgreSQL.
    • SQL schema provided for quick database setup.
  • RESTful Endpoints:

    • Comprehensive CRUD operations, secured and optimized.
    • Separation of concerns for routing, middleware, and business logic.
  • Extensibility:

    • Easily adaptable for different use cases, such as e-commerce, education, or financial applications.

Getting Started

Prerequisites

  • Node.js (v16+)
  • PostgreSQL (v13+)
  • npm (v7+)

Installation

  1. Clone the repository:

    git clone https://github.com/drnsmith/SQLtoAPI-Functional-APIs-with-Role-Based-Access-Control-from-Postgres-DB-using-NodeJS.git
    cd SQLtoAPI-Functional-APIs-with-Role-Based-Access-Control-from-Postgres-DB-using-NodeJS
  2. Install dependencies:

    npm install
  3. Configure the database:

    • Create a PostgreSQL database using the provided db_uni.sql script.
    • Update the db.js file with your database credentials.
  4. Run the application:

    npm start

Folder Structure

  • app.js: Initializes the server and middleware.
  • db.js: Handles database connection and queries.
  • index.js: Defines the application routes.
  • db_uni.sql: SQL script for creating the database schema.
  • package.json & package-lock.json: Dependencies and scripts for the project.

Technologies Used

  • Languages: JavaScript
  • Backend Framework: Node.js (Express.js)
  • Database: PostgreSQL
  • Authentication: JWT (JSON Web Tokens), bcrypt.js
  • Role-Based Access Control: Middleware for authorization
  • Deployment: Docker-ready

Contribution Guidelines

We welcome contributions to enhance this project! Please follow these steps:

  1. Fork the repository.
  2. Create a feature branch.
  3. Commit your changes with clear messages.
  4. Submit a pull request for review.

License

This project is licensed under the MIT License.

About

The purpose of this project is to create SQL queries to support functional requirements, create a business logic layer to have API for each functional requirement using NodeJS, test and demonstrate results using Postman, and practice remote database connection and role-based access control.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors