Skip to content

Latest commit

Β 

History

History
271 lines (194 loc) Β· 6.16 KB

README.md

File metadata and controls

271 lines (194 loc) Β· 6.16 KB

Design and Implementation of Security-Conscious, Location-Sharing in a Geosocial Network

Link to the Gist

Link to the Presentation

Link to the Thesis

Link to the reference research paper

Architecture

One Instance Architecture

Managing the MongoDB and Postgres

Scalable Architecture

Privacy Filtration Logic

Database Schema

Mongoose Schema

ERD

Prisma Schema

PostGIS Query

CREATE OR REPLACE FUNCTION nearby_privacy_entities(
    IN lat FLOAT,
    IN long FLOAT,
    IN d FLOAT,
    IN max_age FLOAT,
    IN college_param TEXT,
    IN gender_param TEXT,
    IN entity_type TEXT
)
RETURNS TABLE (
    id TEXT,
    name TEXT,
    email TEXT,
    age FLOAT,
    gender TEXT,
    college TEXT,
    isVisible BOOLEAN,
    lat FLOAT,
    long FLOAT,
    dist_meters FLOAT
)
LANGUAGE SQL
AS $$
    SELECT
        entity.id,
        entity.name,
        entity.email,
        entity.age,
        entity.gender,
        entity.college,
        entity."isVisible",
        latitude AS lat,
        longitude AS long,
        ST_DISTANCE(
            ST_GeomFromText('POINT(' || long || ' ' || lat || ')', 4326)::geography,
            ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography
        ) AS dist_meters
    FROM
        "Location"
    JOIN
        "User" entity ON "Location".id = entity."locationId"
    WHERE
        ST_DISTANCE(
            ST_GeomFromText('POINT(' || long || ' ' || lat || ')', 4326)::geography,
            ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography
        ) <= d AND entity_type = 'user'
        AND (college_param IS NULL OR entity.college = college_param)
        AND (gender_param IS NULL OR entity.gender = gender_param)
        AND (max_age IS NULL OR entity.age <= max_age)
    ORDER BY
        ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography <-> ST_GeomFromText('POINT(' || long || ' ' || lat || ')', 4326)::geography;
$$;

Privacy Network API Documentation

Privacy Network API Docs

OpenAPI Swagger API Docs

OpenAPI Swagger API Docs

OpenAPI Swagger Schemas

OpenAPI Swagger Schemas

Login Page

Dashboard Page

Map Page: Real-Time Location Updation

Map Page: Privacy Filtration

Map Page: Real-Time Location Sharing

Tech Stack

  • TypeScript
  • React with Google Maps API and Material UI
  • Node
  • Express
  • WebSockets
  • MongoDB
  • Postgres with PostGIS
  • Swagger

Setting up locally

The codebase is organized as :

  1. ts-frontend - The react frontend (default port 5173)
  2. backend/ts-backend - The primary express backend with mongoDB (default port 5050)
  3. backend/loc - The secondary express backend with Postgres (default port 6060)
  4. backend/ws - The websocket backend (default port 8080)
  • Clone the PrivacyNetwork repository
    git clone git@github.com:sanam2405/PrivacyNetwork.git
    cd PrivacyNetwork
  • Configure the .env of the four servers
// ts-frontend

VITE_BACKEND_URI=<BACKEND_API_URI: ts-backend server address>
VITE_WS_URI=<WEBSOCKET_URI: ws WebSocket server address>
VITE_GOOGLE_API_KEY=<GOOGLE_MAPS_API_KEY: API KEY for Google map>
// ts-backend

GOOGLE_CLIENT=<GOOGLE_CLIENT_ID: for logging in with Google>
GOOGLE_API_KEY=<GOOGLE_API_KEY: for logging in with Google>
MONGO_URI=<MONGO_URI: for mongoDB database connection>
SECRET_KEY=<CLIENT_SECRET: for generating/verifying the JWT token>
PORT=<PORT: at which the ts-backend server runs>
LOCATION_BACKEND_URI=<LOCATION_BACKEND_URI: for location querying req to loc server>
BACKEND_INTERCOMMUNICATION_SECRET=<BACKEND_INTERCOMMUNICATION_SECRET: for backend intercommunication>
// loc

DATABASE_URL=<DATABASE_URI: for connecting to the Postgres instance of Supabase>
DIRECT_URL=<DIRECT_URL: for connection direct connection to Postgres instance of Supabase via ORM Prisma for migrations>
BACKEND_INTERCOMMUNICATION_SECRET=<BACKEND_INTERCOMMUNICATION_SECRET: for backend intercommunication>
// ws

SECRET_KEY=<CLIENT_SECRET: verifying the JWT token>
TS_BACKEND_URI=<TS_BACKEND_URI: for user auth from ts-backend>
  • Database Seeding
// MongoDB Mock Data

backend/ts-backend/src/mockdata
└── MOCK_DATA.json

// Postgres Mock Data

backend/loc/src/mockdata
β”œβ”€β”€ Location.sql
└── User.sql
  • Run with docker (start all services with a single command)
    docker compose up
  • Run the frontend
    cd ts-frontend
    npm install
    npm run dev
  • Run the MongoDB backend
    cd backend/ts-backend
    npm install
    npm run dev
  • Run the Postgres backend
    cd backend/loc
    npm install
    npm run dev
  • Run the WebSocket backend
    cd backend/ws
    npm install
    npm run build
    npm start

Contributors

Mentor

  • Dr. Munmun Bhattacharya