REST API for LedgerFlow, a full-stack financial management application developed as the Final Project for the Ironhack Web Development Bootcamp.
The API handles authentication, users, clients, invoices, expenses, categories, and dashboard financial data.
https://ledgerflow-api-lfry.onrender.com/
https://ledger-flow-frontend-three.vercel.app/
- Backend: https://github.com/AndreRibeiro24/LedgerFlow-Backend
- Frontend: https://github.com/AndreRibeiro24/LedgerFlow-Frontend
- Node.js โ Server-side JavaScript runtime
- Express 5 โ REST API framework
- MongoDB โ NoSQL database
- MongoDB Atlas โ Cloud database hosting
- Mongoose โ MongoDB object modelling and schema validation
- JSON Web Token (JWT) โ Authentication
- bcrypt โ Password hashing
- CORS โ Cross-origin request handling
- Morgan โ HTTP request logging
- dotenv โ Environment variable management
- Nodemon โ Development server auto-reloading
React Frontend
โ
โ HTTPS / Axios
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Express REST API โ
โ โ
โ Routes โ
โ โ โ
โ Middleware โ
โ โ โ
โ Controllers โ
โ โ โ
โ Mongoose Models โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
MongoDB Atlas
The backend follows a modular structure separating:
- Routes
- Controllers
- Models
- Middleware
- Database configuration
server/
โโโ config/
โ โโโ db.js
โ
โโโ controllers/
โ โโโ auth.controller.js
โ โโโ category.controller.js
โ โโโ client.controller.js
โ โโโ dashboard.controller.js
โ โโโ expense.controller.js
โ โโโ invoice.controller.js
โ
โโโ middleware/
โ โโโ auth.middleware.js
โ โโโ error.middleware.js
โ
โโโ models/
โ โโโ Category.model.js
โ โโโ Client.model.js
โ โโโ Expense.model.js
โ โโโ Invoice.model.js
โ โโโ User.model.js
โ
โโโ routes/
โ โโโ auth.routes.js
โ โโโ categories.routes.js
โ โโโ clients.routes.js
โ โโโ dashboard.routes.js
โ โโโ expenses.routes.js
โ โโโ invoices.routes.js
โ
โโโ app.js
โโโ server.js
LedgerFlow uses JWT authentication.
When registering:
- Required fields are validated.
- The API checks whether the user already exists.
- Password strength requirements are validated.
- The password is hashed using bcrypt.
- The user is stored in MongoDB.
When logging in:
- The API searches for the user by email.
- The account status is verified.
- bcrypt compares the submitted password with the stored hash.
- A JWT is generated after successful authentication.
Protected endpoints expect:
Authorization: Bearer <token>The authentication middleware verifies the token and makes the authenticated user's information available to subsequent controllers.
The API implements several security and validation mechanisms:
- Password hashing with bcrypt
- Password complexity requirements
- JWT-based authentication
- Protected API routes
- Resource ownership validation
- Required field validation
- Mongoose schema validation
- Duplicate user detection
- Duplicate client tax number detection
- Duplicate invoice number detection
- Duplicate category detection
- Client ownership validation for invoices
- Inactive user account validation
- Centralized Express error handling
- Environment variables for sensitive configuration
Sensitive values such as database credentials and JWT secrets are never committed to source control.
Application resources are associated with the authenticated user through an owner field.
For example:
const owner = req.user.userId;Database operations include the owner when searching for resources:
const client = await Client.findOne({
_id: id,
owner: req.user.userId
});This prevents authenticated users from reading, updating, or deleting resources belonging to another account.
Base production URL:
https://ledgerflow-api-lfry.onrender.com/api
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /auth/register |
Register a new user | No |
| POST | /auth/login |
Authenticate user | No |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /clients |
Get all user clients | Yes |
| GET | /clients/:id |
Get client by ID | Yes |
| POST | /clients |
Create client | Yes |
| PUT | /clients/:id |
Update client | Yes |
| DELETE | /clients/:id |
Delete client | Yes |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /invoices |
Get all user invoices | Yes |
| GET | /invoices/:id |
Get invoice by ID | Yes |
| POST | /invoices |
Create invoice | Yes |
| PUT | /invoices/:id |
Update invoice | Yes |
| DELETE | /invoices/:id |
Delete invoice | Yes |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /expenses |
Get all user expenses | Yes |
| GET | /expenses/:id |
Get expense by ID | Yes |
| POST | /expenses |
Create expense | Yes |
| PUT | /expenses/:id |
Update expense | Yes |
| DELETE | /expenses/:id |
Delete expense | Yes |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /categories |
Get all user categories | Yes |
| GET | /categories/:id |
Get category by ID | Yes |
| POST | /categories |
Create category | Yes |
| PUT | /categories/:id |
Update category | Yes |
| DELETE | /categories/:id |
Delete category | Yes |
The dashboard API provides aggregated data for the authenticated user, including:
- Financial summary
- Invoice status distribution
- Recent invoices
- Recent expenses
- Expenses grouped by category
Stores account and authentication information.
Main fields:
name
email
password
role
isActive
Stores customer information and is associated with its owner.
Main fields:
name
email
phone
taxNumber
address
notes
owner
isActive
Stores invoice information and its associated client.
Main information includes:
invoiceNumber
client
owner
issueDate
dueDate
currency
items
subtotal
taxTotal
total
billingDetails
issuerDetails
notes
status
Stores business expenses.
Main information includes:
description
amount
date
category
paymentMethod
notes
owner
Stores custom expense categories associated with the authenticated user.
Main fields:
name
owner
The API uses MongoDB/Mongoose queries and aggregation pipelines to generate dashboard information.
Examples include:
- Counting clients, invoices, and expenses
- Calculating paid invoice revenue
- Calculating total expenses
- Calculating profit
- Grouping invoices by status
- Grouping expenses by category
- Retrieving the five most recent invoices
- Retrieving the five most recent expenses
Invoices support:
EUR
USD
GBP
Currency is stored at invoice level.
The current dashboard aggregates numerical invoice totals without performing foreign exchange conversion.
Automatic currency conversion and configurable base currencies are planned as future improvements.
Make sure you have:
- Node.js
- npm
- MongoDB Community Server or access to MongoDB Atlas
git clone https://github.com/AndreRibeiro24/LedgerFlow-Backend.git
cd LedgerFlow-Backendnpm installCreate a .env file in the project root:
PORT=5005
MONGO_URL=your_mongodb_connection_string
JWT_SECRET=your_jwt_secretNever commit the .env file to source control.
npm run devThe API will be available locally at:
http://localhost:5005
npm startnpm run devStarts the API using Nodemon for development.
npm startStarts the API using Node.js.
The backend is deployed using Render.
Production architecture:
Vercel Frontend
โ
โผ
Render Express API
โ
โผ
MongoDB Atlas
Production secrets such as MONGO_URL and JWT_SECRET are configured using Render environment variables.
MongoDB Atlas Network Access is configured to allow connections from the deployed backend.
Possible future backend improvements include:
- Automatic foreign exchange conversion
- Configurable base currency
- Advanced financial reporting
- PDF invoice generation
- Notification and reminder system
- User/business settings
- Administrative functionality
- Advanced filtering and pagination
- Additional analytics endpoints
- Automated testing
Andrรฉ Ribeiro
Final Project โ Ironhack Web Development Bootcamp
Backend Repository:
https://github.com/AndreRibeiro24/LedgerFlow-Backend
Frontend Repository:
https://github.com/AndreRibeiro24/LedgerFlow-Frontend
Live Application:
https://ledger-flow-frontend-three.vercel.app/
Backend API:
https://ledgerflow-api-lfry.onrender.com/