| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A Comprehensive, Microservices-Based API for Managing Budgets, Expenses, Users, and So Much More!
Welcome to the Budget Management API, a robust, microservices backend platform for managing budgets, expenses, users, orders, and notifications. Built with Node.js, Express, and TypeScript, it supports advanced features like GraphQL, gRPC, WebSockets, and REST APIs.
The API also integrates with PostgreSQL, MongoDB, MySQL, Redis, RabbitMQ, Kafka, and Elasticsearch, and is containerized with Docker and orchestrated using Kubernetes that fully supports zero-downtime deployment (blue/green & canary deployment). It also includes a developer-friendly CLI tool and interactive Swagger/OpenAPI documentation for exploring and testing endpoints.
Below is a very comprehensive guide to setting up, running, and utilizing this API! 💸🚀
The Budget Management API is designed to handle complex budget management requirements, including:
The purpose of this API is to demonstrate the capabilities of modern backend technologies and provide a foundation for building scalable, real-time applications. It can be used as a reference for developers looking to implement similar features in their projects. Simply clone the repository, set up the environment, and start building the frontend or additional functionality on top of the existing API!
The Budget Management API is deployed live at https://budget-management-backend-api.onrender.com.
Additionally, a mock frontend UI is also available, hosted at https://budget-manage-app.vercel.app.
You can access the API and test the endpoints directly from the browser. Feel free to use the API for your own projects or applications. Simply add some attribution to the original repository and the creator. Also, be sure that you use your own credentials and tokens, otherwise your data may clash with mine and other users' data!
Important
Be mindful of the rate limits and usage policies when testing the live API. Additionally, because the API is hosted on the free plan of Render, it may take a while (1-2 minutes) to wake up if it has been inactive for some time. Kindly be patient during this process!
Note
Backup Frontend: https://budget-management-system.netlify.app.
| Technology | Purpose |
|---|---|
| Node.js | Core application framework. |
| Express.js | Web application framework for building APIs. |
| MongoDB | Primary NoSQL database for managing budgets and expenses. |
| PostgreSQL | Relational database for transaction logs. |
| MySQL | Optional relational database support. |
| Redis | In-memory database for caching. |
| RabbitMQ | Message broker for task queuing. |
| Kafka | Distributed event streaming platform. |
| Elasticsearch | Advanced search engine for querying data. |
| gRPC | High-performance remote procedure call framework. |
| GraphQL | Query language for fetching and manipulating data. |
| WebSocket | Real-time communication for notifications. |
| WebAuthn/Passkeys | Passwordless, phishing-resistant authentication (@simplewebauthn). |
| Swagger/OpenAPI | API documentation and testing. |
| Docker | Containerization for easy deployment. |
| Kubernetes | Orchestrating containerized applications at scale. |
| Nginx | Reverse proxy and load balancer. |
| Prometheus | Monitoring and alerting toolkit. |
| Grafana | Observability and visualization platform. |
| Jenkins | CI/CD pipeline for automated testing and deployment. |
The Budget Management API is designed with a microservices architecture, allowing for modular development and deployment. Each service can be developed, deployed, and scaled independently, providing flexibility and resilience.
This architecture allows for easy integration of additional services, such as order management, task management, and notification services, without affecting the core functionality of the API.
Each service communicates with others using RabbitMQ for asynchronous messaging, gRPC for high-performance remote procedure calls, and REST APIs for standard HTTP communication. This ensures that services can operate independently while still being able to interact with each other as needed.
Also, the API is designed to be modular, allowing for easy addition of new services or features without disrupting existing functionality. This modularity is achieved through the use of separate directories for each service, with shared utilities and configurations in a common structure.
Tip
Each service does not live in its own directory, but rather is organized within the main project structure. This allows for easier management and deployment of the entire application as a single unit, while still maintaining the modularity of the microservices architecture.
Note
This diagram illustrates the microservices architecture of the Budget Management API, showing how different services interact with each other and external clients. Each service can be independently developed and deployed, allowing for scalability and maintainability.
Note
This architecture diagram illustrates the modular nature of the Budget Management API, showcasing how different services interact with each other and external clients. It also highlights the use of various technologies such as Docker, Kubernetes, and Nginx for deployment and scaling.
%%{init: {'theme':'base', 'themeVariables': { 'primaryColor':'#4CAF50','primaryTextColor':'#fff','primaryBorderColor':'#2E7D32','lineColor':'#1976D2','secondaryColor':'#2196F3','tertiaryColor':'#FFC107','fontSize':'14px','fontFamily':'Arial'}}}%%
mindmap
root((Budget Management API))
Root Files
.env[.env — Environment variables]
.env.example[.env.example — Sample config]
.gitignore[.gitignore — Git ignore]
.prettierrc[.prettierrc — Code formatter]
LICENSE[LICENSE — License]
README[README.md — Documentation]
cli.js[cli.js — CLI tool]
docker-compose.yml[docker-compose.yml — Docker config]
Dockerfile[Dockerfile — Container image]
grpcServer.js[grpcServer.js — gRPC server]
index.js[index.js — App entry point]
nodemon.json[nodemon.json — Dev config]
openapi.yaml[openapi.yaml — API spec]
package.json[package.json — NPM config]
prometheus.yml[prometheus.yml — Monitoring]
start.sh[start.sh — Startup script]
Tests
__tests__[__tests__/app.test.js — Main tests]
Docs
swaggerConfig[docs/swaggerConfig.js — Swagger]
GraphQL
schema[graphql/schema.js — Schema]
Proto
budget[proto/budget.proto — gRPC proto]
NGINX
docker-compose[nginx/docker-compose.yml]
Dockerfile[nginx/Dockerfile]
nginx.conf[nginx/nginx.conf — Reverse proxy]
start_nginx[nginx/start_nginx.sh]
README[nginx/README.md]
Redis-Mongo Flow
app[redis-mongo-flow/app.js]
config[redis-mongo-flow/config.js]
package[redis-mongo-flow/package.json]
README[redis-mongo-flow/README.md]
seed[redis-mongo-flow/seed.js]
test[redis-mongo-flow/test.js]
Round Robin
config[round-robin/config.js]
index[round-robin/index.js]
README[round-robin/README.md]
Services
dataSeeder[dataSeeder.js — MongoDB seeder]
elastic[elasticService.js — Elasticsearch]
jwt[jwtService.js — JWT helpers]
postgres[postgresService.js — PostgreSQL]
rabbitMQ[rabbitMQService.js — RabbitMQ]
redis[redisService.js — Redis]
websocket[websocketService.js — WebSocket]
Controllers
auth[authController.js — Auth]
budget[budgetController.js — Budget]
customer[customerController.js — Customer]
expense[expenseController.js — Expense]
notification[notificationController.js — Notifications]
order[orderController.js — Order]
search[searchController.js — Search]
task[taskController.js — Task]
transaction[transactionController.js — Transaction]
user[userController.js — User]
Middleware
authMiddleware[authMiddleware.js — JWT auth]
Models
budget[budget.js — Budget schema]
customer[customer.js — Customer schema]
expense[expense.js — Expense schema]
order[order.js — Order schema]
task[task.js — Task schema]
user[user.js — User schema]
Routes
auth[authRoutes.js — Auth]
budget[budgetRoutes.js — Budget]
customer[customerRoutes.js — Customer]
expense[expenseRoutes.js — Expense]
graphql[graphqlRoutes.js — GraphQL]
index[index.js — Router entry]
notification[notificationRoutes.js — Notifications]
order[orderRoutes.js — Order]
search[searchRoutes.js — Search]
task[taskRoutes.js — Task]
transaction[transactionRoutes.js — Transaction]
user[userRoutes.js — User]
Views
icons[android/apple/favicon icons]
home[home.html — Homepage]
manifest[manifest.json — Web manifest]
Other
more[Additional files and directories]
Clone the repository:
git clone https://github.com/hoangsonww/Budget-Management-Backend-API.git
cd Budget-Management-Backend-APIInstall dependencies:
npm installSet up environment variables:
MONGO_DB_URI=mongodb://localhost:27017/budget_manager
POSTGRES_URI=postgres://user:password@localhost:5432/budget_manager
REDIS_URL=redis://localhost:6379
RABBITMQ_URL=amqp://localhost
KAFKA_BROKER=localhost:9092
JWT_SECRET=your_secret_keyStart the application:
npm startAccess the application:
| Endpoint | Method | Description |
|---|---|---|
| /api/auth/register | POST | Register a new user (auto-logs in and returns a JWT). |
| /api/auth/login | POST | Login and receive a JWT token. |
| /api/auth/logout | POST | Logout and invalidate the token. |
| /api/auth/verify-email | POST | Verify the user's email address. |
| /api/auth/reset-password | POST | Reset the user's password. |
| /api/passkeys/login/options | POST | Begin passwordless passkey login (returns options + a one-time flowId). |
| /api/passkeys/login/verify | POST | Complete passkey login and receive a JWT token. |
| /api/passkeys/register/options | POST | Begin passkey registration for the authenticated user. (auth) |
| /api/passkeys/register/verify | POST | Complete passkey registration and store the credential. (auth) |
| /api/passkeys | GET | List the authenticated user's passkeys. (auth) |
| /api/passkeys/:id | PATCH | Rename one of the user's passkeys. (auth) |
| /api/passkeys/:id | DELETE | Delete one of the user's passkeys. (auth) |
| /api/users/profile | GET | Get the authenticated user's profile. |
| /api/budgets | GET | Get all budgets. |
| /api/budgets | POST | Create a new budget. |
| /api/budgets/:id | GET | Get a specific budget. |
| /api/budgets/:id | PUT | Update a budget. |
| /api/budgets/:id | DELETE | Delete a budget. |
| /api/customers | GET | Get all customers. |
| /api/customers | POST | Create a new customer. |
| /api/customers/:id | GET | Get a specific customer. |
| /api/customers/:id | PUT | Update a customer. |
| /api/customers/:id | DELETE | Delete a customer. |
| /api/expenses | GET | Get all expenses. |
| /api/expenses | POST | Add a new expense. |
| /api/expenses/:budgetId | GET | Get all expenses for a budget. |
| /api/expenses/:id | PUT | Update an expense. |
| /api/expenses/:id | DELETE | Delete an expense. |
| /api/orders | GET | Get all orders. |
| /api/orders | POST | Create a new order. |
| /api/orders/:id | GET | Get a specific order. |
| /api/orders/:id | PUT | Update an order. |
| /api/orders/:id | DELETE | Delete an order. |
| /api/transactions | GET | Get all transactions. |
| /api/transactions | POST | Add a new transaction. |
| /api/transactions/:id | GET | Get a specific transaction. |
| /api/transactions/:id | PUT | Update a transaction. |
| /api/transactions/:id | DELETE | Delete a transaction. |
| /api/tasks | GET | Get all tasks. |
| /api/tasks | POST | Add a new task. |
| /api/tasks/:id | GET | Get a specific task. |
| /api/tasks/:id | PUT | Update a task. |
| /api/tasks/:id | DELETE | Delete a task. |
| /api/graphql | POST | Perform a GraphQL query. |
| /api/notifications | POST | Send a real-time notification. |
| /api/search | POST | Search for expenses using Elasticsearch. |
Endpoints marked (auth) require a valid JWT in the Authorization: Bearer <token> header. The two passkey login endpoints are public (they form the passwordless sign-in flow), while passkey registration and management require an existing session so a logged-in user can enroll and manage their own credentials.
Additionally, the root / endpoint provides a welcome message and information about the API.
More endpoints and features are available in the API. Refer to the Swagger documentation for detailed information.
| Field | Type | Description |
|---|---|---|
| username | String | Unique username. |
| String | Unique email address. | |
| password | String | Hashed password. |
| createdAt | Date | User creation date. |
| Field | Type | Description |
|---|---|---|
| name | String | Budget name. |
| limit | Number | Budget limit. |
| createdAt | Date | Budget creation date. |
| Field | Type | Description |
|---|---|---|
| budgetId | String | ID of the associated budget. |
| description | String | Expense description. |
| amount | Number | Expense amount. |
| createdAt | Date | Expense creation date. |
| Field | Type | Description |
|---|---|---|
| customerId | String | ID of the associated customer. |
| amount | Number | Order amount. |
| status | String | Order status. |
| createdAt | Date | Order creation date. |
| Field | Type | Description |
|---|---|---|
| name | String | Customer name. |
| String | Customer email address. | |
| phone | String | Customer phone number. |
| Field | Type | Description |
|---|---|---|
| description | String | Task description. |
| status | String | Task status. |
| createdAt | Date | Task creation date. |
A single WebAuthn credential. A user may own many passkeys. Security-critical fields (credentialID, publicKey, counter) never leave the server; only the metadata below is exposed to the management UI.
| Field | Type | Description |
|---|---|---|
| user | ObjectId | Owning user (reference). |
| name | String | User-friendly label (e.g. "MacBook Touch ID"). |
| deviceType | String | singleDevice or multiDevice (synced). |
| backedUp | Boolean | Whether the credential is synced/backed up (e.g. iCloud Keychain). |
| transports | [String] | Authenticator transports (e.g. internal, hybrid, usb). |
| aaguid | String | Authenticator model identifier (used to suggest a name). |
| createdAt | Date | When the passkey was registered. |
| lastUsedAt | Date | When the passkey was last used to sign in. |
npm startdocker-compose up --buildkubectl apply -f kubernetes/The Budget Management API interacts with various services and databases to provide a comprehensive backend solution. The architecture includes a frontend UI, a CLI tool, an API gateway, a gRPC server, and multiple external services. Here is a high-level overview of the service interaction:
flowchart LR
FE[Frontend UI<br/>]
CLI[CLI Tool / gRPC Clients]
APIGW[API Gateway / Express.js]
GRPC[gRPC Server]
CORE[Application Core<br/>Controllers & Services]
Mongo[MongoDB]
Postgres[PostgreSQL]
Elastic[Elasticsearch]
Redis[Redis Cache]
Queue[RabbitMQ / Kafka Queue]
Stream[Kafka Event Streaming]
External[External Services<br/>Email, SMS, etc.]
FE -->|HTTP / GraphQL requests| APIGW
CLI -->|CLI commands / gRPC calls| GRPC
APIGW <--> GRPC
APIGW -->|REST / WebSocket / GraphQL| CORE
GRPC --> CORE
CORE --> Mongo
CORE --> Postgres
CORE --> Elastic
CORE --> Redis
CORE --> Queue
CORE --> Stream
Queue -->|Asynchronous tasks| External
Stream -->|Event-driven actions| External
Ensure your .env file looks like this before getting started:
# Server Configuration
PORT=
# MongoDB Configuration
MONGO_DB_URI=
MONGO_DB_USERNAME=
MONGO_DB_PASSWORD=
# Redis Configuration
REDIS_HOST=
REDIS_PORT=
REDIS_URL=
# RabbitMQ Configuration
RABBIT_MQ_HOST=
RABBITMQ_URL=
# Kafka Configuration
KAFKA_BROKER=
# JWT Secret Key
JWT_SECRET=
# WebAuthn / Passkey Configuration
# RP_ID: the registrable domain passkeys are bound to (e.g. example.com).
# Leave blank to derive it from the request origin (good for local dev,
# where the frontend on http://localhost:3000 resolves to rpID "localhost").
RP_ID=
# RP_NAME: human-readable relying-party name shown in the OS passkey prompt.
RP_NAME=
# WEBAUTHN_ORIGINS: comma-separated allowlist of frontend origins permitted to
# perform passkey ceremonies (e.g. https://app.example.com,http://localhost:3000).
# Leave blank to trust the request origin (local dev convenience).
WEBAUTHN_ORIGINS=
# Elasticsearch Configuration
ELASTIC_SEARCH_URL=
# PostgreSQL Configuration
POSTGRES_URL=The budget-manager CLI provides a convenient way to interact with the application from the command line.
Follow these steps to use the CLI:
Install globally:
npm linkUse commands:
budget-manager seed
budget-manager notify "Hello!"
budget-manager add-task "Task description"View available commands:
budget-manager --helpThis will display a list of available commands and options:
budget-manager --help
Usage: budget-manager [options] [command]
A CLI for managing budgets, tasks, orders, and more.
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
seed Seed the MongoDB database with initial data
notify <message> Send a real-time notification to WebSocket clients
list-budgets List all budgets in the database
add-task <description> Add a new task to the task queue
list-orders List all orders in the database
add-order <customerId> <amount> Add a new order
list-customers List all customers in the database
add-customer <name> <email> [phone] Add a new customer
search-expenses <query> Search for expenses using a query
graphql-query <query> Perform a GraphQL query
help [command] display help for command
Examples:
$ budget-manager seed
$ budget-manager notify "Hello World!"
$ budget-manager list-budgets
$ budget-manager add-task "New Task Description"
budget-manager --versionThe CLI provides a simple way to interact with the backend API and perform various operations. It can be used for testing, debugging, and managing the application without a frontend interface or using the Swagger documentation.
The Budget Management API includes a demo frontend UI for interacting with the backend.
It gives developers an idea of how the API can be used in a real-world application. The frontend UI is built using React, Redux, and Material-UI components.
To run the frontend UI, follow these steps:
Navigate to the frontend directory:
cd frontendInstall dependencies: (use npm install --legacy-peer-deps if you encounter peer dependency issues)
npm installStart the development server:
npm startAccess the frontend UI at http://localhost:3001 (or whichever port is specified in the console).
Alternatively, it is also deployed live at https://budget-manage-app.vercel.app. Feel free to use the live version for testing and exploration.
For more information, refer to the Frontend README in the frontend directory to learn about the frontend UI components, features, and usage.
Here are some screenshots of the frontend UI:
Home:
Dashboard:
Budgets:
Expenses:
Profile:
Passkeys:
Login:
Register:
Users:
query {
budgets {
id
name
limit
createdAt
}
}Or:
query {
expenses(budgetId: "64c9f8f2a73c2f001b3c68f4") {
id
description
amount
budgetId
createdAt
}
}When you run these queries, you will receive a response with the requested data. GraphQL provides a flexible and efficient way to fetch and manipulate data from the backend. Here is an example:
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}The Budget Management API includes support for gRPC to enable high-performance remote procedure calls.
Start the gRPC Server: Run the following command:
node grpcServer.jsUse the gRPC Client: Execute the client to interact with the server:
node grpcClient.jsProto File: The .proto file for defining gRPC services and messages is located in the protos directory.
That's it! Your gRPC server and client should now be operational. 🚀
The Budget Management API can be run in a Docker container for easy deployment and scaling.
You can build and run the app using Docker Compose:
docker-compose up --buildThe Budget Management API now supports advanced deployment strategies for production-grade deployments:
# Deploy blue and green environments
kubectl apply -f kubernetes/backend-deployment-blue.yaml
kubectl apply -f kubernetes/backend-deployment-green.yaml
kubectl apply -f kubernetes/frontend-deployment-blue.yaml
kubectl apply -f kubernetes/frontend-deployment-green.yaml
# Deploy services
kubectl apply -f kubernetes/backend-service-blue-green.yaml
kubectl apply -f kubernetes/frontend-service-blue-green.yaml
# Apply production-ready configurations
kubectl apply -f kubernetes/hpa.yaml
kubectl apply -f kubernetes/pdb.yaml
kubectl apply -f kubernetes/network-policy.yaml
kubectl apply -f kubernetes/ingress.yaml
kubectl apply -f kubernetes/servicemonitor.yaml
# Switch traffic (after validation)
kubectl patch service backend-service -p '{"spec":{"selector":{"version":"green"}}}'# Deploy stable version (90% traffic)
kubectl apply -f kubernetes/backend-deployment-canary-stable.yaml
kubectl apply -f kubernetes/frontend-deployment-canary-stable.yaml
# Deploy canary version (10% traffic)
kubectl apply -f kubernetes/backend-deployment-canary.yaml
kubectl apply -f kubernetes/frontend-deployment-canary.yaml
# Deploy services
kubectl apply -f kubernetes/backend-service-canary.yaml
kubectl apply -f kubernetes/frontend-service-canary.yaml
# Apply production-ready configurations
kubectl apply -f kubernetes/hpa.yaml
kubectl apply -f kubernetes/pdb.yaml
kubectl apply -f kubernetes/network-policy.yamlFor detailed deployment procedures and best practices, see:
Access metrics at:
View health endpoints:
There is also a Spring Boot Java version of the Budget Management API available in the spring-boot directory. It is built using Maven and Gradle.
To run the Spring Boot Maven application, follow these steps:
Navigate to the spring-boot directory:
cd springBuild the application using Maven:
mvn clean installRun the application:
mvn spring-boot:runAccess the Spring Boot application at http://localhost:8080.
To run the Spring Boot Gradle application, follow these steps:
Navigate to the spring-boot directory:
cd gradleBuild the application using Gradle:
./gradlew buildRun the application:
./gradlew bootRunAccess the Spring Boot application at http://localhost:8080.
There is also a Dotnet C# version of the Budget Management API available in the dotnet directory. It is built using ASP.NET Core.
To run the Dotnet C# application, follow these steps:
Navigate to the dotnet directory:
cd dotnetBuild the application using the .NET CLI:
dotnet buildRun the application:
dotnet runAccess the Dotnet C# application at http://localhost:5000.
The Budget Management API includes an advanced Jenkins pipeline with support for multiple deployment strategies and production-ready features.
Multiple Deployment Strategies:
Comprehensive Testing:
Code Quality Checks:
Docker Integration:
Kubernetes Deployment:
Monitoring and Notifications:
Configure the pipeline with these parameters:
DEPLOYMENT_STRATEGY: blue-green
ENVIRONMENT: production
RUN_SMOKE_TESTS: true
AUTO_ROLLBACK: trueDEPLOYMENT_STRATEGY: canary
ENVIRONMENT: production
CANARY_PERCENTAGE: 10
RUN_SMOKE_TESTS: true
AUTO_ROLLBACK: trueDEPLOYMENT_STRATEGY: rolling
ENVIRONMENT: staging
RUN_SMOKE_TESTS: true
AUTO_ROLLBACK: trueConfigure Credentials in Jenkins:
Create Pipeline Job:
Configure Webhooks:
The Jenkinsfile includes sophisticated deployment functions:
For detailed deployment procedures, see Deployment Guide.
The Budget Management API also includes a GitHub Actions workflow for continuous integration and deployment.
This setup allows for automated testing and deployment, ensuring that the application is always in a deployable state.
The Budget Management API includes unit tests for all endpoints and services.
To run the tests, use the following command:
npm testThe test results will be displayed in the console.
Watch Mode: To run tests in watch mode, which automatically re-runs tests on file changes, use:
npm test:watchCoverage Report: To generate a code coverage report, use:
npm test:coverageMocha and Chai tests: In addition to the Jest tests, the project also includes Mocha and Chai tests for the application. These tests can be run using:
npm run test:mochaContributions are welcome! Please fork the repository, create a feature branch, and submit a pull request:
This project is built with ❤️ by:
For more information about me, you can visit my personal website or connect with me on LinkedIn:
Feel free to reach out if you have any questions or feedback! 🚀
Thank you for using the Budget Management API. For questions, feedback, or support, please open an issue or contact me directly.
Created with ❤️ by Son Nguyen in 2024. All rights reserved.
| Back | FazBrowse Home | New Git URL |