# daroom/nearby-shops-mern-app architecture

> Architecture diagram of the GitHub repository daroom/nearby-shops-mern-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/daroom/nearby-shops-mern-app
- Repository: https://github.com/daroom/nearby-shops-mern-app

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Client"
        direction TB
        FE_Entry["Index.js"]:::frontend
        FE_App["App.js"]:::frontend
        FE_Axios["Axios Instance"]:::frontend
        FE_Store["Redux Store"]:::frontend
        FE_AccAct["Account Actions"]:::frontend
        FE_ShopAct["Shop Actions"]:::frontend
        FE_AccRed["Account Reducer"]:::frontend
        FE_ShopRed["Shop Reducer"]:::frontend
        FE_RootRed["Root Reducer"]:::frontend
        FE_Private["PrivateRoute"]:::frontend
        SI["Signin Component"]:::frontend
        SU["Signup Component"]:::frontend
        EP["EditProfile Component"]:::frontend
        Up["UploadPhoto Component"]:::frontend
        CP["CropPhoto Component"]:::frontend
        UCP["UploadCropPhoto Component"]:::frontend
        NS["NearbyShops Component"]:::frontend
        PS["PreferredShops Component"]:::frontend
        Card["CardShop Component"]:::frontend
        SPD_Client["ProfilePhotos (public)"]:::external
    end

    %% Server Layer
    subgraph "API Server"
        direction TB
        SN_entry["app.js"]:::backend
        CFG_DB["DB Config (config/db.js)"]:::backend
        CFG_DEF["default.json"]:::backend
        AR["Auth Routes"]:::backend
        SR["Shops Routes"]:::backend
        MW_Auth["is-Auth Middleware"]:::backend
        MW_User["getUser Middleware"]:::backend
        Ctrl_Auth["Auth Controller"]:::backend
        Ctrl_Shops["Shops Controller"]:::backend
        Model_User["User Model"]:::backend
        Static_Server["ProfilePhotos (public/profilePhotos)"]:::external
    end

    %% Database Layer
    subgraph "Database"
        direction TB
        DB["MongoDB"]:::database
    end

    %% Frontend flow
    FE_Entry --> FE_App
    FE_App --> FE_Axios
    FE_App --> FE_Store
    FE_App --> FE_Private
    SI --> FE_Store
    SU --> FE_Store
    EP --> FE_Store
    NS --> FE_Store
    PS --> FE_Store
    UCP --> FE_Axios
    FE_Store --> FE_Axios

    %% Client-Server communication
    FE_Axios -->|"REST POST /api/auth/signin"| AR
    FE_Axios -->|"REST POST /api/auth/signup"| AR
    FE_Axios -->|"REST GET /api/shops"| SR
    FE_Axios -->|"REST POST /api/auth/upload"| AR

    %% Server internal
    SN_entry --> CFG_DB
    SN_entry --> CFG_DEF
    SN_entry --> AR
    SN_entry --> SR

    AR --> MW_Auth
    AR --> MW_User
    AR --> Ctrl_Auth
    SR --> MW_Auth
    SR --> MW_User
    SR --> Ctrl_Shops

    Ctrl_Auth --> Model_User
    Ctrl_Shops --> Model_User
    Model_User --> DB
    CFG_DB --> DB

    %% Static assets connections
    Static_Server -.-> FE_App
    SPD_Client -.-> FE_App

    %% Click Events
    click FE_Entry "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/index.js"
    click FE_App "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/App.js"
    click FE_Axios "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/api/axiosInstance.js"
    click FE_Store "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/state_management/store.js"
    click FE_AccAct "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/state_management/actions/accountAction.js"
    click FE_ShopAct "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/state_management/actions/shopActions.js"
    click FE_AccRed "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/state_management/reducers/account.js"
    click FE_ShopRed "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/state_management/reducers/shop.js"
    click FE_RootRed "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/state_management/reducers/rootReducer.js"
    click FE_Private "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/Private/PrivateRoute.js"
    click SI "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/components/Account/Signin.js"
    click SU "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/components/Account/Signup.js"
    click EP "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/components/Account/EditProfile.js"
    click Up "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/components/EditProfilePhoto/UploadPhoto.js"
    click CP "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/components/EditProfilePhoto/CropPhoto.js"
    click UCP "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/components/EditProfilePhoto/UploadCropPhoto.js"
    click NS "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/components/ShopsView/NearbyShops.js"
    click PS "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/components/ShopsView/PreferredShops.js"
    click Card "https://github.com/daroom/nearby-shops-mern-app/blob/master/client/src/components/ShopsView/CardShop.js"
    click SPD_Client "https://github.com/daroom/nearby-shops-mern-app/tree/master/client/public/ProfilePhotos/"
    click SN_entry "https://github.com/daroom/nearby-shops-mern-app/blob/master/app.js"
    click CFG_DB "https://github.com/daroom/nearby-shops-mern-app/blob/master/config/db.js"
    click CFG_DEF "https://github.com/daroom/nearby-shops-mern-app/blob/master/config/default.json"
    click AR "https://github.com/daroom/nearby-shops-mern-app/blob/master/routes/authRoutes.js"
    click SR "https://github.com/daroom/nearby-shops-mern-app/blob/master/routes/shopsRoutes.js"
    click MW_Auth "https://github.com/daroom/nearby-shops-mern-app/blob/master/middleware/is-Auth.js"
    click MW_User "https://github.com/daroom/nearby-shops-mern-app/blob/master/middleware/getUser.js"
    click Ctrl_Auth "https://github.com/daroom/nearby-shops-mern-app/blob/master/controllers/authController.js"
    click Ctrl_Shops "https://github.com/daroom/nearby-shops-mern-app/blob/master/controllers/shopsController.js"
    click Model_User "https://github.com/daroom/nearby-shops-mern-app/blob/master/models/User.js"
    click Static_Server "https://github.com/daroom/nearby-shops-mern-app/tree/master/public/profilePhotos/"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef database fill:#FFD580,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
