How ankur-git-commit/mern-goalsetterapp works
Key Components
• Frontend: Built with React and Redux Toolkit. It contains components (GoalForm, GoalItem, Header, Spinner), feature slices (auth and goals), different pages (Dashboard, Login, Register), and uses Vite as the build tool.
• Backend: A Node.js/Express API that includes configuration (db.js), controllers (userController, goalController), middleware (auth, error handling), models (Mongoose models for users and goals), and RESTful routes.
• Database: MongoDB connected via Mongoose.
• External Services: JWT for authentication, Bcrypt for password hashing, and React Toastify for notifications in the frontend.
Out Relationships and Interactions
• Frontend and Backend Interaction: The React frontend makes HTTP requests (using Axios) to the backend API endpoints (e.g., /api/users, /api/goals). The API endpoints are protected by JWT-based authentication.
• State Management: In the frontend, Redux Toolkit manages state (with separate slices for auth and goals), where actions trigger updates based on responses from the backend.
• Data Flow: User actions in React components lead to API calls, which are handled by controllers in the backend. The controllers then interact with the MongoDB database via Mongoose models.
• Middleware: The backend middleware layer (authMiddleware and errorMiddleware) processes requests for authentication and error handling.
Architectural Patterns and Key Principles
• Clear separation between the client-side UI and backend API.
• MVC-leaning structure on the backend (Controllers, Models, Routes).
• Middleware pattern for centralizing cross-cutting concerns like authentication and error handling.
• RESTful design for API endpoints.
• State management with Redux in the frontend to handle global state in a modular way.
Technology Stack Details
• Backend Technologies: Node.js, Express.js, Mongoose/MongoDB, JWT, Bcrypt.js, Express Async Handler.
• Build/Dev Tools: Vite for frontend and concurrently for running both parts (backend and frontend) together.