Skip to content

Harshini2410/AllyNet-full

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AllyNet - Community Safety Platform

AllyNet is a production-grade, safety-first community platform that connects neighbors in need with verified helpers in real-time. The platform combines emergency SOS capabilities with community assistance features, all built on a foundation of trust and verified interactions.


πŸ“‹ Table of Contents


🎯 Overview

AllyNet is a full-stack application designed to enhance community safety through:

  1. Emergency SOS System: Real-time location-based emergency alerts with instant notification to nearby verified helpers
  2. Community Help Marketplace: Non-urgent peer-to-peer assistance platform (moving, tech support, tutoring, etc.)
  3. Trust & Verification: Comprehensive trust score system that rewards helpful behavior and maintains community safety
  4. Safety Features: Emergency contacts with SMS notifications, safety settings, and reporting mechanisms

✨ Key Features

Emergency SOS

  • Real-Time Alerts: Instant location-based emergency notifications
  • Multiple Emergency Types: Medical, safety, accident, assault, natural disaster, and more
  • Privacy Options: Silent mode, anonymous mode, and fake call alerts
  • Helper Coordination: Real-time chat, status updates, and location sharing
  • Emergency History: Complete history of SOS requested and SOS helped

Community Help Requests

  • Create Help Requests: Post non-urgent assistance requests with location
  • Helper Responses: Verified helpers can respond with messages
  • Conversation Threads: Full messaging system for creator-helper communication
  • Accept/Deny/Report: Creator can accept, deny, or report helper responses
  • Response Management: View all requests and responses in one place

Trust Score System

  • Dynamic Scoring: Trust score ranges from 0-1000
  • Score Increases:
    • +10 points: When helper's response to help request is accepted
    • +50 points: When helper accepts/responds to an SOS emergency
    • +50 points: When helper resolves an SOS emergency
  • Score Decreases:
    • -50 points: When helper is reported by a creator
  • Profile Stats: Track helped, requested, SOS alerts, and reports

User Profile & Settings

  • Comprehensive Profile: Trust score, stats, and activity history
  • Emergency Contacts: Add/delete emergency contacts for SMS notifications
  • Safety Settings: Manage emergency contacts and safety preferences
  • Help Center: Submit questions, complaints, bug reports, and feature requests
  • Emergency History: Detailed view of all SOS interactions

Marketplace & Discovery

  • Location-Based Discovery: Find nearby help requests and emergencies
  • Ad System: Create and view marketplace advertisements
  • Nearby Ads Preview: Discover local services and offerings

πŸ›  Technology Stack

Backend

  • Runtime: Node.js (>=18.0.0)
  • Framework: Express.js
  • Database: MongoDB with Mongoose ODM
  • Authentication: JWT (JSON Web Tokens) with refresh token support
  • Real-Time: Socket.IO for real-time communication
  • Validation: express-validator
  • Security: bcryptjs for password hashing
  • Other: dotenv, cors, uuid

Frontend

  • Framework: React 19.2.0
  • Build Tool: Vite 7.2.4
  • Routing: React Router DOM 7.11.0
  • State Management: Zustand 5.0.9
  • Styling: Tailwind CSS 4.1.18
  • Animations: Framer Motion 12.23.26
  • Icons: Lucide React 0.562.0
  • Real-Time: Socket.IO Client 4.8.1
  • Utilities: clsx, tailwind-merge

πŸ“ Project Structure

