Blind Enhancement and Assistive Cap with Optical Navigation
BEACON is a companion system designed to support visually impaired individuals by working in tandem with a smart wearable cap. The cap is equipped with a camera module (ESP32-CAM) that performs real-time object detection, crosswalk recognition, currency identification, and proximity alerts β all powered by AI models running on a separate camera service.
This repository contains the backend API server β the central nervous system that ties the entire BEACON ecosystem together. It handles:
- π User authentication & management β Registration, login, and JWT-secured sessions
- π Emergency alerting β Automated fall detection emails and manual SOS alerts sent to emergency contacts with Google Maps location links
- π Emergency contact management β Full CRUD with priority ordering for contacts who receive alerts
- π Task scheduling β Repeatable and one-time task reminders with trigger tracking to help users manage daily routines
- π¨ Message queues β Bi-directional message relay between the camera module and the mobile app, enabling real-time data transmission
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β BEACON Cap β β BEACON Backend β β BEACON Mobile β
β (ESP32-CAM + ββββββΊβ (This Repo) ββββββΊβ (Expo App) β
β AI Service) β β β β β
β β β ββββββββββββββ β β β’ Voice UI β
β β’ Object Det. β β β Fastify β β β β’ Navigation β
β β’ Crosswalk β β β REST API β β β β’ Task Mgmt β
β β’ Currency β β ββββββββββββββ€ β β β’ SOS Trigger β
β β’ Proximity β β β PostgreSQL β β β β
β β β β (Prisma) β β β β
β β β ββββββββββββββ€ β β β
β β β β Nodemailer β β β β
β β β β (Alerts) β β β β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
The backend acts as the bridge between the smart cap and the mobile application. The camera service pushes detection results into message queues via the API, and the mobile app consumes them to deliver voice-guided audio feedback to the user.
| Layer | Technology |
|---|---|
| Runtime | Node.js with TypeScript |
| Framework | Fastify v5 β high-performance HTTP server |
| ORM | Prisma v7 β type-safe database client |
| Database | PostgreSQL |
| Auth | JWT (jsonwebtoken) + bcrypt password hashing |
| Nodemailer (Gmail SMTP) β HTML-styled emergency alerts | |
| Docs | Swagger / OpenAPI 3.0 with Swagger UI (/docs) |
| Logging | Pino with pino-pretty transport |
| Code Quality | ESLint + Prettier + Husky pre-commit hooks + lint-staged |
| Build | tsx (dev) / tsc (production) |
All endpoints except public routes require a Bearer JWT token in the Authorization header.
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /auth/register |
Register a new user | β |
| POST | /auth/login |
Login and receive a JWT token | β |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /emergency |
Send a generic emergency email with location | β |
| POST | /emergency/alerts/fall |
Send fall-detection alert to primary emergency contact | β |
| POST | /emergency/alerts/manual |
Manually trigger an SOS alert with GPS coordinates | β |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /emergency-contact |
Create a new emergency contact | β |
| GET | /emergency-contact/:id |
Get a specific emergency contact | β |
| GET | /emergency-contact/list |
List contacts with pagination | β |
| PATCH | /emergency-contact/:id |
Update an emergency contact | β |
| DELETE | /emergency-contact/:id |
Delete an emergency contact | β |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /tasks |
Create a new task (one-time or recurring) | β |
| GET | /tasks |
List all tasks for the authenticated user | β |
| GET | /tasks/due |
Fetch tasks due at the current time | β |
| PATCH | /tasks/:id |
Toggle task active/inactive status | β |
| POST | /tasks/trigger/:id |
Mark a task as triggered (update lastTriggered) | β |
| DELETE | /tasks/:id |
Delete a task | β |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /message-queues |
Create a new message in the queue | β |
| POST | /message-queues/public |
Create a message (public β used by cam service) | β |
| GET | /message-queues |
List all messages for the authenticated user | β |
| DELETE | /message-queues/:id |
Delete a message from the queue | β |
π Interactive API docs are available at
http://localhost:8080/docswhen the server is running.
ββββββββββββββββ βββββββββββββββββββββββ
β Users βββββ<β EmergencyContacts β
β β β β
β id (cuid) β β id, userId, name β
β email β β email, mobileNo β
β name β β position (priority)β
β password β β createdAt β
β createdAt β βββββββββββββββββββββββ
β β
β βββββ<βββββββββββββββββββββββ
β β β Tasks β
β β β β
β β β id, userId, name β
β β β scheduledTime β
β β β specificDate β
β β β isActive β
β β β isRepeating β
β β β repeatDays[] β
β β β lastTriggered β
β β βββββββββββββββββββββββ
β β
β βββββ<βββββββββββββββββββββββ
β β β MessageQueue β
β β β β
β β β id, userId β
β β β message β
ββββββββββββββββ βββββββββββββββββββββββ
All relationships cascade on delete β removing a user automatically cleans up their contacts, tasks, and messages.
- Node.js β₯ 18
- PostgreSQL database
- Gmail account with an App Password for email alerts
git clone https://github.com/SabarishAV/beacon-backend.git
cd beacon-backendnpm installCopy the example env file and fill in your values:
cp .env.example .envPORT=8080
DATABASE_URL=postgresql://user:password@localhost:5432/beacon
EMAIL_USERNAME=your-email@gmail.com
EMAIL_APP_PASSWORD=your-gmail-app-password
JWT_SECRET=your-secret-key# Generate Prisma client
npm run prisma:generate
# Run database migrations
npm run prisma:migratenpm run devThe server will start at http://localhost:8080 with hot-reload enabled.
| Script | Description |
|---|---|
npm run dev |
Start dev server with hot-reload (tsx watch) |
npm run build |
Compile TypeScript to JavaScript |
npm run lint |
Run ESLint on all source files |
npm run lint:fix |
Run ESLint with auto-fix |
npm run format |
Format all source files with Prettier |
npm run prisma:generate |
Generate Prisma client from schema |
npm run prisma:studio |
Open Prisma Studio (visual DB editor) |
npm run prisma:migrate |
Run pending database migrations |
npm run prisma:reset |
Reset database and re-run all migrations |
npm run seed:up |
Run database seeders |
npm run seed:down |
Reverse database seeders |
beacon_backend/
βββ prisma/
β βββ schema.prisma # Database schema definition
β βββ migrations/ # SQL migration files
β βββ seeders/ # Database seed scripts
β βββ up.ts
β βββ down.ts
βββ src/
β βββ server.ts # Application entry point
β βββ config/
β β βββ logger.ts # Pino logger configuration
β β βββ prisma.ts # Prisma client singleton
β β βββ swagger.ts # Swagger/OpenAPI setup
β βββ constants/
β β βββ bcrypt.ts # Salt rounds configuration
β β βββ route.ts # Public routes whitelist
β βββ controllers/
β β βββ auth-controller.ts
β β βββ emergency-controller.ts
β β βββ emergency-contact-controllers.ts
β β βββ message-queue-controller.ts
β β βββ tasks-controller.ts
β βββ middlewares/
β β βββ error.ts # Global error handler (Prisma + custom errors)
β β βββ jwt.ts # JWT authentication pre-handler
β βββ repository/
β β βββ user-repository.ts
β β βββ emergency-contact-repository.ts
β β βββ message-queue-repository.ts
β β βββ tasks-repository.ts
β βββ routes/
β β βββ auth-route.ts
β β βββ emergency-route.ts
β β βββ emergency-contact-routes.ts
β β βββ message-queue-route.ts
β β βββ task-route.ts
β βββ utils/
β βββ date.ts # Date formatting helpers
β βββ jwt.ts # JWT sign/verify utilities
β βββ mail.ts # Email templates (fall alert, SOS)
β βββ pagination.ts # Pagination helper
β βββ time.ts # Time utilities
β βββ errors/ # Custom error classes
β β βββ AppError.ts
β β βββ BadRequestError.ts
β β βββ ForbiddenError.ts
β β βββ NotFoundError.ts
β β βββ ValidationError.ts
β βββ swagger-schemas/ # OpenAPI schema definitions
βββ .env.example # Environment variable template
βββ .prettierrc # Prettier configuration
βββ eslint.config.mjs # ESLint configuration
βββ tsconfig.json # TypeScript configuration
βββ tsup.config.ts # tsup bundler configuration
βββ package.json
| Repository | Description |
|---|---|
| beacon-mobile | React Native (Expo) mobile application β voice UI, navigation, task manager |
| beacon-camera | Python AI service β object detection, crosswalk & currency recognition |
MIT
Built with β€οΈ for accessibility