Skip to content

Latest commit

 

History

History
140 lines (96 loc) · 3.59 KB

File metadata and controls

140 lines (96 loc) · 3.59 KB

🖥️ Invoice Builder Backend

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.


✨ Features

  • 📄 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

⚙️ Tech Stack

  • 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)

📂 Project Structure

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


🔑 API Endpoints

Invoices

  • GET /api/invoices → list all invoices
  • GET /api/invoices/:id → get invoice by id
  • POST /api/invoices → create new invoice
  • PUT /api/invoices/:id → update invoice
  • DELETE /api/invoices/:id → delete invoice

Clients

  • GET /api/clients → list all clients
  • POST /api/clients → create client
  • PUT /api/clients/:id → update client
  • DELETE /api/clients/:id → delete client

Products

  • GET /api/products → list all products
  • POST /api/products → create product
  • PUT /api/products/:id → update product
  • DELETE /api/products/:id → delete product

Company

  • GET /api/company → get company profile
  • PUT /api/company → update company profile

🚀 Getting Started

1. Clone & Install

git clone https://github.com/yourusername/invoice-builder-backend.git
cd invoice-builder-backend
npm install

2. Setup Environment

Create a .env file in the root:

PORT=5000
MONGO_URI=your_mongodb_connection_string

3. Run Server

npm run dev   # with nodemon

Server runs at: http://localhost:5000


📌 Notes

  • 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


🤝 What I Learned

  • 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


⚠️ Limitations & Future Improvements

  • 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 userId field to models to isolate data