🚀 Building Occamy – A Scalable MERN-Based Field Operations Platform
📌 The Problem
In rural field operations, most tracking happens through:
WhatsApp messages
Phone calls
Manual registers
This leads to:
No structured data
No verification
No analytics
No audit trail
We built Occamy, a mobile-first field operations tracking system to digitize and structure this workflow.
🏗️ System Architecture
Occamy follows a standard MERN architecture:
Frontend: React (Mobile-first UI)
Backend: Node.js + Express
Database: MongoDB
Authentication: JWT
Deployment: Vercel (Frontend) + Render (Backend)
The backend was designed to be:
Scalable
Secure
Role-based
API-driven
Production deployable
🔐 Authentication & Authorization
One of the most critical backend components was implementing secure authentication.
Approach:
Used JWT for token-based authentication
Password hashing using bcrypt
Created authentication middleware
Implemented Role-Based Access Control (RBAC)
Protected routes ensure:
Only Admin can access analytics
Field officers can only access their own data
🗄️ Database Schema Design
MongoDB collections were designed carefully for scalability.
Key collections:
Users
Name
Role (Admin / Distributor)
Region
Hashed password
Meetings
User ID reference
Location coordinates
Photo URL
Timestamp
Sales
SKU details
Pack size
B2B / B2C type
Order history reference
Relationships were maintained using ObjectId references to ensure data consistency.
⚙️ REST API Design
The backend exposes structured REST APIs:
POST /login
POST /start-day
POST /meeting
POST /sales
GET /admin/analytics
GET /user/activity
Each route:
Validates request body
Uses middleware for token verification
Applies role restrictions
💥 Hardest Backend Challenge
Problem:
Ensuring secure and scalable role-based access while maintaining performance.
Solution:
Created layered middleware:
verifyToken
checkRole
Centralized authentication logic
Structured controllers for clean separation of concerns
This ensured:
Security
Maintainability
Scalability
📊 Analytics & Aggregation
Admin dashboard required:
Distance traveled aggregation
B2B vs B2C sales summary
Monthly meeting counts
We used MongoDB aggregation pipelines to generate efficient reports without excessive queries.
🚀 Deployment Challenges
During deployment:
Faced CORS issues
Environment variable misconfiguration
Token expiry mismatch
Solved by:
Proper CORS setup
Centralized config management
Using consistent production JWT secret
📱 Why Mobile-First Backend Matters
Since most users operate in rural areas with:
Low bandwidth
Low digital literacy
The backend had to:
Keep payload sizes minimal
Avoid unnecessary nested responses
Optimize response times
📚 Key Learnings
Designing scalable REST APIs
Secure authentication flow
MongoDB schema structuring
Production deployment debugging
Real-world system thinking
🔗 GitHub Repository
Top comments (0)