Skip to content

TheMercury1229/ai-invoice-generator-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project name

AI Invoice Generator

Table of contents


Tech stack

  • Backend: Node.js, Express, MongoDB (Mongoose)
  • Frontend: React (Vite), TailwindCSS
  • Auth: JSON Web Tokens (JWT)
  • AI: Google GenAI client (optional - used for invoice extraction/AI-assisted features)

Prerequisites

  • Node.js v18+ (recommended)
  • npm (or yarn)
  • MongoDB (local, Docker, or a cloud provider like MongoDB Atlas)

Environment configuration

You need to create .env files for the API (and optionally the client if you want environment-specific behavior).

API (api/.env)

Create a file at api/.env with the following variables:

PORT=5000
MONGO_URI=mongodb://localhost:27017/invoice-generator
JWT_SECRET=your_jwt_secret_here
GOOGLE_API_KEY=optional_google_genai_key
  • PORT — port to run the API on (default 5000)
  • MONGO_URI — your MongoDB connection string
  • JWT_SECRET — secret used to sign JWT tokens for auth
  • GOOGLE_API_KEY — optional key for AI features

Client (client/.env)

Vite exposes env variables prefixed with VITE_. Create client/.env for local dev if you want to point the frontend to a non-default API host.

VITE_API_BASE_URL=http://localhost:5000/api

If you don't set this, the client uses relative paths configured in src/utils/axiosInstance.js.

Setup & Run (Development)

From the repository root run the backend and the frontend in separate terminals.

API

cd api
npm install
npm run dev
  • npm run dev starts the server with nodemon for hot reload.

Client

cd client
npm install
npm run dev
  • Open the URL Vite prints (usually http://localhost:5173) to view the app.

Build & Run (Production)

Build the client and serve it with a static server, or host separately.

Build client

cd client
npm run build

Start API in production

cd api
npm install --production
npm start

The production flow depends on your hosting choice. You can also serve the client build from the API server by adding a static middleware — not included by default.

API Endpoints (overview)

  • POST /api/auth/register — register new user
  • POST /api/auth/login — login and get JWT
  • GET /api/invoices — list user's invoices
  • POST /api/invoices — create invoice
  • GET /api/invoices/:id — get invoice by ID
  • PATCH /api/invoices/:id — update invoice
  • DELETE /api/invoices/:id — delete invoice

Check api/src/controllers and api/src/routes for the exact implementations and request/response bodies.

Troubleshooting

  • If the client can't reach the API, verify VITE_API_BASE_URL or axios instance base url.
  • If JWT errors occur, ensure JWT_SECRET in .env matches and that tokens are sent in the Authorization: Bearer <token> header.
  • If items are not returned, verify the API's Invoice model has items defined as an array (see api/src/models/invoice.model.js).

Contributing

  • Fork the repo, create a branch, open a PR with clear changes and tests.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages