# msami625/recipesnap architecture

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

- Interactive diagram: https://gitdiagram.com/msami625/recipesnap
- Repository: https://github.com/msami625/recipesnap

## Overview

##### Project Overview
- Recipe Snap is a dynamic recipe-sharing and discovery application.
- The frontend is built using React and styled via Tailwind CSS.
- The backend is built on Node.js/Express with JWT-based authentication.
- The application uses MySQL for the database.
- Hosting and static file management are performed on AWS (EC2 for backend and S3 for static files).

##### Main Components
a. Frontend:
- React Application with components such as pages (e.g., Home, RecipeDetails, SignUp, etc.) and shared components (Navbar, Loader, RecipeCard).
- Service layer (apiClient.js) that handles HTTP communications.
- Tailwind CSS’s involvement for styling.

b. Backend:
- Node.js / Express server.
- Sub-components:
- Controllers (e.g., RecipeController, authController, reviewController) – these handle business logic.
- Routes (e.g., recipeRoute, authRoute, reviewRoute) – map HTTP endpoints.
- Middlewares (e.g., authenticate.js) – apply security and request validation.
- Models (e.g., Recipe, Review, User) – which map to the MySQL database schema.
- Utility modules (e.g., database.js) – handle database connections/configuration.

c. Database:
- MySQL to represent persistent storage with entities corresponding to users, recipes, reviews, etc.

d. External Services:
- AWS EC2 for hosting the Node.js Express backend.
- AWS S3 to serve static assets (like React build files or media uploads).

e. Authentication:
- Use of JWT in the backend for securing endpoints.

##### Relationships and Interactions
- The Backend routes incoming requests to appropriate Controllers. Illustrate that Controllers interact with Models to perform CRUD operations on the MySQL Database.
- Use a middleware layer (authenticate.js) between client requests and controllers to enforce user authentication.
- That the backend, when deployed, runs on an AWS EC2 instance.
- That static files and possibly media content are hosted on AWS S3 and consumed by the frontend.

##### Architectural Patterns and Design Principles
- MVC (Model-View-Controller): The backend distinctly organizes Models, Controllers, and Routes, which is a hallmark of the MVC pattern.
- Separation of Concerns: Distinguish clearly between the frontend (user interface) and backend (server-side logic and data).
- RESTful API: Use of API endpoints for client-server communication.

##### Elements
- Clear labels for each system component (e.g., “React Frontend”, “Express API Server”, “JWT Authentication Middleware”, “MySQL Database”, “AWS EC2”, “AWS S3”).
- Frontend to Backend: indicating RESTful API calls.
- Backend to Database: indicating data CRUD operations.
- Backend response back to Frontend.
- Annotations where necessary to emphasize essential services (e.g., “User Authentication with JWT”, “File Hosting on AWS S3”).
- UI components (frontend),
- Application logic (backend controllers, routes, middleware),
- Data storage (MySQL), and
- Infrastructure (AWS services).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Subgraph
    subgraph "React Frontend"
        A["Pages"]:::frontend
        B["Components"]:::frontend
        C["Service Layer"]:::frontend
        D["Tailwind CSS Config"]:::frontend
        F1["Static Assets"]:::frontend
    end

    %% Backend Subgraph
    subgraph "Express API Server"
        E["Express API Server"]:::backend
        F["JWT Auth Middleware"]:::backend
        G["Routes"]:::backend
        H["Controllers"]:::backend
        I["Models"]:::backend
        J["Database Utility"]:::backend
    end

    %% External and Database Components
    K["MySQL Database"]:::database
    L["AWS EC2"]:::external
    M["AWS S3"]:::external

    %% Relationships and Data Flow
    C -->|"APIcalls"| E
    E -->|"authenticates"| F
    F -->|"routes"| G
    G -->|"invokes"| H
    H -->|"accesses"| I
    H -->|"connects"| J
    I -->|"CRUDoperations"| K
    J -->|"DBoperations"| K
    E -->|"hostedOn"| L
    F1 -->|"hostedOn"| M

    %% Click Events for Frontend Components
    click A "https://github.com/msami625/recipesnap/tree/main/frontend/src/Pages"
    click B "https://github.com/msami625/recipesnap/tree/main/frontend/src/components"
    click C "https://github.com/msami625/recipesnap/blob/main/frontend/src/services/apiClient.js"
    click D "https://github.com/msami625/recipesnap/blob/main/frontend/tailwind.config.js"

    %% Click Events for Backend Components
    click E "https://github.com/msami625/recipesnap/blob/main/backend/app.js"
    click F "https://github.com/msami625/recipesnap/blob/main/backend/middlewares/authenticate.js"
    click G "https://github.com/msami625/recipesnap/tree/main/backend/routes"
    click H "https://github.com/msami625/recipesnap/tree/main/backend/controllers"
    click I "https://github.com/msami625/recipesnap/tree/main/backend/models"
    click J "https://github.com/msami625/recipesnap/blob/main/backend/utils/database.js"

    %% Class Definitions for Coloring
    classDef frontend fill:#A7D8FF,stroke:#1B7FFF,stroke-width:2px;
    classDef backend fill:#C3FDB8,stroke:#57A773,stroke-width:2px;
    classDef database fill:#FFE6A7,stroke:#FFA500,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px;
```
