How a169n/fitme works
Project type and purpose
• FitMe is a monorepo full-stack web application.
• Frontend: React + Vite + Redux Toolkit for a single-page app.
• Backend: Node.js + Express + Mongoose for RESTful APIs.
• Purpose: Manage users, restaurants, foods, categories, orders, reviews, messages; integrate with external exercise/recipe APIs; handle auth, file uploads, and email notifications.
Key directories and architectural patterns
• client/ → React app (components, pages, hooks, redux).
• server/ → Express app (routes, controllers, models, middleware).
• Root uses concurrently to start both dev servers.
• MVC-style on the backend (models/controllers/routes).
• Presentation/container pattern on the frontend; global state via Redux slices and RTK Query for API calls.
Main components
a. Client Tier (Browser)
• React SPA (pages & components)
• Redux store & RTK Query services
• Custom hooks for auth and role checks
b. API Gateway (Express Server)
• Routers (apiRouter, authRouter, cartRouter, etc.)
• Controllers (business logic)
• Middleware (authMiddleware for JWT, multer for file uploads, cors)
• Config (db connection via Mongoose, env variables via dotenv)
c. Data Tier
• MongoDB cluster (collections: users, restaurants, foods, categories, orders, messages, reviews, globalCategories)
d. External Services
• Third-party exercise API
• Third-party recipes API
• SMTP/Mail service via Nodemailer
e. File storage
• Local server/uploads directory via multer (images)
Component interactions and data flows
• Browser ↔ React SPA: user actions trigger API calls via RTK Query.
• React SPA → Express API endpoints (HTTP REST).
• Express → Controllers → Mongoose Models → MongoDB.
• Express ↔ External APIs: fetch exercises & recipes on demand.
• Express → Nodemailer: send email notifications on login/registration.
• Express → multer → server/uploads: handle image uploads/deletions.
• JWT tokens issued by authController, validated by authMiddleware on protected routes.
Important architectural patterns/design principles
• Separation of concerns:
• Frontend UI / state management vs. backend REST & business logic.
• Controllers for logic, models for data schema, routes for API definitions.
• Statelessness: RESTful endpoints use JWT for authentication.
• Single source of truth: Redux store holds client state; MongoDB is persistent store.
• Scalability: MVC layering allows independent scaling of API, DB, and front end.
• Extensibility: RTK Query services add new endpoints easily; Express router/controller pattern permits adding new resources.
a. Sketch the three tiers horizontally: Client | API | Data & Services.
b. Inside Client tier, subdivide into UI layer, state management, network layer.
c. Inside API tier, stack routers at top, controllers in middle, models at bottom, middleware on the side along incoming routes.