AllyNet-full/
β”œβ”€β”€ AllyNet-back/                 # Backend API Server
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/              # Configuration files
β”‚   β”‚   β”‚   └── database.js      # MongoDB connection
β”‚   β”‚   β”œβ”€β”€ controllers/         # Request handlers
β”‚   β”‚   β”‚   β”œβ”€β”€ authController.js
β”‚   β”‚   β”‚   β”œβ”€β”€ emergencyController.js
β”‚   β”‚   β”‚   β”œβ”€β”€ helpRequestController.js
β”‚   β”‚   β”‚   β”œβ”€β”€ messageController.js
β”‚   β”‚   β”‚   β”œβ”€β”€ adController.js
β”‚   β”‚   β”‚   └── contactController.js
β”‚   β”‚   β”œβ”€β”€ models/              # Mongoose schemas
β”‚   β”‚   β”‚   β”œβ”€β”€ User.js
β”‚   β”‚   β”‚   β”œβ”€β”€ Emergency.js
β”‚   β”‚   β”‚   β”œβ”€β”€ HelpRequest.js
β”‚   β”‚   β”‚   β”œβ”€β”€ EmergencyMessage.js
β”‚   β”‚   β”‚   β”œβ”€β”€ Ad.js
β”‚   β”‚   β”‚   β”œβ”€β”€ Contact.js
β”‚   β”‚   β”‚   └── index.js
β”‚   β”‚   β”œβ”€β”€ routes/              # Express routes
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   β”‚   β”œβ”€β”€ emergency.js
β”‚   β”‚   β”‚   β”œβ”€β”€ helpRequest.js
β”‚   β”‚   β”‚   β”œβ”€β”€ health.js
β”‚   β”‚   β”‚   β”œβ”€β”€ ad.js
β”‚   β”‚   β”‚   └── contact.js
β”‚   β”‚   β”œβ”€β”€ services/            # Business logic layer
β”‚   β”‚   β”‚   β”œβ”€β”€ emergencyService.js
β”‚   β”‚   β”‚   β”œβ”€β”€ helpRequestService.js
β”‚   β”‚   β”‚   β”œβ”€β”€ messageService.js
β”‚   β”‚   β”‚   β”œβ”€β”€ adService.js
β”‚   β”‚   β”‚   └── contactService.js
β”‚   β”‚   β”œβ”€β”€ middleware/          # Custom middleware
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.js          # JWT authentication
β”‚   β”‚   β”‚   └── errorHandler.js  # Global error handler
β”‚   β”‚   β”œβ”€β”€ sockets/             # Socket.IO handlers
β”‚   β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”‚   β”œβ”€β”€ emergencySocket.js
β”‚   β”‚   β”‚   └── socketAuth.js
β”‚   β”‚   β”œβ”€β”€ utils/               # Utility functions
β”‚   β”‚   β”‚   β”œβ”€β”€ jwt.js
β”‚   β”‚   β”‚   β”œβ”€β”€ asyncHandler.js
β”‚   β”‚   β”‚   β”œβ”€β”€ messageSerializer.js
β”‚   β”‚   β”‚   └── smsService.js
β”‚   β”‚   β”œβ”€β”€ app.js               # Express app setup
β”‚   β”‚   └── server.js            # Server bootstrap
β”‚   β”œβ”€β”€ scripts/                 # Utility scripts
β”‚   β”‚   └── cleanup-stale-emergencies.js
β”‚   └── package.json
β”‚
β”œβ”€β”€ AllyNet-front/               # Frontend React Application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ api/                 # API client functions
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   β”‚   β”œβ”€β”€ emergency.js
β”‚   β”‚   β”‚   β”œβ”€β”€ helpRequest.js
β”‚   β”‚   β”‚   β”œβ”€β”€ socket.js
β”‚   β”‚   β”‚   β”œβ”€β”€ ad.js
β”‚   β”‚   β”‚   └── contact.js
β”‚   β”‚   β”œβ”€β”€ components/          # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ Button.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Card.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ BottomNav.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ProtectedRoute.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ThemeToggle.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ EmergencyNotification.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ EmergencyEndedNotification.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ EmergencyMapModal.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ FakeCallAlert.jsx
β”‚   β”‚   β”‚   └── NearbyAdsPreview.jsx
β”‚   β”‚   β”œβ”€β”€ features/            # Feature-based components
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ SignupPage.jsx
β”‚   β”‚   β”‚   β”‚   └── Onboarding.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ emergency/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ SOSOverlay.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ EmergencyActiveView.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ EmergencyChat.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ EmergencyDetails.jsx
β”‚   β”‚   β”‚   β”‚   └── EmergencyChatHistory.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ help/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ CreateHelpRequest.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ HelpFeed.jsx
β”‚   β”‚   β”‚   β”‚   └── HelpRequestsPage.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ profile/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ProfilePage.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ProfileView.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ EmergencyHistory.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ SafetySettings.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ HelpCenter.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ TrustScoreRing.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ OrganizationView.jsx
β”‚   β”‚   β”‚   β”‚   └── PaymentsView.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ marketplace/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DiscoveryView.jsx
β”‚   β”‚   β”‚   β”‚   └── CreateAdForm.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ads/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AdDetailView.jsx
β”‚   β”‚   β”‚   β”‚   └── AdHistory.jsx
β”‚   β”‚   β”‚   └── about/
β”‚   β”‚   β”‚       └── AboutAllyNet.jsx
β”‚   β”‚   β”œβ”€β”€ hooks/               # Custom React hooks
β”‚   β”‚   β”‚   └── useEmergencySocket.js
β”‚   β”‚   β”œβ”€β”€ layouts/             # Layout components
β”‚   β”‚   β”‚   └── AppShell.jsx
β”‚   β”‚   β”œβ”€β”€ store/               # Zustand state stores
β”‚   β”‚   β”‚   β”œβ”€β”€ useAuthStore.js
β”‚   β”‚   β”‚   β”œβ”€β”€ useEmergencyStore.js
β”‚   β”‚   β”‚   β”œβ”€β”€ useEmergencySessionStore.js
β”‚   β”‚   β”‚   β”œβ”€β”€ useHelpStore.js
β”‚   β”‚   β”‚   β”œβ”€β”€ useMarketplaceStore.js
β”‚   β”‚   β”‚   β”œβ”€β”€ useTabStore.js
β”‚   β”‚   β”‚   └── useThemeStore.js
β”‚   β”‚   β”œβ”€β”€ App.jsx              # Main app component
β”‚   β”‚   β”œβ”€β”€ main.jsx             # React entry point
β”‚   β”‚   β”œβ”€β”€ index.css            # Global styles
β”‚   β”‚   └── utils.js             # Utility functions
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── favicon.svg
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ vite.config.js
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   └── package.json
β”‚
└── README.md                    # This file

