Skip to content

ricmershon/kibbutz-16-api

Repository files navigation

Kibbutz-19 Server

An online community for people to find and share household and other necessities during the Covid-19 crisis.

Designer and Engineer

Ric Mershon

Background

Kibbutz-19 is a central resource for the finding and offering help during the Covid-19 crisis.

Accessing the Application

API: https://kibbutz-19-api.herokuapp.com/graphql

Client: https://kibbutz-19-client.herokuapp.com (Alternatively at kibbutz-19.com but unsecured)

Notable Features

Kibbutz-19 is built on a MERN model with GraphQL

API

  1. MongoDB database with a relatonal model to associte items with members. See Database Schemas section below.
  2. Backend developed with Express and Node.js frameworks.
  3. API built on GraphQL for lightweight queries integrated with MongoDB via Mongoose.
  4. Database deployed to AWS using MongoDB Atlas.
  5. Deployed to Heroku.

Client

  1. Responsive interface built with ReactJS and React Bootstrap.
  2. React Router with React Router Dom for easy interface navigation.
  3. GraphQL queries performed with Apollo Fetch.
  4. Chart.js for data charts.

Client repo and details can be found at https://github.com/ricmershon/kibbutz-16-client.

MongoDB Database Shemas

Member Shema

const memberSchema = new mongoose.Schema(
  {
    name: { type: String, required: true },
    email: { type: String, required: true },
    phone: { type: String, required: false },
    password: { type: String, required: false },
    contactMethod: {
      type: String,
      required: true,
      enum: ['text', 'email', 'phone'],
      default: 'text'
    },
    zipCode: { type: String, required: true }
  }
)

Item Schema

const itemSchema = new mongoose.Schema(
  {
    helpType: {
      type: String,
      required: true,
      enum: ['offering help', 'requesting help'],
      default: 'requesting help'
    },
    tag: {
      type: String,
      required: true,
      enum: [
        'Baby Supplies',
        'Business Support',
        'Food',
        'Supplies',
        'Toiletries',
        'Volunteer Work'
      ]
    },
    notes: String,
    quantity: Number,
    memberId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Member'
    }
  }
)

User Schema

const userSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
    trim: true
  },
  email: {
    type: String,
    required: true,
    unique: true,
    lowercase: true,
    validate: value => {
      if (!validator.isEmail(value)) {
          throw new Error({error: 'Invalid Email address'})
      }
    }
  },
  password: {
    type: String,
    required: true,
    minLength: 8
  },
  tokens: [{
    token: {
      type: String,
      required: true
    }
  }]
})

GraphQL Implementation

GraphQL is an open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data.

GraphQL resolvers are available for UserType and MemberType.

Resolvers for Queries

GraphQL queries perform read funtions.

Resolver Description
user returns a single user by ID
users returns all users
member returns a single member by ID
members returns all members

All of the items associated with a member can be returned with the following sample GraphQL query:

query {
  member(_id: "xxxx") {
    name
    email
    items {
      helpType
      tag
      notes
    }
  }
}

Resolvers for Mutations

GraphQL mutations peform create, update and delete functions.

Resolver Description
addMember adds a member to the DB
updateMember updates a member's information
deleteMember delete's a member's record from the DB
addItem adds an item to the DB
updateItem updates an item's information
deleteItem delete's an item's record from the DB

Mutation to create a member:

mutation {
  addMember(name: "Peter Parker" email: "spiderman@theavengers.com" phone: "6786406926" zipCode: "41234") {
    _id name email phone zipCode
  }
}

Technologies Used

  • Express - backend framework for Node.js.
  • MongoDB - a general purpose, document-based, distributed database. Database deployed to AWS (Amazon Web Services) using MongoDB Atlas.
  • MongoDB Atlas- a Cloud-hosted MongoDB service on Amazon Web Services.* Mongoose - MongoDB object modeling for Node.js.
  • dotenv - for loading environment variables from a .env file into process.env.
  • ReactJS - a JavaScript library for building user interfaces.
  • React Router - a collection of navigational components taht compose delaratively wiht a React application.
  • React Bootstrap - for a responsive, mobile-first layout.
  • GraphQL - an open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data.
  • Trello board - for project management.
  • Chart.js - a free open-source JavaScript library for data visualization

Future Development

  • User authentication with JSON Web Tokens.
  • React route for current Covid 19 News.
  • Flexible data requests on Data page.
  • Search capabilities.
  • Sidebar information.

About

API for community support page for COVID-19 pandemic

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published