# joel-johny/memories architecture

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

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

## Overview

##### Main Components
- Frontend:
- Built using React and Vite.
- Contains components like CalendarModal, MemoryCard, MoodPicker, and various pages (Dashboard, Login, Register, etc.).
- Utilizes Tailwind CSS for styling.
- Backend:
- Node.js and Express server managing the API.
- Organized in an MVC-like pattern: controllers (authController, journalController, userController), models (User, Journal, EmailVerificationMagicLink), routes, middleware (authentication, file upload handling via Multer and Cloudinary), and utility modules for tasks such as email dispatching and file cleanup.
- Database:
- MongoDB (as inferred from the README and environment variables) for storing user data and journal entries.
- External Services:
- Cloudinary for media management (uploading files, generating thumbnails, cleanup).
- Email service (using Nodemailer) for sending email verification links.
- Environment/Deployment:
- Configuration files (.env for both frontend and backend), vercel.json for deployment, and scripts to run servers concurrently.

##### Determining Relationships and Interactions
- Frontend ↔ Backend:
- The React-based UI interacts with the backend through RESTful APIs.
- API calls handle authentication (login, registration, email verification) and CRUD operations for journal entries.
- Backend ↔ Database:
- Node.js/Express communicates with MongoDB to perform database operations.
- Models define schemas for users, journals, etc.
- Backend ↔ External Services:
- Uses Cloudinary integration for handling multimedia uploads.
- Integrates with an email service (via Nodemailer) for sending verification emails.
- Data Flow:
- Users interact via the UI to trigger API requests.
- Authentication middleware verifies requests using JWT tokens.
- Controllers coordinate business logic, querying or updating data in the database, and handling file operations through middleware.

##### Architectural Patterns and Principles
- MVC-like pattern on the backend: clear separation between models, controllers, and routes.
- Modular design: separation of concerns is visible through folder segregation (e.g., separate directories for middleware, utils, configurations).
- API-driven communications: REST APIs to facilitate frontend-backend interactions.
- Cloud integration for specialized tasks (media management and email verification).
- Environment-specific configuration using .env files, facilitating different setups (development, production).

##### Relevant Technologies and Frameworks
- Frontend: React, Vite, Tailwind CSS.
- Backend: Node.js, Express.js.
- Database: MongoDB.
- Authentication: JWT.
- External: Cloudinary & Nodemailer.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Section
    subgraph "Frontend (React/Vite)"
        subgraph "General Setup"
            FS1("index.html"):::frontend
            FS2("App.jsx"):::frontend
            FS3("main.jsx"):::frontend
        end
        subgraph "Pages"
            FP1("Dashboard"):::frontend
            FP2("Login"):::frontend
            FP3("Register"):::frontend
            FP4("EmailVerification"):::frontend
            FP5("JournalEntryForm"):::frontend
            FP6("Landing"):::frontend
            FP7("Memory"):::frontend
            FP8("NotFound"):::frontend
        end
        subgraph "Components"
            FC1("CalendarModal"):::frontend
            FC2("MemoryCard"):::frontend
            FC3("MoodPicker"):::frontend
            FC4("DayDescription"):::frontend
            FC5("LoadingSpinner"):::frontend
            FC6("MemorySearch"):::frontend
            FC7("MemorySnapshot"):::frontend
            FC8("Navbar"):::frontend
            FC9("PrivateRoute"):::frontend
            FC10("ProductivitySlider"):::frontend
            FC11("TitleNThumbnail"):::frontend
        end
        subgraph "Context & Styling"
            FCS("AuthContext"):::frontend
            FSStyle1("index.css"):::frontend
            FSStyle2("tailwind.config.js"):::frontend
        end
    end

    %% Backend Section
    subgraph "Backend (Express/Node.js API)"
        subgraph "Entry Point"
            BE1("app.js"):::backend
        end
        subgraph "Controllers"
            BC1("AuthController"):::backend
            BC2("JournalController"):::backend
            BC3("UserController"):::backend
        end
        subgraph "Models"
            BM1("User"):::backend
            BM2("Journal"):::backend
            BM3("EmailVerificationMagicLink"):::backend
        end
        subgraph "Routes"
            BR1("AuthRoutes"):::backend
            BR2("JournalRoutes"):::backend
            BR3("UserRoutes"):::backend
        end
        subgraph "Middleware"
            BMW1("AuthMiddleware"):::backend
            BMW2("Multer/CloudinaryMiddleware"):::backend
        end
        subgraph "Database Config"
            BDC("MongoDBConnection"):::backend
        end
        subgraph "Utility Modules"
            BU1("CleanupServerUploads"):::backend
            BU2("DeleteCloudinaryResource"):::backend
            BU3("JournalValidation"):::backend
            BU4("EmailDispatch(Mailer)"):::backend
        end
    end

    %% Database Section
    subgraph "Database"
        DB("MongoDB"):::database
    end

    %% External Services Section
    subgraph "External Services"
        ES1("Cloudinary"):::external
        ES2("EmailService"):::external
    end

    %% Deployment & Environment Configurations
    subgraph "Deployment & Environment"
        DE1("BackendDeploymentConfig"):::deployment
        DE2("FrontendDeploymentConfig"):::deployment
    end

    %% Relationships
    %% Frontend to Backend: API calls
    FS2 -->|"REST_API"| BE1

    %% Example user authentication flow from Login page to Auth Controller and middleware
    FP2 -->|"LoginRequest"| BC1
    BC1 -->|"VerifyJWT"| BMW1
    FCS -->|"JWTAuth"| BMW1

    %% Backend controllers interacting with database
    BC1 -->|"DB_Query"| BDC
    BC2 -->|"DB_Query"| BDC
    BC3 -->|"DB_Query"| BDC
    BDC -->|"Connect"| DB

    %% Backend middleware for media handling
    BMW2 -->|"MediaUpload"| ES1

    %% Email dispatch from utilities to Email Service
    BU4 -->|"EmailDispatch"| ES2

    %% Deployment connections
    BE1 -->|"DeployedAs"| DE1
    FS2 -->|"DeployedAs"| DE2

    %% Click Events for Frontend components
    click FS1 "https://github.com/joel-johny/memories/blob/main/frontend/index.html"
    click FS2 "https://github.com/joel-johny/memories/blob/main/frontend/src/App.jsx"
    click FS3 "https://github.com/joel-johny/memories/blob/main/frontend/src/main.jsx"
    click FP1 "https://github.com/joel-johny/memories/blob/main/frontend/src/pages/Dashboard.jsx"
    click FP2 "https://github.com/joel-johny/memories/blob/main/frontend/src/pages/Login.jsx"
    click FP3 "https://github.com/joel-johny/memories/blob/main/frontend/src/pages/Register.jsx"
    click FP4 "https://github.com/joel-johny/memories/blob/main/frontend/src/pages/EmailVerification.jsx"
    click FP5 "https://github.com/joel-johny/memories/blob/main/frontend/src/pages/JournalEntryForm.jsx"
    click FP6 "https://github.com/joel-johny/memories/blob/main/frontend/src/pages/Landing.jsx"
    click FP7 "https://github.com/joel-johny/memories/blob/main/frontend/src/pages/Memory.jsx"
    click FP8 "https://github.com/joel-johny/memories/blob/main/frontend/src/pages/NotFound.jsx"
    click FC1 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/CalendarModal.jsx"
    click FC2 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/MemoryCard.jsx"
    click FC3 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/MoodPicker.jsx"
    click FC4 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/DayDescription.jsx"
    click FC5 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/LoadingSpinner.jsx"
    click FC6 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/MemorySearch.jsx"
    click FC7 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/MemorySnapshot.jsx"
    click FC8 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/Navbar.jsx"
    click FC9 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/PrivateRoute.jsx"
    click FC10 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/ProductivitySlider.jsx"
    click FC11 "https://github.com/joel-johny/memories/blob/main/frontend/src/components/TitleNThumbnail.jsx"
    click FCS "https://github.com/joel-johny/memories/blob/main/frontend/src/context/AuthContext.jsx"
    click FSStyle1 "https://github.com/joel-johny/memories/blob/main/frontend/src/index.css"
    click FSStyle2 "https://github.com/joel-johny/memories/blob/main/frontend/tailwind.config.js"

    %% Click Events for Backend components
    click BE1 "https://github.com/joel-johny/memories/blob/main/backend/app.js"
    click BC1 "https://github.com/joel-johny/memories/blob/main/backend/src/controllers/authController.js"
    click BC2 "https://github.com/joel-johny/memories/blob/main/backend/src/controllers/journalController.js"
    click BC3 "https://github.com/joel-johny/memories/blob/main/backend/src/controllers/userController.js"
    click BM1 "https://github.com/joel-johny/memories/blob/main/backend/src/models/User.js"
    click BM2 "https://github.com/joel-johny/memories/blob/main/backend/src/models/Journal.js"
    click BM3 "https://github.com/joel-johny/memories/blob/main/backend/src/models/EmailVerificationMagicLink.js"
    click BR1 "https://github.com/joel-johny/memories/blob/main/backend/src/routes/authRoutes.js"
    click BR2 "https://github.com/joel-johny/memories/blob/main/backend/src/routes/journalRoutes.js"
    click BR3 "https://github.com/joel-johny/memories/blob/main/backend/src/routes/userRoutes.js"
    click BMW1 "https://github.com/joel-johny/memories/blob/main/backend/src/middleware/authMiddleware.js"
    click BMW2 "https://github.com/joel-johny/memories/blob/main/backend/src/middleware/multerCloudinaryMiddleware.js"
    click BDC "https://github.com/joel-johny/memories/blob/main/backend/src/config/db.js"
    click BU1 "https://github.com/joel-johny/memories/blob/main/backend/src/utils/cleanupServerUploads.js"
    click BU2 "https://github.com/joel-johny/memories/blob/main/backend/src/utils/deleteCloudinaryResource.js"
    click BU3 "https://github.com/joel-johny/memories/blob/main/backend/src/utils/journalValidation.js"
    click BU4 "https://github.com/joel-johny/memories/blob/main/backend/src/utils/mailer.js"
    click DE1 "https://github.com/joel-johny/memories/blob/main/backend/vercel.json"
    click DE2 "https://github.com/joel-johny/memories/blob/main/frontend/vercel.json"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef deployment fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
