How alokinfilon/trackmate works
Purpose and Entry Point
This is a Node.js API backend for travel-oriented users: authentication, trips, locations, galleries, notifications, and supporting content such as FAQs, reviews, and travel preferences. The process starts at index.js, with application-level request handling in controllers/appController.js.
HTTP API Surface
Feature routes partition the public API by domain:
• Authentication: routes/auth.js, controllers/auth.js
• Trips: routes/trip.routes.js, controllers/trip.controller.js
• Gallery/media: routes/gallery.routes.js, controllers/gallery.controller.js
• Locations: routes/locationRoutes.js, controllers/location.js
• Notifications: routes/notification.routes.js, controllers/notification.controller.js
routes/apiRoutes.js is the likely route aggregation boundary. Swagger definitions under docs/ and swagger/swagger.js document the API contract.
Identity and Request Security
Authentication is handled through controllers and shared middleware. middleware/auth.middleware.js protects authenticated endpoints, while middleware/passport.js configures Passport-based identity handling. Refresh-token persistence is represented by models/refreshToken.js; user records are defined in models/user.js.
The flow is: auth route → auth controller → user/token models → protected feature routes through auth middleware.
Domain Persistence Layer
Mongo-style model definitions appear to be centralized in models/index.js, with separate records for primary entities:
• Trips and collections: models/trip.model.js, models/collection.model.js, models/collectionShare.js
• Gallery assets: models/gallery.model.js
• Geographic content: models/location.js
• User-facing content and preferences: models/faq.js, models/travelPreference.js, models/review.js
• Device delivery state: models/deviceToken.js, models/notification.js
Database initialization and seed loading are separated in database/connection.js and database/seed.js.
Location and Travel Data Boundary
Location behavior has a repository layer in repository/location.repo.js, distinct from its controller in controllers/location.js. This is the clearest data-access abstraction in the repository and likely mediates database-backed location lookup or aggregation. Static/bootstrap travel content is also present under data/location_data.json and data/travel_preference_data.json.
Media and Sharing Flow
Gallery endpoints coordinate gallery records with external media storage through utils/cloudinary.js. Gallery-specific transformation or validation logic is isolated in utils/gallery.helper.js. Collections and collection shares (models/collection.model.js, models/collectionShare.js) indicate that trip/gallery content can be grouped and shared independently of core trip ownership.
Notifications and External Delivery
Notification request handling resides in controllers/notification.controller.js; persisted notification and device-token state are in models/notification.js and models/deviceToken.js. utils/firebase.js and utils/notification.service.js form the external push-notification boundary, likely sending to registered client devices rather than directly coupling controllers to Firebase.
Cross-Cutting Failure Handling
Request validation and failure normalization are centralized in middleware/validator.js, middleware/errorHandler.js, and middleware/notFound.js. These form the API boundary around feature controllers: validate input before domain handling, return standardized errors for thrown failures, and handle unmatched routes consistently.
Main entry points: apiRoutes.js API route aggregator · connection.js Mongo database setup · auth.middleware.js Authenticated-route guard · gallery.routes.js Gallery API
Components 22
HTTP API
- Node entry point
index.js - Application handler
controllers/appController.js - API route aggregator
routes/apiRoutes.js - Trips API
routes/trip.routes.js - Gallery API
routes/gallery.routes.js - Locations API
routes/locationRoutes.js - Notifications API
routes/notification.routes.js - Validation & error handling · Validates requests and normalizes failures or unmatched routes.
middleware/validator.js - Swagger API contract
swagger/swagger.js
Identity & Security
- Authentication API
routes/auth.js - Passport identity
middleware/passport.js - Authenticated-route guard
middleware/auth.middleware.js - Users & refresh tokens
models/user.js
Domain & Persistence
- Trips & shared collections
models/trip.model.js - Gallery records
models/gallery.model.js - Location repository · Mediates location lookup and aggregation.
repository/location.repo.js - Location content
models/location.js - Preferences & reviews
models/travelPreference.js - Notifications & devices
models/notification.js - Mongo database setup
database/connection.js
External Delivery
- Cloudinary media storage
utils/cloudinary.js - Push notification service
utils/notification.service.js
Connections 28
- Node entry point → Application handler: starts
- Application handler → API route aggregator: mounts
- Application handler → Validation & error handling: applies
- API route aggregator → Authentication API: routes
- API route aggregator → Trips API: routes
- API route aggregator → Gallery API: routes
- API route aggregator → Locations API: routes
- API route aggregator → Notifications API: routes
- Authentication API → Users & refresh tokens: reads and writes
- Authentication API → Passport identity: uses
- Authenticated-route guard → Passport identity: verifies identity with
- Authenticated-route guard → Trips API: protects
- Authenticated-route guard → Gallery API: protects
- Authenticated-route guard → Notifications API: protects
- Trips API → Trips & shared collections: manages
- Gallery API → Gallery records: manages
- Gallery API → Cloudinary media storage: stores media through
- Locations API → Location repository: queries through
- Location repository → Location content: accesses
- Notifications API → Notifications & devices: persists state
- Notifications API → Push notification service: sends through
- Trips & shared collections → Mongo database setup: persists via
- Gallery records → Mongo database setup: persists via
- Location content → Mongo database setup: persists via
- Notifications & devices → Mongo database setup: persists via
- Users & refresh tokens → Mongo database setup: persists via
- Preferences & reviews → Mongo database setup: persists via
- Swagger API contract → API route aggregator: documents