# resilient-labs/nourish architecture

> Architecture diagram of the GitHub repository resilient-labs/nourish, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/resilient-labs/nourish
- Repository: https://github.com/resilient-labs/nourish

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express.js, React, Node.js) application called “Nourish.”
- Purpose: A community-driven platform to locate Philly community fridges, share updates on restocking, maintenance, and general community posts.

##### File structure
- Top-level: “client” (React frontend) and “server” (Node/Express backend).
- client/src: React components (UI, pages, routing) plus Tailwind CSS and Flowbite for styling.
- server:
- config: database connection (MongoDB URI), Passport.js setup (JWT/local strategies)
- controllers: request handlers (auth, fridge, posts, profile, team)
- models: Mongoose schemas (User, CommunityFridge, Post, Comment, Team)
- middleware: auth guard, file uploads (multer + Cloudinary), error handling
- routes: express routers exposing RESTful endpoints (/auth, /fridge, /posts, /profile, /team)

##### README for additional insights
- Interactive map uses Leaflet inside React (FridgeMap component).
- Community board features comment posting, filtering by zip code.
- Authentication (sign up/in) with protected routes on the client.
- Cloudinary for storing images.
- Future roadmap: real-time updates, additional locations, user profiles.

##### Detail and essential architectural elements
- Server folders as sub-components: config, controllers, middleware, routes, models
- On the client side, show core pages (Home, FridgeLocations, Community) and shared components (Navbar, ProtectedRoute)
- Data flow for key scenarios:
1. User logs in → React form → POST /auth/login → Passport validates → JWT → stored in client
2. React fetches fridge list → GET /fridge → Express controller → MongoDB → JSON → React renders map + list
3. User posts a comment → React form → POST /posts → multer + Cloudinary → save in MongoDB → broadcast update

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Browser
    Browser["Browser / User"]:::external

    %% Frontend Layer
    subgraph "React Client" 
        direction TB
        ReactClient["React Client"]:::frontend
        Index["src/index.js"]:::frontend
        TailwindConfig["tailwind.config.js"]:::frontend
        App["src/App.js"]:::frontend
        ProtectedRoute["src/components/ProtectedRoute.js"]:::frontend
        Navbar["src/components/Navbar.js"]:::frontend
        FridgeMap["src/components/FridgeMap.js"]:::frontend
        FridgeList["src/components/FridgeList.js"]:::frontend
        FridgeCard["src/components/Fridge.js"]:::frontend
        MessageBoard["src/components/MessageBoardInteractive.js"]:::frontend
        AllPosts["src/components/AllPosts.js"]:::frontend
        CommentBox["src/components/CommentBox.js"]:::frontend
        CommentButtons["src/components/CommentButtons.js"]:::frontend
        Home["src/pages/Home.js"]:::frontend
        FridgeLocations["src/pages/FridgeLocations.js"]:::frontend
        Community["src/pages/Community.js"]:::frontend
        FridgeProfile["src/pages/FridgeProfile.js"]:::frontend
        OurTeam["src/pages/OurTeam.js"]:::frontend
        Login["src/pages/Login.js"]:::frontend
        SignUp["src/pages/SignUp.js"]:::frontend
        UserProfile["src/pages/UserProfile.js"]:::frontend
    end

    %% Backend Layer
    subgraph "Express API" 
        direction TB
        ExpressAPI["Express API"]:::backend
        ServerEntry["server/server.js"]:::backend
        DBConfig["config/database.js"]:::backend
        PassportConfig["config/passport.js"]:::backend
        AuthController["controllers/auth.js"]:::backend
        FridgeController["controllers/fridge.js"]:::backend
        PostsController["controllers/posts.js"]:::backend
        ProfileController["controllers/profile.js"]:::backend
        TeamController["controllers/team.js"]:::backend
        AuthMiddleware["middleware/auth.js"]:::backend
        MulterMiddleware["middleware/multer.js"]:::backend
        Cloudinary1["middleware/cloudinary.js"]:::backend
        Cloudinary2["middleware/cloudinary2.js"]:::backend
        RouteMain["routes/main.js"]:::backend
        RouteFridge["routes/fridge.js"]:::backend
        RoutePosts["routes/posts.js"]:::backend
        RouteProfile["routes/profile.js"]:::backend
        RouteTeam["routes/team.js"]:::backend
        ModelsUser["models/User.js"]:::backend
        ModelsFridge["models/CommunityFridge.js"]:::backend
        ModelsPost["models/Post.js"]:::backend
        ModelsComment["models/Comment.js"]:::backend
        ModelsTeam["models/Team.js"]:::backend
    end

    %% Data & External
    DB["MongoDB"]:::db
    CloudinaryService["Cloudinary"]:::external
    LeafletTiles["Leaflet Map Tiles"]:::external

    %% Connections
    Browser -->|"interacts with"| ReactClient
    ReactClient -->|"HTTP/REST calls"| ExpressAPI
    ExpressAPI -->|"CRUD operations"| DB
    ExpressAPI -->|"upload images"| CloudinaryService
    ReactClient -->|"tile requests"| LeafletTiles

    %% Click Events
    click ReactClient "https://github.com/resilient-labs/nourish/tree/main/client/"
    click Index "https://github.com/resilient-labs/nourish/blob/main/client/src/index.js"
    click TailwindConfig "https://github.com/resilient-labs/nourish/blob/main/client/tailwind.config.js"
    click App "https://github.com/resilient-labs/nourish/blob/main/client/src/App.js"
    click ProtectedRoute "https://github.com/resilient-labs/nourish/blob/main/client/src/components/ProtectedRoute.js"
    click Navbar "https://github.com/resilient-labs/nourish/blob/main/client/src/components/Navbar.js"
    click FridgeMap "https://github.com/resilient-labs/nourish/blob/main/client/src/components/FridgeMap.js"
    click FridgeList "https://github.com/resilient-labs/nourish/blob/main/client/src/components/FridgeList.js"
    click FridgeCard "https://github.com/resilient-labs/nourish/blob/main/client/src/components/Fridge.js"
    click MessageBoard "https://github.com/resilient-labs/nourish/blob/main/client/src/components/MessageBoardInteractive.js"
    click AllPosts "https://github.com/resilient-labs/nourish/blob/main/client/src/components/AllPosts.js"
    click CommentBox "https://github.com/resilient-labs/nourish/blob/main/client/src/components/CommentBox.js"
    click CommentButtons "https://github.com/resilient-labs/nourish/blob/main/client/src/components/CommentButtons.js"
    click Home "https://github.com/resilient-labs/nourish/blob/main/client/src/pages/Home.js"
    click FridgeLocations "https://github.com/resilient-labs/nourish/blob/main/client/src/pages/FridgeLocations.js"
    click Community "https://github.com/resilient-labs/nourish/blob/main/client/src/pages/Community.js"
    click FridgeProfile "https://github.com/resilient-labs/nourish/blob/main/client/src/pages/FridgeProfile.js"
    click OurTeam "https://github.com/resilient-labs/nourish/blob/main/client/src/pages/OurTeam.js"
    click Login "https://github.com/resilient-labs/nourish/blob/main/client/src/pages/Login.js"
    click SignUp "https://github.com/resilient-labs/nourish/blob/main/client/src/pages/SignUp.js"
    click UserProfile "https://github.com/resilient-labs/nourish/blob/main/client/src/pages/UserProfile.js"
    click ExpressAPI "https://github.com/resilient-labs/nourish/tree/main/server/"
    click ServerEntry "https://github.com/resilient-labs/nourish/blob/main/server/server.js"
    click DBConfig "https://github.com/resilient-labs/nourish/blob/main/server/config/database.js"
    click PassportConfig "https://github.com/resilient-labs/nourish/blob/main/server/config/passport.js"
    click AuthController "https://github.com/resilient-labs/nourish/blob/main/server/controllers/auth.js"
    click FridgeController "https://github.com/resilient-labs/nourish/blob/main/server/controllers/fridge.js"
    click PostsController "https://github.com/resilient-labs/nourish/blob/main/server/controllers/posts.js"
    click ProfileController "https://github.com/resilient-labs/nourish/blob/main/server/controllers/profile.js"
    click TeamController "https://github.com/resilient-labs/nourish/blob/main/server/controllers/team.js"
    click AuthMiddleware "https://github.com/resilient-labs/nourish/blob/main/server/middleware/auth.js"
    click MulterMiddleware "https://github.com/resilient-labs/nourish/blob/main/server/middleware/multer.js"
    click Cloudinary1 "https://github.com/resilient-labs/nourish/blob/main/server/middleware/cloudinary.js"
    click Cloudinary2 "https://github.com/resilient-labs/nourish/blob/main/server/middleware/cloudinary2.js"
    click RouteMain "https://github.com/resilient-labs/nourish/blob/main/server/routes/main.js"
    click RouteFridge "https://github.com/resilient-labs/nourish/blob/main/server/routes/fridge.js"
    click RoutePosts "https://github.com/resilient-labs/nourish/blob/main/server/routes/posts.js"
    click RouteProfile "https://github.com/resilient-labs/nourish/blob/main/server/routes/profile.js"
    click RouteTeam "https://github.com/resilient-labs/nourish/blob/main/server/routes/team.js"
    click ModelsUser "https://github.com/resilient-labs/nourish/blob/main/server/models/User.js"
    click ModelsFridge "https://github.com/resilient-labs/nourish/blob/main/server/models/CommunityFridge.js"
    click ModelsPost "https://github.com/resilient-labs/nourish/blob/main/server/models/Post.js"
    click ModelsComment "https://github.com/resilient-labs/nourish/blob/main/server/models/Comment.js"
    click ModelsTeam "https://github.com/resilient-labs/nourish/blob/main/server/models/Team.js"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#2196F3,stroke-width:1px
    classDef backend fill:#E8F5E9,stroke:#4CAF50,stroke-width:1px
    classDef db fill:#FFF3E0,stroke:#FB8C00,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#F3E5F5,stroke:#9C27B0,stroke-width:1px,stroke-dasharray: 2 2
```
