A RESTful backend API for the Invoice Builder full-stack project.
Built with Node.js, Express.js, and MongoDB, this backend handles invoices, clients, products, and company profiles, with validation, snapshotting, and automatic totals calculation.
-
📄 Invoice Management
- Create, edit, delete, and fetch invoices
- Snapshot client & company details inside invoices
- Automatic calculation of subtotal, taxes, fees, and grand total
- Invoice status tracking (Draft, Paid, Unpaid)
-
👥 Client Management
- Add, edit, delete, and fetch clients
- Autofill invoices with saved client info
-
📦 Product Management
- Add, edit, delete, and fetch products
- Reuse products in invoices for consistency
-
🏢 Company Management
- Store business details and logo
- Used as default company profile in invoices
-
🧮 Smart Calculations
- Real-time subtotal, tax, fee, and total calculation on server side
- Ensures consistent results between frontend and backend
- ⚡ Node.js + Express.js (REST API)
- 🍃 MongoDB + Mongoose (database & schema validation)
- 🔐 dotenv (environment variables)
- 🔄 CORS (cross-origin requests for frontend integration)
- 🛠 Nodemon (dev auto-reload)
backend/ ┣ 📂 controllers/ # Business logic for invoices, clients, products, company ┣ 📂 models/ # Mongoose schemas ┣ 📂 routes/ # Express routers for each resource ┣ 📂 utils/ # Helper functions (e.g., totals calculation) ┣ server.js # App entry point ┣ package.json ┗ README.md
GET /api/invoices→ list all invoicesGET /api/invoices/:id→ get invoice by idPOST /api/invoices→ create new invoicePUT /api/invoices/:id→ update invoiceDELETE /api/invoices/:id→ delete invoice
GET /api/clients→ list all clientsPOST /api/clients→ create clientPUT /api/clients/:id→ update clientDELETE /api/clients/:id→ delete client
GET /api/products→ list all productsPOST /api/products→ create productPUT /api/products/:id→ update productDELETE /api/products/:id→ delete product
GET /api/company→ get company profilePUT /api/company→ update company profile
git clone https://github.com/yourusername/invoice-builder-backend.git
cd invoice-builder-backend
npm installCreate a .env file in the root:
PORT=5000
MONGO_URI=your_mongodb_connection_stringnpm run dev # with nodemonServer runs at: http://localhost:5000
-
Backend is designed to integrate with the Invoice Builder Frontend
-
Totals are always computed on backend for consistency
-
Client & Company snapshots are stored inside invoices for history
-
Structuring a modular Node.js + Express API
-
Designing Mongoose schemas with nested snapshots
-
Handling calculated fields on server instead of frontend only
-
Building a backend ready for full-stack integration
-
Authentication/authorization not implemented yet
-
All data is stored in a shared MongoDB collection, so multiple users see the same data
-
Plan: add JWT-based authentication and
userIdfield to models to isolate data