Git Product home page Git Product logo

beacon-backend's Introduction

CCExtractor Beacon back-end

This is the backend for the Beacon app. It is written in GraphQL using Apollo and has realtime subscriptions to share user locations with one another. A MongoDB Atlas cluster is used for databasing.

Live URL's (possibly outdated)

  • https://beacon.aadibajpai.com: standalone version for development and testing;
  • https://agw4au70ek.execute-api.us-east-1.amazonaws.com/dev/ for production use

Deployment

Set up MongoDB

Through cloud.mongodb.com you can set up a (free) instance of MongoDB to store all data.

While creating a database, make sure you do the following things:

  • Write down the username/password combination after adding the user (through the quick-configuration).
  • Allow all IP's to access the database (use 0.0.0.0/0for this); FIXME (unsecure)

Once created, you can get the full URI by clicking "Connect", then select "Connect your application". The URI should look something like "mongodb+srv://:@.mongodb.net/?retryWrites=true&w=majority". This URI should be stored in the DB variable of your .env file.

Running on AWS Lambda (serverless)

# Install serverless and plugins needed
npm install -g serverless
serverless plugin install -n serverless-offline
# Copy the .env and update it accordingly
cp .env.example .env
nano .env
# Things you should have set up: DB (see above, "Set up MongoDB"), JWT_SECRET (random string)
# Run the install script
./script.sh "{acess key here}" "{secret key here}" {dev or prod here}

Running locally

  • clone the repo
  • copy .env.sample to .env and fill variables then run:
npm i
npm start

Old ramblings

master contains all the queries, mutations and subscriptions together for running on a standalone server. The aws branch has been modified to run the API on AWS Lambda which is a serverless platform so no resources are used while idle. This means subscriptions cannot be run since it is serverless, so we have another manager function that starts an ec2 instance while a beacon is active since that is only when subscriptions are necessary, and it pauses the ec2 instance when there is no beacon running. To communicate across Lambda and ec2, redis is used for the pub/sub mechanism.

for the ec2 instance, you would want to deploy the normal master branch to a server and set up a cron job or similar that would start the service when the instance is started after it was paused

beacon-backend's People

Contributors

aadeesh11 avatar aadibajpai avatar canihavesomecoffee avatar cfsmp3 avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

beacon-backend's Issues

Issue: Beacon Leader Field Returning Null in Group Query

Description:
The leader information of beacons is currently returning null when querying group details. This affects the accuracy of beacon details.
Screenshot 2024-02-08 at 12 36 04

Steps to Reproduce:

Query group details.
Check leader field within Beacon objects.
Observe null values instead of expected leader details.

Expected Behavior:
leader field in Beacon objects should contain the respective user details in group queries.

[Feature]: A well-defined architecture for codebase

Currently, the codebase is a bit unstructured, with all the errors, mutations, and queries in the same resolver file.

Solution proposed:
A well-defined architecture could be introduced, with rebased mutations and queries for different functionalities to be separated in different files with their respective usage and used individually and for a more readable codebase.

Detailed approach for implementation of N beacon 1 Group.

This issue (open for discussion!) describes the detailed implementation on how to update the backend for this feature.

Current roadmap (in-order):

  • Implement data model: Group data model should be added to be able to store it in MongoDB.
GroupModel = {  
	id, 
	shortcode //(can be used to join), 
	title //name, 
	[followers id] //list, 
	leader id //super leader (who created the group, with ability to delete the grp (TBD), 
	[beacon ids] //list.
}
  • Update existing models,
    • Beacon model:
      • New field, grpID = id of the group belongs to.
      • Remove the followers list, since it is same as group's followers list. (TBD)
      • Remove shortcode, since joining the group is sufficient for joining the beacon. (TBD)
      • leader is not same as the group’s leader. Here leader is the one who created it, which can later be changed using changeLeader() mutation.
    • User Model:
      • New field, groups = [ids of all the groups the user is a part of].
  • New mutations for creating, joining and fetching a group (changes to be done is resolvers and typedefs).
    • createAGroup() , fairly straightforward, creating a new group with all the fields and saving it in the DB.
    • joinAGroup(shortcode), Add the new member to all the beacons in the group, also use pubsub to publish this change.
    • getGroupDetails() (small thing to be taken care of is populating the necessary fields before returning).
    • nearby groups, what is a “group’s location”? (TBD).
  • Update the existing mutations, queries and subscriptions to incorporate group model.
    • Update me query.
    • Update createBeacon() and joinBeacon() mutations.
    • Change beaconJoined() subscription to groupJoined(), since the followers list is same for all the beacons in the group.
💡 Open for further discussion!

(TBD = To be discussed)

Leader's name in nearby beacons is returned as null

Upon querying the beacon for the leader's name under nearby beacons, we get a null value which results in the leader being shown as anonymous on the app.

Upon terminating the hike and coming back to the home screen, my own beacon is shown as Anonymous. This is because nearbyBeacons query in the backend gives out null as the leader's name.

This would help in fixing issue CCExtractor/beacon/issues/35

One subscription for all beacon changes.

I mean will this sync the updates for all and stop the subscriptions if beacon has been deactivated?
Originally posted by @nb9960 in CCExtractor/beacon#97 (comment)

As the beacon is subject to lot of changes, having multiple subscriptions can be inefficient. To allow users to subscribe to beacon updates(modifying leader, start/end time etc) and location updates(all users of the beacon), a single stream can be used to achieve this. This will require to change the beacon model.

This issue is open to further discussion, to choose the best way to implement it.

Are yo working on it?
Yes

Enabling real-time loading of beacons

Description:

Currently, the beacons do not load in real-time, impacting the user experience. To address this, we need to implement improvements that ensure instantaneous loading of beacons for a smoother interaction.

Host Error

There seems to be no server for hosting queries or subscriptions for the app. The link to GraphQL playground shows an error.
This causes the app to be unable to do the required tasks. @aadibajpai Is this problem noticed by you already?

Add facebook and google oauth (backend)

Front end issue - CCExtractor/beacon#160
Currently, the app only accepts email sign in/signup. Having oauth would be better for the user, then user can sign in with ease.
Also there is PR for email verification, having oauth wont even need email verification. (Although that feature would be required for user sign in with their email).

Unsure error messages

Some error messages being thrown do not represent the particular type of error they are pointing to. We could change some wordings to make them better!

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.