How aliftalha/mern works
Project type and purpose
• This is a full-stack MERN-stack fitness tracker app.
• Purpose: Allow users to register/login (JWT auth), log cardio and resistance workouts, view workout history, calculate BMI, and manage exercises (create/delete).
File structure
• Top level:
• backend/ – Express.js REST API
• frontend/ – React.js single-page application
• backend/ pattern:
• config/db.js – Mongoose/MongoDB connection
• middleware/auth.middleware.js – JWT verification
• controllers/ – route handlers (auth.controller.js, exercise.controller.js, resistance-controller.js, workoutController.js, user.controller.js)
• models/ – Mongoose schemas (User, Workout, Exercise, Resistance, Comment)
• routes/ – express.Router modules mounted on /api/auth, /api/workouts, /api/exercises, /api/resistance, /api/comments, /api/users
• utils/errorHandler.js – centralized error formatting
• server.js – app setup, middleware registration, route mounting, listen
• frontend/ pattern:
• public/ – static index.html, manifest
• src/
– pages/ – React Router pages (Home, About, BMI, ContactUs, Dashboard, Details, Login, Register, Resistance)
– components/ – reusable UI (Navbar, Footer, ExerciseList/Form, WorkoutList/Form/Details)
– context/ – React Context providers (AuthContext, WorkoutContext)
– hooks/useWorkoutsContext.js – custom hook for global state
– utils/api.js – axios instance with baseURL + token injection
– App.js + index.js – root component, routing
README for additional insights
• Technology stack: Mongoose, Express, React, Node, JWT Authentication
• Key features: workout logging (cardio/resistance), history view, delete operations, BMI calculator, standard pages (About, Contact Us), authentication flows.
a. Main components
• Client-side (React SPA)
• API Gateway (Express server)
• Authentication layer (JWT middleware)
• Business logic (controllers)
• Data Access (Mongoose models)
• Database (MongoDB)
• External services (e.g., hosting/CDN, if any)
b. Relationships and interactions
1. User (browser/mobile) → React SPA (HTTP over HTTPS)
2. React SPA → axiosInstance (in utils) attaches JWT token → Express API endpoints
3. Express routes → auth middleware (for protected routes) → controllers
4. Controllers ↔ models (Mongoose) → MongoDB Atlas/local
5. Responses flow back along the chain to the client
c. Architectural patterns and principles
• MVC-style layering on backend (Routes → Controllers → Models)
• Single Page Application with React Router on frontend
• Context API for global state management (AuthContext, WorkoutContext)
• Custom hooks for data fetching and state updates
• Centralized error handling in backend (utils/errorHandler)
• Stateless JWT auth for session management
d. Key technologies/frameworks
• React.js, React Router, Context API, axios
• Node.js, Express.js, JWT, Mongoose, MongoDB