# pratham2994/streamlined architecture

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

- Interactive diagram: https://gitdiagram.com/pratham2994/streamlined
- Repository: https://github.com/pratham2994/streamlined

## Overview

##### Main Components
- Frontend: Built with React and Material UI, this component includes the UI, routing logic (protected routes), state management with Context API, and visual effects (Framer Motion and particles background).
- Backend: An Express application that handles API endpoints, authentication (JWT), order management, cart logic, and admin functionalities.
- Database: Uses MongoDB with Mongoose for storing users, products, orders, and cart details.
- External Services:
◦ Notification Service that integrates NodeMailer for email notifications.
◦ Notification Service integration with Twilio for WhatsApp notifications.
- Security & Middleware: JWT authentication, rate limiting, Helmet for security headers, and auth middleware to ensure hygiene in API requests.

##### Parts of the File Structure
- Backend Components:
- Config (e.g., db.js) indicates database connection setups.
- Controllers (cartController.js, orderController.js, productController.js, userController.js) show that the logic is segregated per domain, implying a RESTful API design.
- Routes (cartRoutes.js, orderRoutes.js, productRoutes.js, userRoutes.js) reflect how the API endpoints are organized.
- Models (cart.js, orders.js, product.js, users.js) demonstrate the schema definitions for MongoDB.
- Middleware (authMiddleware.js) signals security measures and request validations.
- Services (notificationService.js) encapsulate external notification functionality.
- The server.js file is the central point initiating the Express app.
- Frontend Components:
- The src folder includes the main App and various components (AdminHome, CustomerHome, Navbar, etc.) to handle different user roles.
- There are dedicated components for functionality like order tracking (HorizontalTimeline), modals, and a dynamic background.
- Context folder for managing global state (AuthContext) which assists in maintaining user session data and role-based access.

- A Frontend block labeled “React Frontend” with sub-components such as UI Components (AdminHome, CustomerHome, etc.), Routing (ProtectedRoute), and State Management (AuthContext).
- A Backend block labeled “Express/MongoDB Backend” containing sub-components for Controllers, Routes, Models, Middleware, and Services (notificationService.js).
- A Database block labeled “MongoDB” connecting to the backend’s models.
- External Services block for “Email (NodeMailer)” and “WhatsApp (Twilio)”.

##### Important Architectural Patterns and Design Principles
- Separation of concerns by clearly segregating the frontend and backend components.
- Use of RESTful API design in the backend, wherein controllers and routes are neatly organized per resource (users, orders, cart, products).
- Role-based access control in the frontend (using protected routes) as well as in the backend (using authMiddleware).
- Integration points for external services, illustrating how external dependencies (email and WhatsApp notifications) fit into the order processing lifecycle.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        A["React Frontend"]:::frontend
        B["UI Components & Routing"]:::frontend
        C["Auth Context (Global State)"]:::state
    end

    %% Backend Layer
    subgraph "Backend Layer"
        D["Express/MongoDB Server"]:::backend
        subgraph "Controllers"
            D1["RESTful Controllers"]:::backend
        end
        subgraph "Routes"
            D2["API Routes"]:::backend
        end
        subgraph "Models"
            D3["Database Models"]:::backend
        end
        subgraph "Middleware & Security"
            D4["Auth & Security Middleware"]:::backend
        end
        subgraph "Services"
            D5["Notification Services"]:::backend
        end
    end

    %% Database Layer
    E["MongoDB Database"]:::database

    %% External Services
    subgraph "External Services"
        F["Email Service (NodeMailer)"]:::external
        G["WhatsApp Service (Twilio)"]:::external
    end

    %% Connections
    A -->|"API_Call"| D
    D -->|"Delegates_to"| D1
    D -->|"Routes_via"| D2
    D -->|"Secured_by"| D4
    D -->|"Uses_Models"| D3
    D -->|"Invokes"| D5
    D3 -->|"Stores_Data"| E
    D5 -->|"Emails_via"| F
    D5 -->|"WhatsApp_via"| G
    B --> A
    C --> A

    %% Click Events
    click A "https://github.com/pratham2994/streamlined/blob/main/frontend/src/App.jsx"
    click C "https://github.com/pratham2994/streamlined/blob/main/frontend/src/context/AuthContext.jsx"
    click D "https://github.com/pratham2994/streamlined/blob/main/backend/server.js"
    click D3 "https://github.com/pratham2994/streamlined/tree/main/backend/models"
    click D1 "https://github.com/pratham2994/streamlined/tree/main/backend/controllers"
    click D2 "https://github.com/pratham2994/streamlined/tree/main/backend/routes"
    click D4 "https://github.com/pratham2994/streamlined/blob/main/backend/middleware/authMiddleware.js"
    click D5 "https://github.com/pratham2994/streamlined/blob/main/backend/services/notificationService.js"
    click E "https://github.com/pratham2994/streamlined/blob/main/backend/config/db.js"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef state fill:#ff9,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccf,stroke:#333,stroke-width:2px;
    classDef database fill:#cfc,stroke:#333,stroke-width:2px;
    classDef external fill:#fc9,stroke:#333,stroke-width:2px;
```