πŸš€ Getting Started

Prerequisites

  • Node.js: >= 18.0.0
  • MongoDB: Local installation or MongoDB Atlas account
  • npm or yarn: Package manager

Backend Setup

  1. Navigate to backend directory:

    cd AllyNet-back
  2. Install dependencies:

    npm install
  3. Create environment file: Create a .env file in the AllyNet-back directory:

    NODE_ENV=development
    PORT=5000
    MONGODB_URI=mongodb://localhost:27017/allynet
    JWT_SECRET=your-super-secret-jwt-key-change-in-production
    JWT_REFRESH_SECRET=your-super-secret-refresh-key-change-in-production
    JWT_EXPIRE=1d
    JWT_REFRESH_EXPIRE=7d
    FRONTEND_URL=http://localhost:5173
  4. Start MongoDB (if running locally):

    # Make sure MongoDB is running on localhost:27017
    # Or update MONGODB_URI in .env to point to your MongoDB instance
  5. Run the server:

    # Development mode (with hot reload)
    npm run dev
    
    # Production mode
    npm start
  6. Verify backend is running:

    curl http://localhost:5000/api/health

Frontend Setup

  1. Navigate to frontend directory:

    cd AllyNet-front
  2. Install dependencies:

    npm install
  3. Configure API base URL (if needed): Update the API base URL in src/api/*.js files if your backend runs on a different port.

  4. Run the development server:

    npm run dev
  5. Build for production:

    npm run build
  6. Preview production build:

    npm run preview

The frontend will be available at http://localhost:5173 (or the next available port).


πŸ”§ Environment Variables

Backend (.env)

Variable Description Default Required
NODE_ENV Environment (development/production) development No
PORT Server port 5000 No
MONGODB_URI MongoDB connection string - Yes
JWT_SECRET Secret key for access tokens - Yes
JWT_REFRESH_SECRET Secret key for refresh tokens - Yes
JWT_EXPIRE Access token expiration 1d No
JWT_REFRESH_EXPIRE Refresh token expiration 7d No
FRONTEND_URL Frontend URL for CORS http://localhost:5173 No

Security Note: Never commit .env files to version control. Use strong, unique secrets in production.


πŸ“‘ API Documentation

Base URL

http://localhost:5000/api/v1

Authentication Endpoints

Register User

POST /auth/register
Body: { email, password, name (or firstName, lastName), phone?, location? }
Response: { success, data: { user, tokens } }

Login

POST /auth/login
Body: { email, password }
Response: { success, data: { user, tokens } }

Get Current User

GET /auth/me
Headers: { Authorization: "Bearer <access_token>" }
Response: { success, data: { user } }

Get User Stats

GET /auth/stats
Headers: { Authorization: "Bearer <access_token>" }
Response: { success, data: { trustScore, helped, requested, sosAlerts, reports } }

Emergency Contacts

GET /auth/emergency-contacts
POST /auth/emergency-contacts (Body: { name, phone })
DELETE /auth/emergency-contacts/:contactId

Emergency Endpoints

Create Emergency (SOS)

POST /emergencies
Body: {
  location: { latitude, longitude },
  type?: string,
  description?: string,
  silentMode?: boolean,
  anonymousMode?: boolean,
  fakeCallAlert?: boolean
}
Response: { success, data: { emergency } }

Get Active Emergency

GET /emergencies/active
Response: { success, data: { emergency } }

Get Nearby Emergencies

GET /emergencies/nearby?latitude=...&longitude=...&radius=...
Response: { success, data: { emergencies } }

Respond to Emergency

POST /emergencies/:id/respond
Body: { estimatedArrival?: Date }
Response: { success, data: { emergency } }

Resolve Emergency

POST /emergencies/:id/resolve
Body: { resolutionType?: string, notes?: string }
Response: { success, data: { emergency } }

Help Request Endpoints

Create Help Request

POST /help-requests
Body: {
  title, description, category, location: { latitude, longitude },
  urgency, estimatedDuration?, budget?
}
Response: { success, data: { helpRequest } }

Get User's Help Requests

GET /help-requests/my
Response: { success, data: { helpRequests } }

Get Nearby Help Requests

GET /help-requests/nearby?latitude=...&longitude=...&radius=...
Response: { success, data: { helpRequests } }

Respond to Help Request

POST /help-requests/:id/respond
Body: { message }
Response: { success, data: { helpRequest } }

Accept/Deny/Report Helper Response

POST /help-requests/:id/responses/:helperId/accept
POST /help-requests/:id/responses/:helperId/deny
POST /help-requests/:id/responses/:helperId/report
Body (for report): { reason: string }
Response: { success, data: { helpRequest } }

Reply to Response

POST /help-requests/:id/responses/:helperId/reply
Body: { message }
Response: { success, data: { helpRequest } }

Contact Endpoints

Submit Contact Form

POST /contact
Body: { category, subject, message }
Response: { success, message }

πŸŽ– Trust Score System

The trust score is a numerical representation of a user's reliability and helpfulness in the community, ranging from 0 to 1000.

Score Increases

Action Points Description
Help Request Accepted +10 When a creator accepts a helper's response to their help request
SOS Response +50 When a helper accepts/responds to an SOS emergency
SOS Resolution +50 When a helper resolves an SOS emergency (additional to response points)

Score Decreases

Action Points Description
Reported -50 When a helper is reported by a creator (minimum score: 0)

Profile Statistics

Users can view their statistics on their profile:

  • Trust Score: Current trust score (0-1000)
  • Helped: Number of help requests where user's response was accepted
  • Requested: Number of help requests created by user
  • SOS Alerts: Number of emergencies created by user
  • Reports: Number of times user was reported

πŸ”’ Security Features

Authentication & Authorization

  • JWT-based Authentication: Secure token-based authentication
  • Refresh Tokens: Long-lived refresh tokens with short-lived access tokens
  • Password Hashing: bcrypt with 12 salt rounds
  • Protected Routes: Middleware protection on all private endpoints

Data Security

  • Input Validation: express-validator on all endpoints
  • CORS Configuration: Restrictive CORS policies
  • Environment Variables: Sensitive data stored in environment variables
  • SQL Injection Prevention: Mongoose ODM provides built-in protection

User Privacy

  • Anonymous Mode: Users can create emergencies anonymously
  • Silent Mode: Silent emergency notifications
  • Location Privacy: Location only shared during active emergencies
  • Fake Call Alert: Disguised emergency interface

πŸ”΄ Real-Time Features

Socket.IO Integration

AllyNet uses Socket.IO for real-time communication, particularly for emergency events.

Namespace

/emergencies

Events

Client β†’ Server:

  • emergency:join - Join an emergency room
  • emergency:leave - Leave an emergency room
  • message:send - Send a message in emergency chat

Server β†’ Client:

  • emergency:created - New emergency created nearby
  • helper:joined - Helper joined emergency
  • emergency:status_changed - Emergency status updated
  • emergency:resolved - Emergency resolved
  • message:received - New message in emergency chat

Authentication

Socket connections are authenticated using JWT tokens sent during connection.


🚒 Deployment

Backend Deployment

  1. Set environment variables on your hosting platform (Heroku, AWS, DigitalOcean, etc.)
  2. Build command: Not required (Node.js application)
  3. Start command: npm start
  4. Port: Use the PORT environment variable (most platforms set this automatically)

Frontend Deployment

  1. Build the application:

    cd AllyNet-front
    npm run build
  2. Deploy the dist folder to your static hosting service:

    • Vercel
    • Netlify
    • AWS S3 + CloudFront
    • GitHub Pages
    • Any static file server
  3. Configure API base URL: Update API endpoints in src/api/*.js to point to your production backend URL.

Production Checklist

  • Set NODE_ENV=production
  • Use strong, unique JWT secrets
  • Configure MongoDB Atlas or production MongoDB instance
  • Set up CORS to allow only your frontend domain
  • Enable HTTPS/SSL
  • Set up error monitoring (e.g., Sentry)
  • Configure backup strategy for MongoDB
  • Set up SMS service (Twilio) for emergency contacts
  • Test all critical features
  • Set up logging and monitoring

πŸ‘¨β€πŸ’» Development

Backend Development

  • Hot Reload: Use npm run dev (nodemon)
  • Health Check: GET /api/health
  • Error Handling: Global error handler in src/middleware/errorHandler.js
  • Logging: Console logging (consider adding Winston or similar in production)

Frontend Development

  • Hot Module Replacement: Vite provides instant HMR
  • Linting: npm run lint
  • Build: npm run build
  • Preview: npm run preview (preview production build locally)

Code Structure

  • Backend: Follows MVC pattern with services layer for business logic
  • Frontend: Feature-based organization with shared components
  • State Management: Zustand for global state, local state for component-specific data
  • Styling: Tailwind CSS utility classes with custom theme configuration

πŸ“ Notes

SMS Integration

The smsService.js utility contains placeholder code for sending SMS notifications. To enable SMS functionality:

  1. Sign up for Twilio (or another SMS service)
  2. Add credentials to environment variables
  3. Implement the sendEmergencySMS function in AllyNet-back/src/utils/smsService.js

MongoDB Indexes

The application uses MongoDB indexes for:

  • User email (unique)
  • User location (2dsphere for geospatial queries)
  • Emergency location (2dsphere)
  • Help request location (2dsphere)
  • Various query optimizations

Performance Considerations

  • Geospatial queries are indexed for fast location-based searches
  • Socket.IO rooms are used to minimize broadcast traffic
  • Aggregation pipelines are used for complex statistics queries
  • Trust score calculations are optimized with proper indexing

🀝 Contributing

This is a production application. When making changes:

  1. Test thoroughly in development
  2. Ensure all environment variables are documented
  3. Update this README if adding new features
  4. Follow existing code patterns and structure
  5. Test API endpoints and frontend components

πŸ“„ License

This project is proprietary. All rights reserved.


πŸ†˜ Support

For issues, questions, or feature requests:

  1. Use the Help Center feature in the application
  2. Contact the development team
  3. Review the About page in the application for more information

Status: 🟒 Production Ready

Last Updated: 2024

Version: 1.0.0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages