# pmg1601/memories architecture

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

- Interactive diagram: https://gitdiagram.com/pmg1601/memories
- Repository: https://github.com/pmg1601/memories

## Overview

##### Project type and purpose
- This is a MERN-style full-stack web application named “memories.”
- Purpose: allow users to sign up/log in, create/read/update/delete “memory” cards (posts) with titles, messages, images, and comments.

##### File structure
Top-level:
- client/ – React single-page application
- server/ – Node.js + Express REST API
- HowItWorks.md, README.md – documentation
client/:
- src/ – React components, Redux actions & reducers, API wrapper
- public/ – static HTML, manifest, redirects
- build/ – production bundle (static assets)
server/:
- index.js – app entrypoint (Express app, DB connection, middleware)
- controllers/ – postsController.js, userController.js (business logic)
- routes/ – postsRoutes.js, userRoutes.js (URL → controller mapping)
- models/ – Mongoose schemas (postMessageModel.js, userModel.js)
- middleware/ – authMiddleware.js (JWT verification)
- Procfile – Heroku deployment descriptor

##### README
- Confirms that the app is for posting and browsing life memories in card form.
- Likely uses JWT for auth, MongoDB for storage, Redux for client-side state.

a. Main components
1. Browser/Client (React + Redux SPA)
2. REST API Server (Node.js + Express)
3. Database (MongoDB via Mongoose)
4. Authentication layer (JWT issuing & validation)
5. (Optional) Static asset host or CDN for client build
6. Deployment platforms (Heroku for server, Netlify/Vercel for client or bundled in Express)

b. Relationships & interactions
- User ▶ React UI (interacts via clicks, form submissions)
- React ▶ Redux store ▶ dispatch(actions) ▶ API calls (axios/fetch)
- Frontend HTTP requests ▶ Express routes (e.g. /posts, /users/auth)
- Express routes ▶ middleware ▶ controllers ▶ models ▶ MongoDB
- Controllers return JSON ▶ client updates UI via Redux

c. Architectural patterns
- Client: Flux/Redux for unidirectional data flow, container/components split
- Server: MVC-inspired (routes → controllers → models)
- RESTful API design for CRUD operations on “memories” and user auth
- JWT-based stateless authentication (authMiddleware)

