Skip to content

BackSeatDriver-Final-Year-Project/backseatdriver.ie-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

102 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Back Seat Driver - Express API

Project Overview

Back Seat Driver is a telematics-focused application designed to provide drivers with insights into their driving habits, vehicle performance, and recommendations for safer, more efficient driving. The Express API serves as the backend for user authentication, vehicle data management, and app-related functionalities. It uses JWT authentication, MySQL for data storage, and caching mechanisms for optimized performance.

Features

  • User authentication using JWT
  • Secure password storage with bcrypt
  • Vehicle data retrieval with caching for performance optimization
  • CRUD operations for managing app-related data
  • Search functionality for records

Technologies Used

  • Node.js with Express.js
  • MySQL (using mysql2)
  • JWT for authentication
  • bcrypt for password hashing
  • NodeCache for caching
  • CORS for handling cross-origin requests

Installation & Setup

Prerequisites

  • Node.js installed
  • MySQL database configured
  • Environment variables set up for security

Installation

  1. Clone the repository:
    git clone https://github.com/your-repo/backseatdriver-api.git
  2. Install dependencies:
    cd backseatdriver-api
    npm install --force
  3. Configure environment variables:
    export JWT_SECRET=your_jwt_secret_key
    export DB_PASSWORD=your_database_password
  4. Start the server:
    node index.js

API Endpoints

Authentication

Register User

POST /register

  • Request Body:
    {
      "username": "user123",
      "password": "securepassword"
    }
  • Response:
    {
      "message": "User registered successfully"
    }

Login User

POST /login

  • Request Body:
    {
      "username": "user123",
      "password": "securepassword"
    }
  • Response:
    {
      "token": "your_jwt_token"
    }

Vehicle Data

Get Vehicles (Authenticated)

GET /vehicles

  • Headers:
    Authorization: Bearer your_jwt_token
  • Response:
    [
      {
        "id": 1,
        "make": "Toyota",
        "model": "Corolla",
        "year": 2020
      }
    ]

App Data Management

Retrieve All App Records

POST /app_endpoint

  • Response:
    [
      {
        "id": 1,
        "name": "Sample App",
        "description": "An example entry."
      }
    ]

Retrieve Family Records

POST /app_endpoint_family

  • Response:
    [
      {
        "id": 1,
        "name": "John Doe",
        "funeral_time": "2024-06-15"
      }
    ]

Insert a Family Record

POST /api/app_list_family

  • Request Body:
    {
      "Name": "John Doe",
      "Address": "123 Main St",
      "Time": "10:00 AM",
      "Description": "Funeral Service",
      "Personal_msg": "Loving father",
      "Family_flowers": "Yes",
      "Donations": "Charity",
      "Funeral_arrangement": "Private",
      "Date_published": "2024-06-14",
      "Funeral_time": "2024-06-15",
      "Image": "image_url"
    }
  • Response:
    {
      "message": "Data inserted successfully",
      "id": 1
    }

Search Functionality

Search for App Records

GET /search_app

  • Query Parameters:
    • firstname (optional)
    • lastname (optional)
  • Response:
    [
      {
        "id": 1,
        "name": "Jane Doe"
      }
    ]

Posting New Data

Add a Record to App List

POST /posttoapp

  • Request Body:
    {
      "fullname": "Jane Doe",
      "county": "Galway"
    }
  • Response:
    {
      "message": "Record added successfully"
    }

Security Considerations

  • Ensure JWT_SECRET and DB_PASSWORD are stored in environment variables
  • Implement rate limiting to prevent abuse
  • Sanitize user input to prevent SQL injection
  • Hash passwords using bcrypt

Future Enhancements

  • Implement role-based access control
  • Introduce logging and monitoring
  • Optimize query performance
  • Enhance caching mechanisms

Author

Caolán Maguire - Final Year Project (Back Seat Driver)

About

Repository for backend server for digisafe project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors