# yuvraj-110/easyinvoice architecture

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

- Interactive diagram: https://gitdiagram.com/yuvraj-110/easyinvoice
- Repository: https://github.com/yuvraj-110/easyinvoice

## Overview

##### Project Type and Purpose
- This is a full-stack invoicing web application (“EasyInvoice”) that lets authenticated users create, preview, and send styled PDF invoices.
- On the client side, it uses a React/Vite/Tailwind setup. On the server side, it uses Node.js with Express, Mongoose models, custom controllers, and utilities for PDF generation and email delivery.

##### File‐Structure Analysis
- Top‐level split into `client/` (frontend) and `server/` (backend).
- Frontend: React components, pages, custom hooks, context for auth state, axios wrapper for API calls, Tailwind config, Vite config.
- Backend: Express `routes/` wiring to `controllers/`, `models/` (User, Business, Invoice), `middleware/` (auth guarding routes), `templates/` (HTML invoice templates), `utils/` (PDF buffer generation, email sending, scheduled tasks).
- Common config: `.env` files, package manifests, build configs.

##### Key Architectural Patterns
- Client‐Server separation via a RESTful API.
- MVC‐style on the server: Routes → Controllers → Models → Database.
- Context + React Router + ProtectedRoute for client‐side auth flow.
- Utility modules for cross-cutting concerns (email, PDF gen, cron tasks).

