How dharamshiyash/calmspace works
Project type and purpose
• This is a MERN-stack web application (“PBL”) with a React frontend and a Node.js/Express backend using MongoDB for data storage.
• Purpose: user authentication flow (register, login, verify OTP) with API endpoints secured by JWT.
File structure
• Top level: two main folders “frontend” and “backend.”
• Backend folder:
• config/db.js – MongoDB connection setup
• controllers/authController.js – business logic for registration, login, OTP
• middleware/authMiddleware.js – JWT verification for protected routes
• models/User.js – Mongoose schema for user data
• routes/authRoutes.js – Express routes for auth endpoints
• server.js – Express app initialization and route mounting
• utils/generateOTP.js – helper for one-time codes
• Frontend folder:
• public – static HTML, manifest, etc.
• src
– api.js – Axios or fetch wrapper pointing to backend
– pages/* – React components for Landing, Home, Login, Register, Verify OTP
– App.js – router setup and context
– index.js – React DOM bootstrap
README for additional insights
• Confirms use of environment variables (PORT, MONGO_URI, JWT_SECRET, REACT_APP_API_BASE_URL)
• Describes dev scripts for nodemon, React dev server, build process
• Emphasizes separation of concerns: frontend and backend run on different ports
Detail without overcomplication
• Layer and its responsibility
• How environment variables bridge configuration
• Secured routes via middleware
• Sequence: User → LoginPage → api.login() → authController → JWT → Store token in client