d. Key technologies & libraries
- React, Redux, React-Redux, React Router (frontend)
- Axios or fetch for HTTP calls (client/src/api)
- Express, Mongoose, JSON Web Token (server)
- Heroku (Procfile), Node.js, npm

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top: User
    User["User (Browser)"]:::user

    %% Client Layer
    subgraph "Client (React + Redux SPA)"
        direction TB
        EP["Entry Point\n(index.js, App.js)"]:::frontend
        UI["React UI Components"]:::frontend
        subgraph "Components"
            direction TB
            Auth["Auth Components"]:::frontend
            Form["Form Components"]:::frontend
            Home["Home Components"]:::frontend
            Navbar["Navbar Components"]:::frontend
            Posts["Posts List & Card"]:::frontend
            PostDetails["Post Details & Comments"]:::frontend
        end
        Store["Redux Store"]:::frontend
        subgraph "Store Details"
            direction TB
            Actions["Actions"]:::frontend
            Reducers["Reducers"]:::frontend
            ActionTypes["Action Types"]:::frontend
        end
        API["API Client\n(client/src/api/index.js)"]:::frontend
        Public["Public Assets"]:::frontend
        Build["Production Build"]:::frontend
    end

    %% Server Layer
    subgraph "Server (Node.js + Express API)"
        direction TB
        ServerEntry["Server Entry\n(server/index.js)"]:::backend
        subgraph "Routes"
            direction TB
            PostsRoutes["Posts Routes"]:::backend
            UserRoutes["User Routes"]:::backend
        end
        AuthMW["Auth Middleware\n(JWT)"]:::backend
        subgraph "Controllers"
            direction TB
            PostsCtrl["Posts Controller"]:::backend
            UserCtrl["User Controller"]:::backend
        end
        subgraph "Models"
            direction TB
            PostModel["PostMessage Model"]:::backend
            UserModel["User Model"]:::backend
        end
        Procfile["Heroku Procfile"]:::backend
    end

    %% External Services
    MongoDB[(MongoDB)]:::db
    JWT["JWT Token"]:::auth
    CDN["Static Asset Host / CDN"]:::deploy
    Heroku["Heroku Hosting"]:::deploy

    %% Connections
    User -->|opens app| EP
    EP -->|renders| UI
    UI -->|uses| Store
    UI -->|calls| API
    API -->|HTTP requests| ServerEntry
    ServerEntry -->|routes to| PostsRoutes
    ServerEntry -->|routes to| UserRoutes
    PostsRoutes -->|uses| AuthMW
    UserRoutes -->|uses| AuthMW
    PostsRoutes -->|calls| PostsCtrl
    UserRoutes -->|calls| UserCtrl
    AuthMW -->|verifies| JWT
    PostsCtrl -->|queries| PostModel
    PostsCtrl -->|returns JSON| API
    UserCtrl -->|queries| UserModel
    UserCtrl -->|issues| JWT
    PostModel -->|stores| MongoDB
    UserModel -->|stores| MongoDB
    UI -->|loads assets| Public
    Build -->|served by| CDN
    ServerEntry -->|deploys on| Heroku

    %% Click Events
    click EP "https://github.com/pmg1601/memories/blob/main/client/src/index.js"
    click EP "https://github.com/pmg1601/memories/blob/main/client/src/App.js"
    click Auth "https://github.com/pmg1601/memories/tree/main/client/src/components/Auth/"
    click Form "https://github.com/pmg1601/memories/tree/main/client/src/components/Form/"
    click Home "https://github.com/pmg1601/memories/tree/main/client/src/components/Home/"
    click Navbar "https://github.com/pmg1601/memories/tree/main/client/src/components/Navbar/"
    click Posts "https://github.com/pmg1601/memories/tree/main/client/src/components/Posts/"
    click PostDetails "https://github.com/pmg1601/memories/tree/main/client/src/components/PostDetails/"
    click Actions "https://github.com/pmg1601/memories/blob/main/client/src/actions/auth.js"
    click Actions "https://github.com/pmg1601/memories/blob/main/client/src/actions/posts.js"
    click Reducers "https://github.com/pmg1601/memories/blob/main/client/src/reducers/auth.js"
    click Reducers "https://github.com/pmg1601/memories/blob/main/client/src/reducers/posts.js"
    click Reducers "https://github.com/pmg1601/memories/blob/main/client/src/reducers/index.js"
    click ActionTypes "https://github.com/pmg1601/memories/blob/main/client/src/constants/actionTypes.js"
    click API "https://github.com/pmg1601/memories/blob/main/client/src/api/index.js"
    click Public "https://github.com/pmg1601/memories/blob/main/client/public/index.html"
    click Public "https://github.com/pmg1601/memories/blob/main/client/public/manifest.json"
    click Build "https://github.com/pmg1601/memories/tree/main/client/build/"
    click ServerEntry "https://github.com/pmg1601/memories/blob/main/server/index.js"
    click PostsCtrl "https://github.com/pmg1601/memories/blob/main/server/controllers/postsController.js"
    click UserCtrl "https://github.com/pmg1601/memories/blob/main/server/controllers/userController.js"
    click PostsRoutes "https://github.com/pmg1601/memories/blob/main/server/routes/postsRoutes.js"
    click UserRoutes "https://github.com/pmg1601/memories/blob/main/server/routes/userRoutes.js"
    click PostModel "https://github.com/pmg1601/memories/blob/main/server/models/postMessageModel.js"
    click UserModel "https://github.com/pmg1601/memories/blob/main/server/models/userModel.js"
    click AuthMW "https://github.com/pmg1601/memories/blob/main/server/middleware/authMiddleware.js"
    click Procfile "https://github.com/pmg1601/memories/tree/main/server/Procfile"
    click README "https://github.com/pmg1601/memories/blob/main/README.md"
    click HowItWorks "https://github.com/pmg1601/memories/blob/main/HowItWorks.md"
    click ClientReadme "https://github.com/pmg1601/memories/blob/main/client/README.md"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef backend fill:#DFFFE0,stroke:#228B22,color:#228B22;
    classDef db fill:#FFF5BA,stroke:#DAA520,color:#DAA520,stroke-width:2px;
    classDef auth fill:#FFEFD5,stroke:#CD853F,color:#CD853F,stroke-width:2px;
    classDef deploy fill:#E8E8E8,stroke:#696969,color:#696969;
    classDef user fill:#F0F8FF,stroke:#4682B4,color:#4682B4;
```
