https://github.com/hoangsonww/Budget-Management-Backend-API
π Dive into the world of Node.js, MongoDB, Redis, PostgreSQL, Kafka, RabbitMQ, ELK stack, and more with this comprehensive backend API project! Explore how these powerful technologies can be integrated to build robust, scalable, and efficient backend solutions. Also includes a CLI and a sample React frontend!
https://github.com/hoangsonww/Budget-Management-Backend-API
cli elasticsearch elk-stack express gprc grafana graphql kibana logstash mongo mongodb mongodb-database nginx nodejs postgres postgresql rabbitmq redis redis-cache rest-api
Last synced: about 2 months ago
JSON representation
π Dive into the world of Node.js, MongoDB, Redis, PostgreSQL, Kafka, RabbitMQ, ELK stack, and more with this comprehensive backend API project! Explore how these powerful technologies can be integrated to build robust, scalable, and efficient backend solutions. Also includes a CLI and a sample React frontend!
- Host: GitHub
- URL: https://github.com/hoangsonww/Budget-Management-Backend-API
- Owner: hoangsonww
- License: mit
- Created: 2024-06-23T13:18:43.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-28T22:08:59.000Z (11 months ago)
- Last Synced: 2025-01-28T23:21:45.003Z (11 months ago)
- Topics: cli, elasticsearch, elk-stack, express, gprc, grafana, graphql, kibana, logstash, mongo, mongodb, mongodb-database, nginx, nodejs, postgres, postgresql, rabbitmq, redis, redis-cache, rest-api
- Language: JavaScript
- Homepage: https://hoangsonww.github.io/Budget-Management-Backend-API/
- Size: 5.54 MB
- Stars: 21
- Watchers: 15
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# **Budget Management API - A Comprehensive, Microservices-Based API for Managing Budgets, Expenses, Users, and 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 integrates with **PostgreSQL**, **MongoDB**, **MySQL**, **Redis**, **RabbitMQ**, **Kafka**, and **Elasticsearch**, and is containerized with **Docker** and orchestrated using **Kubernetes**. 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. πΈπ
## **Table of Contents**
1. [Overview](#overview)
2. [Live Deployment](#live-deployment)
3. [Technologies Used](#technologies-used)
- [Microservices Architecture](#microservices-architecture)
- [Microservices Diagram](#microservices-diagram)
- [Full Architecture Diagram](#full-architecture-diagram)
4. [Project Structure](#project-structure)
5. [Setup Instructions](#setup-instructions)
6. [Available Endpoints](#available-endpoints)
7. [Schemas](#schemas)
8. [Features and Integrations](#features-and-integrations)
9. [Environment Variables](#environment-variables)
10. [CLI Usage](#cli-usage)
11. [Demo Frontend UI](#demo-frontend-ui)
12. [Swagger Documentation](#swagger-documentation)
13. [GraphQL Integration](#graphql-integration)
14. [NGINX Configuration](#nginx-configuration)
15. [gRPC Integration](#grpc-integration)
16. [Dockerization](#dockerization)
17. [Kubernetes Deployment](#kubernetes-deployment)
18. [Spring Boot Backends with Gradle & Maven](#spring-boot-backends-with-maven-and-gradle)
19. [Dotnet Backends with C#](#dotnet-backend-with-c-sharp)
20. [Continuous Integration and Deployment with Jenkins](#continuous-integration-and-deployment-with-jenkins)
- [GitHub Actions](#github-actions)
21. [Testing](#testing)
22. [Contributing](#contributing)
23. [Author](#author)
## **Overview**
The Budget Management API is designed to handle complex budget management requirements, including:
- Budget and expense tracking.
- User management and authentication.
- Real-time notifications via WebSockets.
- Asynchronous task handling using RabbitMQ and Kafka.
- Advanced search capabilities with Elasticsearch.
- CLI operations for direct interaction with the system.
- Compatibility with modern cloud environments like Docker and Kubernetes.
- Support for both REST and GraphQL APIs for flexible data access.
- Sample `dotnet` and `spring-boot` backends to demonstrate integration with other technologies.
- ...and so much more!
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!












































## **Live Deployment**
The Budget Management API is deployed live at **[https://budget-management-backend-api.onrender.com](https://budget-management-backend-api.onrender.com).**
Additionally, a mock frontend UI is also available, hosted at **[https://budget-manage-app.vercel.app](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.
### Deployment and Technology Status
[](https://budget-management-backend-api.onrender.com)
[](https://www.mongodb.com/)
[](https://redis.io/)
[](https://www.postgresql.org/)
[](https://www.rabbitmq.com/)
[](https://kafka.apache.org/)
[](https://www.elastic.co/elasticsearch/)
[](https://grpc.io/)
[](https://graphql.org/)
[](https://budget-management-backend-api.onrender.com/docs)
[](https://www.docker.com/)
[](https://kubernetes.io/)
[](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
[](https://www.nginx.com/)
[](https://www.openapis.org/)
[](https://www.jenkins.io/)
[](https://prometheus.io/)
[](https://grafana.com/)
[](https://maven.apache.org/)
[](https://gradle.org/)
[](https://spring.io/projects/spring-boot)
[](https://dotnet.microsoft.com/)
[](https://budget-manage-app.vercel.app)
[](https://budget-management-backend-api.onrender.com)
[](https://budget-management-system.netlify.app)
## **Technologies Used**
| **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. |
| **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. |
### Microservices Architecture
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.
1. **Authentication/User Service**: Handles user registration, login, and JWT token management (+ profile management as well).
2. **Budget Service**: Manages budgets, including creation, updates, and retrieval.
3. **Expense Service**: Manages expenses associated with budgets, including CRUD operations.
4. **Customer Service**: Manages customer data, including creation and updates.
5. **Search Service**: Provides advanced search capabilities using Elasticsearch.
6. **Order Service**: Manages orders, including creation and updates.
7. **Transaction Service**: Logs transactions for budgets and expenses.
8. **Notification Service**: Sends real-time notifications to users via WebSockets.
9. **Task Management Service**: Handles asynchronous tasks using RabbitMQ and Kafka.
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.
#### Communication Between Services
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.
### Microservices Diagram
> [!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.
### Full Architecture Diagram
> [!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.
## **Project Structure**
```plaintext
Budget-Management-Backend-API/
βββ .env # Environment variables configuration
βββ .env.example # Example environment configuration file
βββ .gitignore # Git ignore file
βββ .prettierrc # Prettier configuration for code formatting
βββ LICENSE # License information
βββ README.md # Documentation for the project
βββ __tests__/app.test.js # Main test file for application
βββ cli.js # CLI tool for interacting with the backend
βββ docker-compose.yml # Docker Compose configuration
βββ Dockerfile # Dockerfile for containerizing the application
βββ grpcServer.js # gRPC server implementation
βββ index.js # Main entry point for the application
βββ nodemon.json # Nodemon configuration file
βββ openapi.yaml # OpenAPI specification for the API
βββ package.json # NPM package configuration file
βββ start.sh # Script to start the application
βββ prometheus.yml # Prometheus configuration for monitoring
βββ redis-mongo-flow/ # Directory for Redis-Mongo integration flow
β βββ app.js # Express app for Redis-Mongo flow
β βββ config.js # Configuration for Redis-Mongo flow
β βββ package.json # NPM configuration for this module
β βββ README.md # Documentation specific to Redis-Mongo flow
β βββ seed.js # Data seeder for Redis-Mongo flow
β βββ test.js # Test file for Redis-Mongo flow
βββ round-robin/ # Directory for round-robin load balancer
β βββ config.js # Configuration for round-robin implementation
β βββ index.js # Main entry point for round-robin logic
β βββ README.md # Documentation for round-robin functionality
βββ proto/ # Protocol Buffers directory
β βββ budget.proto # gRPC proto file for budgets
βββ nginx/ # NGINX configuration directory
β βββ docker-compose.yml # Docker Compose for NGINX
β βββ Dockerfile # Dockerfile for NGINX
β βββ nginx.conf # NGINX configuration file
β βββ start_nginx.sh # Script to start NGINX
β βββ README.md # Documentation for NGINX
βββ docs/ # Documentation directory
β βββ swaggerConfig.js # Swagger configuration for API docs
βββ graphql/ # GraphQL-related files
β βββ schema.js # GraphQL schema definition
βββ services/ # Services and utilities
β βββ dataSeeder.js # Seeder for MongoDB
β βββ elasticService.js # Elasticsearch client and utility functions
β βββ jwtService.js # JSON Web Token (JWT) utilities
β βββ postgresService.js # PostgreSQL client and utilities
β βββ rabbitMQService.js # RabbitMQ client and utilities
β βββ redisService.js # Redis client and utilities
β βββ websocketService.js # WebSocket server and utilities
βββ controllers/ # Route controllers for the API
β βββ authController.js # Authentication-related endpoints
β βββ budgetController.js # Budget management endpoints
β βββ customerController.js # Customer management endpoints
β βββ expenseController.js # Expense management endpoints
β βββ notificationController.js # Notification management endpoints
β βββ orderController.js # Order management endpoints
β βββ searchController.js # Search-related endpoints
β βββ taskController.js # Task management endpoints
β βββ transactionController.js # Transaction log endpoints
β βββ userController.js # User profile management endpoints
βββ middleware/ # Middleware utilities
β βββ authMiddleware.js # JWT authentication middleware
βββ models/ # Mongoose schemas
β βββ budget.js # Schema for budgets
β βββ customer.js # Schema for customers
β βββ expense.js # Schema for expenses
β βββ order.js # Schema for orders
β βββ task.js # Schema for tasks
β βββ user.js # Schema for users
βββ routes/ # Express router files
β βββ authRoutes.js # Routes for authentication
β βββ budgetRoutes.js # Routes for budgets
β βββ customerRoutes.js # Routes for customers
β βββ expenseRoutes.js # Routes for expenses
β βββ graphqlRoutes.js # Routes for GraphQL
β βββ index.js # Main router entry point
β βββ notificationRoutes.js # Routes for notifications
β βββ orderRoutes.js # Routes for orders
β βββ searchRoutes.js # Routes for Elasticsearch
β βββ taskRoutes.js # Routes for tasks
β βββ transactionRoutes.js # Routes for transactions
β βββ userRoutes.js # Routes for user profiles
βββ views/ # Static assets and templates
β βββ android-chrome-192x192.png # Android Chrome app icon
β βββ android-chrome-512x512.png # Android Chrome high-res icon
β βββ apple-touch-icon.png # Apple Touch icon
β βββ favicon.ico # Favicon
β βββ favicon-16x16.png # 16x16 favicon
β βββ favicon-32x32.png # 32x32 favicon
β βββ home.html # HTML template for homepage
β βββ manifest.json # Web app manifest
βββ and many more files... # Additional files and directories
```
## **Setup Instructions**
### Prerequisites
- Node.js (>= 16)
- Docker and Docker Compose (if using containerized setup)
- MongoDB, PostgreSQL, MySQL, RabbitMQ, Redis, and Elasticsearch services.
### Local Installation
1. Clone the repository:
```bash
git clone https://github.com/hoangsonww/Budget-Management-Backend-API.git
cd Budget-Management-Backend-API
```
2. Install dependencies:
```bash
npm install
```
3. Set up environment variables:
- Create a `.env` file in the root directory:
```env
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_key
```
- Replace placeholders with your actual configuration.
4. Start the application:
```bash
npm start
```
5. Access the application:
- API: `http://localhost:3000`
- Swagger: `http://localhost:3000/docs`
## **Available Endpoints**
| **Endpoint** | **Method** | **Description** |
|----------------------------|------------|------------------------------------------|
| `/api/auth/register` | POST | Register a new user. |
| `/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/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. |
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](https://budget-management-backend-api.onrender.com/docs) for detailed information.
## **Schemas**
### **User**
| **Field** | **Type** | **Description** |
|-------------|----------|-----------------------------|
| `username` | String | Unique username. |
| `email` | String | Unique email address. |
| `password` | String | Hashed password. |
| `createdAt` | Date | User creation date. |
### **Budget**
| **Field** | **Type** | **Description** |
|-------------|----------|-----------------------------|
| `name` | String | Budget name. |
| `limit` | Number | Budget limit. |
| `createdAt` | Date | Budget creation date. |
### **Expense**
| **Field** | **Type** | **Description** |
|---------------|----------|------------------------------|
| `budgetId` | String | ID of the associated budget. |
| `description` | String | Expense description. |
| `amount` | Number | Expense amount. |
| `createdAt` | Date | Expense creation date. |
### **Order**
| **Field** | **Type** | **Description** |
|--------------|----------|--------------------------------|
| `customerId` | String | ID of the associated customer. |
| `amount` | Number | Order amount. |
| `status` | String | Order status. |
| `createdAt` | Date | Order creation date. |
### **Customer**
| **Field** | **Type** | **Description** |
|-------------|----------|------------------------------|
| `name` | String | Customer name. |
| `email` | String | Customer email address. |
| `phone` | String | Customer phone number. |
### **Task**
| **Field** | **Type** | **Description** |
|---------------|----------|------------------------------|
| `description` | String | Task description. |
| `status` | String | Task status. |
| `createdAt` | Date | Task creation date. |
## **Features and Integrations**
### **gRPC**
- High-performance RPC framework.
- Start the gRPC server using:
```bash
npm start
```
### **GraphQL**
- Flexible data queries and mutations.
- Access the GraphQL endpoint at `http://localhost:3000/graphql`.
### **WebSocket**
- Real-time notifications for clients.
- Notifications can be sent using the `/api/notifications` endpoint or CLI.
### **Docker**
- Build and run the app with Docker:
```bash
docker-compose up --build
```
### **Elasticsearch**
- Advanced search for expenses.
- Search endpoint: `/api/search/expenses`.
### **RabbitMQ**
- Asynchronous task handling.
- Use the `budget-manager` CLI to add tasks.
- Tasks are processed in the background.
### **Kafka**
- Distributed event streaming platform.
- Kafka broker URL: `localhost:9092`.
- Kafka producer and consumer are integrated.
### **Redis**
- In-memory caching for improved performance.
- Redis URL: `redis://localhost:6379`.
- Caching is used for user sessions and other data.
### **PostgreSQL**
- Relational database for transaction logs.
- PostgreSQL URL: `postgres://user:password@localhost:5432/budget_manager`.
- Used for storing transaction logs and other relational data.
- MySQL is also supported as an alternative.
### **MongoDB**
- Primary NoSQL database for managing budgets and expenses.
- MongoDB URL: `mongodb://localhost:27017/budget_manager`.
- Used for storing budgets, expenses, and user data.
### **Nginx**
- Reverse proxy and load balancer.
- Nginx configuration is included in the `nginx` directory.
- Load balancing can be configured for multiple instances.
- SSL termination and caching can be added.
### **Kubernetes**
- Deployment manifests are available in the `kubernetes` directory.
- Deploy the application to a Kubernetes cluster using:
```bash
kubectl apply -f kubernetes/
```
### **Prometheus and Grafana**
- Monitoring and observability tools.
- Prometheus configuration is available in `prometheus.yml`.
- Grafana can be used for visualization and monitoring.
- Metrics and dashboards can be configured.
- Monitor the health and performance of the API.
## **Services Interaction**
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:
```plaintext
+--------------------+ +------------------+
| Frontend UI | | |
| (not impl.) | | CLI Tool / gRPC |
+--------------------+ +------------------+
| |
| HTTP/GraphQL Requests | CLI Commands / gRPC Calls
| |
+--------------------+ +------------------+
| API Gateway / |<--------------->| gRPC Server |
| Express.js | +------------------+
+--------------------+
|
| RESTful API / WebSocket / GraphQL Responses
|
+--------------------+
| Application Core |
|--------------------|
| Controllers / |
| Services |
+--------------------+
| | |
+------+ | +-------------+
| | |
+----------+ +-----------+ +----------------+
| MongoDB | | PostgreSQL | | Elasticsearch |
| NoSQL DB | | Relational | | Search Engine |
+----------+ +-----------+ +----------------+
| | |
| | |
+----------+ +-------------+ +----------------+
| Redis | | RabbitMQ / | | Kafka (Event |
| Cache | | Kafka Queue | | Streaming) |
+----------+ +-------------+ +----------------+
| | |
+--------------|-(Asynchronous Tasks)---+
|
+----------------------+
| External Services |
| (Email, SMS, etc.) |
+----------------------+
```
## **Environment Variables**
Ensure your `.env` file looks like this before getting started:
```env
# 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=
# Elasticsearch Configuration
ELASTIC_SEARCH_URL=
# PostgreSQL Configuration
POSTGRES_URL=
```
## **CLI Usage**
The `budget-manager` CLI provides a convenient way to interact with the application from the command line.
Follow these steps to use the CLI:
1. Install globally:
```bash
npm link
```
2. Use commands:
```bash
budget-manager seed
budget-manager notify "Hello!"
budget-manager add-task "Task description"
```
3. View available commands:
```bash
budget-manager --help
```
This will display a list of available commands and options:
```plaintext
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 Send a real-time notification to WebSocket clients
list-budgets List all budgets in the database
add-task Add a new task to the task queue
list-orders List all orders in the database
add-order Add a new order
list-customers List all customers in the database
add-customer [phone] Add a new customer
search-expenses Search for expenses using a query
graphql-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"
```
4. View version information:
```bash
budget-manager --version
```
The 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.
## **Demo Frontend UI**
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:
1. Navigate to the `frontend` directory:
```bash
cd frontend
```
2. Install dependencies: (use `npm install --legacy-peer-deps` if you encounter peer dependency issues)
```bash
npm install
```
3. Start the development server:
```bash
npm start
```
4. Access 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](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](frontend/README.md) in the `frontend` directory to learn about the frontend UI components, features, and usage.
### **UI Images**
Here are some screenshots of the frontend UI:
**Home:**
**Dashboard:**
**Budgets:**
**Expenses:**
**Profile:**
**Login:**
**Register:**
**Forgot Password:**
**Users:**
## **Swagger Documentation**
- Comprehensive API documentation is available at `/docs`.
- Includes all endpoints, schemas, and examples.
- Use Swagger UI to test and interact with the API.
- The Swagger UI looks like this:
## **GraphQL Integration**
- The Budget Management API supports GraphQL queries and mutations.
- Access the GraphQL endpoint at `http://localhost:3000/api/graphql`.
- Use the GraphiQL interface to interact with the API.
- The GraphiQL interface looks like this:
- Interact with the API using GraphQL queries and mutations. Examples include:
```graphql
query {
budgets {
id
name
limit
createdAt
}
}
```
Or:
```graphql
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:
## **NGINX Configuration**
- The `nginx` directory contains an Nginx configuration for reverse proxy and load balancing.
- Use Nginx to route requests to multiple instances of the API.
- Configure SSL termination and caching for improved performance.
- The Nginx configuration looks like this:
```nginx
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;
}
}
```
- For more information, refer to the [Nginx documentation](https://nginx.org/en/docs/) and the [Nginx Directory](nginx/README.md).
## **gRPC Integration**
The Budget Management API includes support for **gRPC** to enable high-performance remote procedure calls.
### **Getting Started**
1. **Start the gRPC Server**:
Run the following command:
```bash
node grpcServer.js
```
2. **Use the gRPC Client**:
Execute the client to interact with the server:
```bash
node grpcClient.js
```
3. **Proto 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. π
## **Dockerization**
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:
```bash
docker-compose up --build
```
## **Kubernetes Deployment**
1. Create Kubernetes manifests for the services.
2. Deploy to a cluster:
```bash
kubectl apply -f kubernetes/
```
3. Access the application using the service URL.
## **Spring Boot Backends with Maven and Gradle**
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:
1. Navigate to the `spring-boot` directory:
```bash
cd spring
```
2. Build the application using Maven:
```bash
mvn clean install
```
3. Run the application:
```bash
mvn spring-boot:run
```
4. Access the Spring Boot application at `http://localhost:8080`.
To run the Spring Boot Gradle application, follow these steps:
1. Navigate to the `spring-boot` directory:
```bash
cd gradle
```
2. Build the application using Gradle:
```bash
./gradlew build
```
3. Run the application:
```bash
./gradlew bootRun
```
4. Access the Spring Boot application at `http://localhost:8080`.
## **Dotnet Backend with C Sharp**
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:
1. Navigate to the `dotnet` directory:
```bash
cd dotnet
```
2. Build the application using the .NET CLI:
```bash
dotnet build
```
3. Run the application:
```bash
dotnet run
```
4. Access the Dotnet C# application at `http://localhost:5000`.
## **Continuous Integration and Deployment with Jenkins**
The Budget Management API includes a Jenkins pipeline for continuous integration and deployment.
1. **Pipeline Configuration:** The `Jenkinsfile` defines the CI/CD pipeline stages, including code checkout, dependency installation, testing, building, and deployment. Add it to the root of the project.
2. **Job Setup:** Create a pipeline job in Jenkins, point it to the repository, and configure it to use the `Jenkinsfile`.
3. **Automated Testing:** The pipeline runs `npm test` to ensure all tests pass before proceeding to the build or deployment stages.
4. **Environment Variables:** Use Jenkins environment variables to securely manage secrets like API keys and credentials for services such as MongoDB, Redis, or Render.
5. **Deployment:** The pipeline supports deploying the application using Render or directly to a server using SSH and PM2.
6. **Webhooks:** Integrate GitHub/GitLab webhooks to trigger builds automatically on code changes.
7. **Notifications:** Add Slack or email notifications in the pipeline to inform team members about build and deployment statuses.
### **GitHub Actions**
The Budget Management API also includes a GitHub Actions workflow for continuous integration and deployment.
1. **Workflow Configuration:** The `.github/workflows/ci.yml` file defines the CI/CD workflow, including steps for checking out code, installing dependencies, running tests, and building the application.
2. **Job Setup:** The workflow is triggered on push and pull request events to the `main` branch.
3. **Automated Testing:** The workflow runs `npm test` to ensure all tests pass before proceeding to the build or deployment stages.
4. **Deployment:** The workflow can be configured to deploy the application to Render or other hosting services using GitHub Actions deployment steps.
5. **Environment Variables:** Use GitHub Secrets to securely manage sensitive information like API keys and database credentials.
6. **Notifications:** Configure GitHub Actions to send notifications to Slack or email on build and deployment statuses.
This setup allows for automated testing and deployment, ensuring that the application is always in a deployable state.
## **Testing**
The Budget Management API includes unit tests for all endpoints and services.
To run the tests, use the following command:
```bash
npm test
```
The 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:
```bash
npm test:watch
```
**Coverage Report:** To generate a code coverage report, use:
```bash
npm test:coverage
```
**Mocha 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:
```bash
npm run test:mocha
```
## **Contributing**
Contributions are welcome! Please fork the repository, create a feature branch, and submit a pull request:
1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Make changes and commit them (`git commit -am 'Add new feature'`).
4. Push to the branch (`git push origin feature-branch`).
5. Create a new pull request. We will review your changes and merge them if they look good.
## **Author**
This project is built with β€οΈ by:
- **Son Nguyen** - [hoangsonww](https://github.com/hoangsonww)
For more information about me, you can visit my personal website or connect with me on LinkedIn:
- **Website:** [https://sonnguyenhoang.com](https://sonnguyenhoang.com)
- **Email:** [hoangson091104@gmail.com](mailto:hoangson091104@gmail.com)
- **LinkedIn:** [https://www.linkedin.com/in/hoangsonw](https://www.linkedin.com/in/hoangsonw)
- **GitHub:** [@hoangsonww](https://github.com/hoangsonww)
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](mailto:hoangson091104@gmail.com).
Created with β€οΈ by [Son Nguyen](https://sonnguyenhoang.com) in 2024. All rights reserved.
---
[β¬οΈ Back to Top](#budget-management-api---a-comprehensive-microservices-based-api-for-managing-budgets-expenses-users-and-more-)