How daroom/nearby-shops-mern-app works
Project Type and Purpose
• This is a full-stack MERN (MongoDB, Express, React, Node.js) web application.
• Purpose: Allow users to sign up, sign in, view and edit their profile (including uploading and cropping a photo), and browse nearby or preferred shops.
File Structure Analysis
• Top-level
– app.js: Entry point for the Express server
– config/: Database configuration and default settings
– controllers/: Business logic for authentication and shops
– middleware/: Request-level middleware (authentication, user retrieval)
– models/: Mongoose schemas (User)
– routes/: API route definitions for auth and shops
– client/: React frontend app
– lib/ & spec/: Test examples using Jasmine
• client/ (React)
– public/: Static assets (HTML shell, profile photos, manifest)
– src/
· App.js, index.js: React bootstrap
· api/axiosInstance.js: Configured Axios for API calls
· components/: UI components (Account flows, NavBar, ShopsView, profile photo editing)
· state_management/: Redux (actions, reducers, store)
· PrivateRoute: Route guards for authenticated views
• config/default.json: Stores environment-specific settings (e.g., MongoDB URI)
• spec/ and lib/: Illustrative Jasmine tests and helpers
README Insights
• Confirms MERN stack and use of react-image-crop for client-side image cropping
• Deployed to Heroku
Main Components
a. Frontend Client
– React application (Components, Redux store, Axios)
– Static file server (serving bundle in production)
b. API Server
– Node.js + Express
– Routes → Controllers → Middleware
– Authentication (JWT or session)
c. Database
– MongoDB (via Mongoose)
– Collections: Users, Shops (implied)
d. External/Supporting Services
– Image-crop library on client
– File storage for profile photos (could be local fs or cloud storage—note if using AWS S3 or similar)
e. Third-party Integrations
– (Optional) Any analytics, logging, or monitoring service if in use
Relationships and Data Flows
• User’s browser ↔ React client
– HTTP/HTTPS requests for dynamic data via Axios
– Webpack-bundled JS/CSS served by Express (or static host in production)
• React client → Express API
– RESTful calls (signin, signup, fetch shops, upload profile photo)
• Express API → MongoDB
– Mongoose queries in controllers
• Middleware
– is-Auth: validates JWT token on protected routes
– getUser: retrieves user data from token for controllers
• Profile photo upload
– Client uses react-image-crop → POST to /auth/upload (or similar) → saved in public/profilePhotos → served back as static asset
Architectural Patterns and Design Principles
• Layered MVC-style on the server (Routes → Controllers → Models)
• Flux pattern on the client (Redux store, actions, reducers)
• Separation of concerns:
– UI vs. state management vs. API calls on client
– Routing vs. business logic vs. data access on server
• Use of middleware for cross-cutting concerns (authentication)
Step-by-Step Creation
2. Inside Client lane, place React App block; inside it, show Redux store and key components.
4. In Server lane, sketch subcomponents: Routes → Middleware → Controllers → Models.