# armin1723/crm-grocery architecture

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

- Interactive diagram: https://gitdiagram.com/armin1723/crm-grocery
- Repository: https://github.com/armin1723/crm-grocery

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“CRM Grocery”) for grocery-store operations: inventory, sales, suppliers, customers.
- It consists of a React/Tailwind frontend (“client/”) and an Express/Node backend (“server/”) talking to MongoDB.

##### File Structure
- client/ – React SPA
– src/components, pages, hooks, context, redux – UI, state, routing
– public/ – static assets, redirect rules
– config files – tailwind, ESLint, Vite
- server/ – Node/Express API
– controllers/, routes/, models/ – MVC structure
– middleware/ – auth (JWT), error handling
– config/ – Cloudinary, DB connection
– templates/ – email & invoice generation
– crons/ – scheduled jobs (low-stock alerts, cache loads)
- support-backend/ & support-frontend/ – separate support ticket microservice (similar full-stack)

##### README Insights
- Frontend: React.js + TailwindCSS + Context API + React Router
- Backend: Node.js + Express + MongoDB + JWT
- Features: real-time stock alerts (cron jobs), email notifications, PDF invoices

##### Main Components & Interactions
a. Frontend (React App)
– UI Components (Inventory, Sales, Reports, Auth)
– State Management: Context API & Redux slices (theme, user)
– Routes: React Router for pages (Auth, Home, Seller)
– HTTP Client (fetch/axios) → REST API
b. Backend (Express API)
– REST Endpoints (auth, inventory, sales, reports, support)
– Controllers → business logic
– Models (Mongoose) → MongoDB collections
– Middleware → JWT auth, error handling, authorization
– Cron jobs → scheduled tasks (inventory alerts, subscription cache)
– Email Service → template rendering → SMTP/third-party
– Cloudinary → media uploads (e.g., product images)
– PDF Generation → invoice templates → temporary storage
c. Database
– MongoDB cluster (Atlas or local)
– Collections: users, products, inventory, sales, purchases, suppliers, customers, support tickets, etc.
d. External Services
– Cloudinary for file storage
– Email provider (SMTP/SendGrid) for notifications
– (Optional) Payment gateway or analytics if integrated

##### Architectural Patterns & Design Principles
- Frontend: component-based architecture, separation of concerns (shared vs domain-specific components), global vs local state
- Backend: MVC (models, controllers, routes), middleware pipeline, configuration abstraction
- Cron jobs as background workers within the same service
- Separation of concerns between CRM app and support microservice

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        ReactApp["React SPA"]:::frontend
        UIComponents["UI Components"]:::frontend
        StateContext["Context API"]:::frontend
        StateRedux["Redux State"]:::frontend
        Routing["App Routing"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        ExpressAPI["Express API Service"]:::backend
        Routes["API Routes"]:::backend
        Controllers["API Controllers"]:::backend
        Models["Data Models"]:::backend
        Middleware["Middleware (Auth, Error)"]:::backend
        CronJobs["Scheduled Cron Jobs"]:::backend
        CloudinaryCfg["Cloudinary Config"]:::backend
        EmailEngine["Email Template Engine"]:::backend
        PDFEngine["PDF Invoice Engine"]:::backend
        Helpers["General Helpers"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MongoDB["MongoDB Cluster"]:::db
    end

    %% Support Microservice
    subgraph "Support Microservice"
        direction TB
        subgraph "Support Frontend"
            SupportFE["Support React SPA"]:::frontend
        end
        subgraph "Support Backend"
            SupportBE["Support API Service"]:::backend
            SRoutes["Support Routes"]:::backend
            SControllers["Support Controllers"]:::backend
            SModels["Support Models"]:::backend
        end
    end

    %% External Services
    CloudinaryExt["Cloudinary Service"]:::external
    EmailExt["Email Provider"]:::external

    %% Connections - Main App
    ReactApp --> UIComponents
    ReactApp --> StateContext
    ReactApp --> StateRedux
    ReactApp --> Routing
    ReactApp -->|"REST/HTTPS"| ExpressAPI
    ExpressAPI --> Routes
    Routes --> Controllers
    Controllers --> Models
    ExpressAPI --> Middleware
    ExpressAPI --> CronJobs
    CronJobs --> Controllers
    ExpressAPI --> CloudinaryCfg
    CloudinaryCfg --> CloudinaryExt
    ExpressAPI --> EmailEngine
    EmailEngine --> EmailExt
    ExpressAPI --> PDFEngine
    ExpressAPI --> Helpers
    ExpressAPI -->|"MongoDB Driver"| MongoDB

    %% Connections - Support Service
    SupportFE -->|"REST/HTTPS"| SupportBE
    SupportBE --> SRoutes
    SRoutes --> SControllers
    SControllers --> SModels
    SModels --> MongoDB

    %% Click Events
    click ReactApp "https://github.com/armin1723/crm-grocery/tree/main/client/"
    click UIComponents "https://github.com/armin1723/crm-grocery/tree/main/client/src/components/"
    click StateContext "https://github.com/armin1723/crm-grocery/tree/main/client/src/context/"
    click StateRedux "https://github.com/armin1723/crm-grocery/tree/main/client/src/redux/"
    click Routing "https://github.com/armin1723/crm-grocery/blob/main/client/src/App.jsx"
    click ExpressAPI "https://github.com/armin1723/crm-grocery/tree/main/server/"
    click Routes "https://github.com/armin1723/crm-grocery/tree/main/server/routes/"
    click Controllers "https://github.com/armin1723/crm-grocery/tree/main/server/controllers/"
    click Models "https://github.com/armin1723/crm-grocery/tree/main/server/models/"
    click Middleware "https://github.com/armin1723/crm-grocery/tree/main/server/middleware/"
    click CronJobs "https://github.com/armin1723/crm-grocery/tree/main/server/crons/"
    click CloudinaryCfg "https://github.com/armin1723/crm-grocery/blob/main/server/config/cloudinary.js"
    click MongoDB "https://github.com/armin1723/crm-grocery/blob/main/server/db.js"
    click EmailEngine "https://github.com/armin1723/crm-grocery/tree/main/server/templates/email/"
    click PDFEngine "https://github.com/armin1723/crm-grocery/tree/main/server/templates/invoice/"
    click Helpers "https://github.com/armin1723/crm-grocery/blob/main/server/helpers/index.js"
    click SupportFE "https://github.com/armin1723/crm-grocery/tree/main/support-frontend/"
    click SupportBE "https://github.com/armin1723/crm-grocery/tree/main/support-backend/"
    click SRoutes "https://github.com/armin1723/crm-grocery/tree/main/support-backend/routes/"
    click SControllers "https://github.com/armin1723/crm-grocery/tree/main/support-backend/controller/"
    click SModels "https://github.com/armin1723/crm-grocery/tree/main/support-backend/models/"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#1E88E5
    classDef backend fill:#C8E6C9,stroke:#43A047
    classDef db fill:#FFE0B2,stroke:#FB8C00
    classDef external fill:#E0E0E0,stroke:#9E9E9E
```