##### Main Components and Interactions
a. Frontend Application
- React SPA served from Vite/Web server
- Components/pages call `api/authApi.js` or invoice APIs via axios
- AuthContext holds JWT / session info
- UI modules for invoice creation, preview, template selection
b. Backend API
- Express server listens for REST calls (/api/auth, /api/business, /api/invoices)
- `authController` issues/validates JWT, `businessController` CRUD, `invoiceController` CRUD + PDF/email
- Middleware `auth.js` protects invoice/business routes
c. Database
- MongoDB (via Mongoose) stores Users, Businesses, Invoices
d. File Storage
- `server/uploads/` for file assets (e.g., logo uploads)
- Generated PDF buffers may be persisted or streamed directly
e. External Services
- Email SMTP/SendGrid for sending invoices
- (Optional) Cron scheduler triggering `updateOverdueInvoices.js`

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    User["User"]:::external

    %% Frontend Layer
    subgraph "Frontend (client/)"
        direction TB
        FEApp["React SPA"]:::frontend
        subgraph "API Wrappers (client/src/api/)"
            direction TB
            AxiosInst["axios instance"]:::frontend
            AuthAPI["authApi.js"]:::frontend
        end
        subgraph "Auth State"
            direction TB
            AuthCtx["AuthContext"]:::frontend
            UseAuth["useAuth hook"]:::frontend
        end
        ProtectedRoute["ProtectedRoute"]:::frontend
        subgraph "UI Components (client/src/components/)"
            direction TB
            CreateInv["CreateInvoice.jsx"]:::frontend
            InvPreview["InvoicePreview.jsx"]:::frontend
            InvTemplateSel["InvoiceTemplate.jsx"]:::frontend
            subgraph "Templates"
                direction TB
                ClassicTemp["ClassicInvoice.jsx"]:::frontend
                ElegantTemp["ElegantInvoiceForm.jsx"]:::frontend
                MinimalTemp["MinimalInvoice.jsx"]:::frontend
            end
            subgraph "Preview Variants"
                direction TB
                PreviewVars["InvoicePreviews"]:::frontend
            end
        end
        subgraph "Pages & Dashboard (client/src/pages/)"
            direction TB
            DashboardPage["Dashboard.jsx"]:::frontend
            subgraph "Dashboard Components"
                direction TB
                BusinessDash["BusinessDashboard.jsx"]:::frontend
                InvList["InvoicesList.jsx"]:::frontend
            end
        end
    end

    %% Backend Layer
    subgraph "Backend (server/)"
        direction TB
        EntryPoint["index.js"]:::backend
        subgraph "Routes (server/routes/)"
            direction TB
            AuthRoutes["auth.js"]:::backend
            BusinessRoutes["businessRoutes.js"]:::backend
            InvoiceRoutes["invoiceRoutes.js"]:::backend
        end
        AuthMw["auth middleware"]:::backend
        subgraph "Controllers (server/controllers/)"
            direction TB
            AuthCtrl["authController.js"]:::backend
            BusinessCtrl["businessController.js"]:::backend
            InvoiceCtrl["invoiceController.js"]:::backend
        end
        subgraph "Models (server/models/)"
            direction TB
            UserModel["User.js"]:::backend
            BusinessModel["businessModel.js"]:::backend
            InvoiceModel["Invoice.js"]:::backend
        end
        subgraph "Templates (server/templates/)"
            direction TB
            ClassicHTML["classic.html"]:::backend
            ElegantHTML["elegant.html"]:::backend
            MinimalHTML["minimal.html"]:::backend
        end
        subgraph "Utils (server/utils/)"
            direction TB
            GenPDF["generateInvoiceBuffer.js"]:::backend
            SendEmail["sendEmail.js"]:::backend
            UpdateCron["updateOverdueInvoices.js"]:::backend
        end
        Uploads["File Storage (uploads/)"]:::storage
    end

    %% Database & External
    MongoDB["MongoDB"]:::storage
    EmailSvc["Email Service (SMTP)"]:::external

    %% Flows
    User -->|"interacts with"| FEApp
    FEApp -->|"uses"| AuthCtx
    FEApp -->|"calls"| AxiosInst
    AxiosInst -->|"GET/POST /api/auth"| AuthAPI
    FEApp -->|"protected by"| ProtectedRoute
    FEApp -->|"renders"| CreateInv & InvPreview & InvTemplateSel & DashboardPage
    FEApp -->|"fetches templates"| PreviewVars & ClassicTemp & ElegantTemp & MinimalTemp

    AuthAPI -->|"HTTP requests"| EntryPoint
    EntryPoint --> AuthRoutes & BusinessRoutes & InvoiceRoutes
    AuthRoutes -->|"calls"| AuthCtrl
    BusinessRoutes -->|"calls"| BusinessCtrl
    InvoiceRoutes -->|"calls"| InvoiceCtrl
    AuthRoutes --> AuthMw
    BusinessRoutes --> AuthMw
    InvoiceRoutes --> AuthMw

    AuthCtrl -->|"queries"| UserModel
    BusinessCtrl -->|"CRUD"| BusinessModel
    InvoiceCtrl -->|"CRUD"| InvoiceModel
    InvoiceCtrl --> GenPDF
    GenPDF --> Templates
    GenPDF --> Uploads
    InvoiceCtrl --> SendEmail
    SendEmail --> EmailSvc

    InvoiceModel --> MongoDB
    BusinessModel --> MongoDB
    UserModel --> MongoDB

    UpdateCron -->|"runs periodically"| GenPDF & InvoiceModel
    UpdateCron --> MongoDB

    %% Click Events
    click FEApp "https://github.com/yuvraj-110/easyinvoice/tree/main/client/"
    click AxiosInst "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/api/axios.js"
    click AuthAPI "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/api/authApi.js"
    click AuthCtx "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/context/AuthContext.jsx"
    click UseAuth "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/hooks/useAuth.js"
    click ProtectedRoute "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/components/ProtectedRoute.jsx"
    click CreateInv "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/components/CreateInvoice.jsx"
    click InvPreview "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/components/InvoicePreview.jsx"
    click InvTemplateSel "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/components/InvoiceTemplate.jsx"
    click ClassicTemp "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/components/InvoiceTemplates/ClassicInvoice.jsx"
    click ElegantTemp "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/components/InvoiceTemplates/ElegantInvoiceForm.jsx"
    click MinimalTemp "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/components/InvoiceTemplates/MinimalInvoice.jsx"
    click PreviewVars "https://github.com/yuvraj-110/easyinvoice/tree/main/client/src/components/InvoicePreviews/"
    click DashboardPage "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/pages/Dashboard.jsx"
    click BusinessDash "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/components/dashboard/BusinessDashboard.jsx"
    click InvList "https://github.com/yuvraj-110/easyinvoice/blob/main/client/src/components/dashboard/Invoices/InvoicesList.jsx"
    click EntryPoint "https://github.com/yuvraj-110/easyinvoice/blob/main/server/index.js"
    click AuthRoutes "https://github.com/yuvraj-110/easyinvoice/blob/main/server/routes/auth.js"
    click BusinessRoutes "https://github.com/yuvraj-110/easyinvoice/blob/main/server/routes/businessRoutes.js"
    click InvoiceRoutes "https://github.com/yuvraj-110/easyinvoice/blob/main/server/routes/invoiceRoutes.js"
    click AuthCtrl "https://github.com/yuvraj-110/easyinvoice/blob/main/server/controllers/authController.js"
    click BusinessCtrl "https://github.com/yuvraj-110/easyinvoice/blob/main/server/controllers/businessController.js"
    click InvoiceCtrl "https://github.com/yuvraj-110/easyinvoice/blob/main/server/controllers/invoiceController.js"
    click UserModel "https://github.com/yuvraj-110/easyinvoice/blob/main/server/models/User.js"
    click BusinessModel "https://github.com/yuvraj-110/easyinvoice/blob/main/server/models/businessModel.js"
    click InvoiceModel "https://github.com/yuvraj-110/easyinvoice/blob/main/server/models/Invoice.js"
    click AuthMw "https://github.com/yuvraj-110/easyinvoice/blob/main/server/middleware/auth.js"
    click ClassicHTML "https://github.com/yuvraj-110/easyinvoice/blob/main/server/templates/classic.html"
    click ElegantHTML "https://github.com/yuvraj-110/easyinvoice/blob/main/server/templates/elegant.html"
    click MinimalHTML "https://github.com/yuvraj-110/easyinvoice/blob/main/server/templates/minimal.html"
    click GenPDF "https://github.com/yuvraj-110/easyinvoice/blob/main/server/utils/generateInvoiceBuffer.js"
    click SendEmail "https://github.com/yuvraj-110/easyinvoice/blob/main/server/utils/sendEmail.js"
    click UpdateCron "https://github.com/yuvraj-110/easyinvoice/blob/main/server/utils/updateOverdueInvoices.js"
    click Uploads "https://github.com/yuvraj-110/easyinvoice/tree/main/server/uploads/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef backend fill:#d4edda,stroke:#155724,color:#155724;
    classDef storage fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external fill:#f5c6cb,stroke:#721c24,color:#721c24;
```
