How rudracoderr/feel_backend works
1. Overall shape
- This is a Node.js + Express REST API for the FEEL platform.
- The app is split into a classic three-layer backend shape: routes for HTTP handling, middleware for request gating, models for MongoDB persistence, and a small service layer for notifications.
2. Runtime and deployment boundary
- The API starts from server.js and listens on port 5000.
- It is intended for Railway deployment.
- Configuration is driven by environment variables, especially MONGO_URI and Firebase Admin credentials.
3. Persistence layer
- Data is stored in MongoDB Atlas through Mongoose.
- The main domain collections are represented by:
- usermodel.js
- report-model.js
- adoption-listing-model.js
- abuse-report-model.js
- notification-model.js
- audit-log-model.js
- ngo-model.js
- These models define the data boundary for users, rescue reports, adoption listings, abuse/moderation records, notifications, audit history, and NGO metadata.
4. External identity and messaging
- Firebase Admin SDK is the main external integration.
- It is used for:
- verifying Firebase ID tokens on protected routes
- supporting push/messaging workflows via the notification service
- The repo includes Firebase initialization/config files in Config/ and a root-level firebase-admin.js, which together indicate a centralized Firebase bootstrap path.
5. Security and access control
- Authentication is enforced by middleware in middleware/requireAuth.js.
- Authorization is split into:
- requireAdmin.js for admin-only operations
- requireActiveUser.js for blocking suspended/inactive users from sensitive actions
- This creates a clear security boundary between:
- public reads
- authenticated user actions
- privileged moderation/admin actions
6. HTTP API surface
- Routes are organized by domain:
- Routes/users-routes.js
- Routes/report-routes.js
- Routes/adoption-routes.js
- Routes/notification-routes.js
- Routes/admin-routes.js
- The API is mounted under /api, with public health/test endpoints outside or adjacent to the main API namespace.
7. Core user workflow: rescue reports
- The rescue-report subsystem is one of the main business flows.
- It supports:
- creating reports
- listing reports with optional radius filtering
- volunteers claiming/accepting reports
- updating progress and resolving/canceling work
- deleting reports
- filing abuse reports against a report
- This flow crosses multiple layers: user auth, report persistence, notification dispatch, and admin moderation.
8. Adoption workflow
- Adoption listings are handled as a separate domain from rescue reports.
- Users can create adoption listings, while the public can browse approved listings.
- Admin routes can approve, reject, or mark adoption listings as adopted, which suggests a moderation gate before listings become public.
9. User and volunteer administration
- User profiles are stored in MongoDB and managed through /api/users.
- A user’s device token can be updated, which is important for push notification delivery.
- Admin routes manage:
- user suspension/unsuspension
- volunteer approval/rejection/suspension
- viewing user-associated reports
- This makes user state central to both access control and workflow eligibility.
10. Moderation and audit trail
- The admin subsystem is broader than simple CRUD.
- It includes:
- report moderation states such as resolved/fake/pending
- NGO management
- adoption moderation
- audit log retrieval
- audit-log-model.js indicates that important admin actions are recorded for traceability, which is a separate concern from the operational data models.
11. Notification subsystem
- Services/notification-service.js sits between domain events and outbound messaging/storage.
- The presence of both a notification model and Firebase Admin messaging support suggests a dual notification path:
- persist notifications in MongoDB
- optionally send push notifications using device tokens/Firebase
- This service likely reacts to state changes in reports, adoptions, or admin actions.
12. Architectural boundaries to show in a diagram
- Client/API consumers call Express routes.
- Middleware enforces auth, admin role, and active-user checks before domain logic runs.
- Route handlers coordinate the request.
- Mongoose models persist to MongoDB Atlas.
- Firebase Admin is used for identity verification and messaging.
- Notification service bridges domain events to stored notifications and push delivery.
- The main business domains are users, rescue reports, adoptions, moderation/admin, and notifications.
Main entry points: admin-routes.js Admin · server.js server.js · report-routes.js Reports · requireAuth.js Auth Gate
Components 22
Runtime
Process entrypoint and deployment boundary
- server.js · Starts the Express app and listens on port 5000
server.js - API Clients · Mobile or frontend clients calling the REST API
API Layer
Express routes and request handling
- Users · User profile, device token, and volunteer-facing operations
Routes/users-routes.js - Reports · Rescue report workflow endpoints
Routes/report-routes.js - Adoptions · Adoption listing endpoints and public browsing
Routes/adoption-routes.js - Notifications · Notification read and delivery endpoints
Routes/notification-routes.js - Admin · Moderation, approval, suspension, and audit endpoints
Routes/admin-routes.js
Security
Authentication and access control middleware
- Auth Gate · Verifies Firebase ID tokens for protected routes
middleware/requireAuth.js - Active User · Blocks suspended or inactive users from sensitive actions
middleware/requireActiveUser.js - Admin Gate · Restricts privileged operations to admins
middleware/requireAdmin.js
Domain
Core business subsystems
- Notify Service · Bridges domain events to stored notifications and push delivery
Services/notification-service.js
Data Models
MongoDB/Mongoose persistence boundary
- Users · User accounts, roles, status, and device tokens
Models/usermodel.js - Reports · Rescue reports and status lifecycle
Models/report-model.js - Listings · Adoption listings and approval state
Models/adoption-listing-model.js - Abuse Reports · Moderation reports filed against rescue reports
Models/abuse-report-model.js - Notifications · Persisted user notifications
Models/notification-model.js - Audit Logs · Admin action history for traceability
Models/audit-log-model.js - NGOs · NGO metadata and management records
Models/ngo-model.js
Integrations
External identity and messaging services
- Firebase Config · Firebase bootstrap and initialization settings
Config/firebase.js - Firebase Admin · Central Firebase Admin initialization entry
firebase-admin.js - Firebase Admin SDK · Token verification and push messaging backend
- MongoDB Atlas · Primary persistence backend accessed through Mongoose
Connections 34
- API Clients → server.js: HTTP requests · Clients call the Express API
- server.js → Users: mounts · Registers user routes
- server.js → Reports: mounts · Registers report routes
- server.js → Adoptions: mounts · Registers adoption routes
- server.js → Notifications: mounts · Registers notification routes
- server.js → Admin: mounts · Registers admin routes
- Users → Auth Gate: guards · Protects authenticated user actions
- Reports → Auth Gate: guards · Protects report operations
- Reports → Active User: guards · Blocks inactive users from sensitive report actions
- Adoptions → Auth Gate: guards · Protects listing creation and owner actions
- Admin → Auth Gate: guards · Requires authenticated admin caller
- Admin → Admin Gate: guards · Enforces admin-only access
- Admin → Active User: guards · Ensures active account status for privileged actions
- Users → Users: reads/writes · Manages user profiles and device tokens
- Reports → Reports: reads/writes · Creates and updates rescue reports
- Reports → Abuse Reports: writes · Stores abuse reports against incidents
- Reports → Notify Service: events · Triggers notifications on workflow changes
- Adoptions → Listings: reads/writes · Creates, lists, and moderates adoption listings
- Notifications → Notifications: reads/writes · Exposes persisted notifications to users
- Admin → Audit Logs: reads/writes · Records and retrieves admin audit history
- Admin → NGOs: reads/writes · Manages NGO metadata
- Admin → Users: moderates · Suspends, approves, or rejects users and volunteers
- Notify Service → Notifications: persists · Stores notification records in MongoDB
- Notify Service → Firebase Admin SDK: pushes · Sends push messages through Firebase
- Firebase Admin → Firebase Admin SDK: initializes · Central Firebase Admin bootstrap
- Firebase Config → Firebase Admin: configures · Provides Firebase initialization settings
- Auth Gate → Firebase Admin SDK: verifies tokens · Uses Firebase Admin to validate ID tokens
- Users → MongoDB Atlas: persists to · Mongoose-backed MongoDB storage
- Reports → MongoDB Atlas: persists to · Mongoose-backed MongoDB storage
- Listings → MongoDB Atlas: persists to · Mongoose-backed MongoDB storage
- Abuse Reports → MongoDB Atlas: persists to · Mongoose-backed MongoDB storage
- Notifications → MongoDB Atlas: persists to · Mongoose-backed MongoDB storage
- Audit Logs → MongoDB Atlas: persists to · Mongoose-backed MongoDB storage
- NGOs → MongoDB Atlas: persists to · Mongoose-backed MongoDB storage