Design and Implementation of Security-Conscious, Location-Sharing in a Geosocial Network
Link to the reference research paper
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;
$$;
- TypeScript
- React with Google Maps API and Material UI
- Node
- Express
- WebSockets
- MongoDB
- Postgres with PostGIS
- Swagger
The codebase is organized as :
- ts-frontend - The react frontend (default port 5173)
- backend/ts-backend - The primary express backend with mongoDB (default port 5050)
- backend/loc - The secondary express backend with Postgres (default port 6060)
- 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
Dr. Munmun Bhattacharya