Code Monkey home page Code Monkey logo

credit-card-luhn-validation's Introduction

credit-card-luhn-validation

License

Description

credit-card-luhn-validation is a comprehensive web application developed in response to the challenge set by Project Broadcast. The primary objective was to craft a fully responsive website where a user is able to enter a credit card number into a React based UI where the validation logic is handled by an express powered api, providing users with a dynamic and user-friendly experience.

This project was bundled with create-turbo.

Frontend deployed by Vercel Backend deployed by Render

Table of Contents

Demo

You can see a live demo of credit-card-luhn-validation here!.

Frontend Project Structure

  • src/app code base for app;
  • src/components components isolated with their styling;
  • src/components/ui shadcn components to use;
  • src/context context for flobal state management;
  • src/hooks hook for handling snackbar data state;
  • src/mocks mocks credit card;
  • src/models credit card model;
  • src/services cardServices for async operations;
  • src/utils utils cn file;
  • src/utils/validators validators used;
  • src/utils/masks masks used;

Backend Project Structure

  • src/__tests__ tests for app routes;
  • src/controllers controller class to handle route actions;
  • src/middlewares middleware used on validation route;
  • src/schemas schema used by Mongoose to create the Card Model;
  • src/routes.ts exports all the project used routes;
  • src/utils logger and luhn's validation function;
  • src/app.ts app class initializing middlewares, database and routes;
  • src/index.ts starts the server;

Features

  • Responsive Design: Implemented a fully responsive layout.

  • 3D Animated Card: card was animated with pure css using preserve 3D.

  • Card Validation: Express powered api routes that validates provided credit card using luhn alghorithm.

  • Card List Database: Implemented database that can save and delete accepted cards.

Stack

Getting Started

Installation

  1. Clone the repository:

    git clone https://github.com/guiduck/credit-card-luhn-validation.git
  2. Install dependencies:

    npm install
  3. Run the development server:

    npm run dev

    Frontend Environment Variables

  4. Create a .env File:

    • Create a file named .env.local(or .env.production for production environment) in your project's root folder.
  5. Define Environment Variables:

    • In the .env.[environment] file, define your environment variables in the following format:

      VARIABLE_NAME=variable_value
      

    Replace VARIABLE_NAME with the name of your variable and variable_value with the actual value you want to set.

  6. Example:

    • local:
    VITE_API_URL=http://localhost:5001/
    
    • production:
    VITE_API_URL=https://credit-card-luhn-validation.onrender.com/   
    

    Backend Environment Variables

    Create a .env File:

    • Create a file named .env in your project's root folder.

    • In the .env file, define your environment variables:

     PORT=5001
     DB_URL=mongodb+srv://guiduck02:[email protected]/?retryWrites=true&w=majority
    

API Documentation

Validation

  • The endoint "api/cards" is used to create(if validation is successful), list and delete the cards.

Endpoints

  • validate and create
    • POST /api/cards
      • Payload
         {
             "holder": string,
             "creditCardNumber": string,
             "expires": string,
             "cvc": string
         }
      • Success Response
         {
             success: boolean,
             data: card object,
             message: string,
         }
      • Error Response
         {
             error: string,
         }
  • list cards
    • GET /api/cards
      • Success Response
         { 
            data: [cards object]
         }
      • Error Response
         { 
            error: string
         }
  • delete cards
    • DELETE /api/cards
      • Success Response
         {
            success: boolean,
            message: string
         }
      • Error Response
         { 
            error: string
         }

Usage

Visit http://localhost:3001 to explore the application. Type in the credit card input, interact with the card animation, and experience the real-time data updates through the database.

Visit http://localhost:5001 to explore the backend api.

Future improvements

While developing checkout page, I am primarly focused on enhancing user experience and functionality:

  • UI: the ui was designed very carefully, but while developing I had many ideas and little time to explore.

  • Input Validation: All frontend validations are being handled manually, it would be preferable to use a lib(react-hook-form or formik).

License

This project is licensed under the MIT License - see the LICENSE file for details.

credit-card-luhn-validation's People

Contributors

turbobot-temp avatar

Watchers

guilherme figueiredo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.