How yuvraj-110/easyinvoice works
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