Skip to content

build a full backend system, interact with external APIs, use databases, and work with background jobs and event queues.

Notifications You must be signed in to change notification settings

vizahat36/Crypto-Monitor-Backend-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File for your Crypto Monitor backend system. It includes:

  • 📁 Project structure
  • ⚙️ Setup instructions
  • 🚀 How to run each service
  • 🧪 Example API endpoints
  • 🖼️ Space for inserting a project diagram or screenshot

# 📈 Crypto Monitor Backend System

This is a full backend microservice system for tracking real-time cryptocurrency statistics using the CoinGecko API. It consists of two services:

- `api-server` — Exposes a REST API and stores stats in MongoDB
- `worker-server` — Background service that fetches stats and sends via NATS

---

## 📁 Project Structure

```bash
crypto-monitor/
├── api-server/
│   ├── src/
│   │   ├── controllers/
│   │   │   └── statsController.js     # API logic for returning stats and deviation
│   │   ├── models/
│   │   │   └── CryptoStat.js          # Mongoose schema for stats data
│   │   ├── routes/
│   │   │   └── statsRoutes.js         # API routes (GET endpoints)
│   │   ├── services/
│   │   │   └── coingeckoService.js    # CoinGecko fetching logic (can be reused)
│   │   ├── utils/
│   │   │   └── db.js                  # MongoDB connection helper
│   │   ├── index.js                   # Main server file (starts Express + DB)
│   │   ├── nats.js                    # NATS listener for stats from worker
│   │   └── storeCryptoStats.js       # Handles writing received stats to DB
│   ├── .env                           # Environment config (PORT, MONGO_URI, NATS_URL)
│   ├── package.json                   # Dependencies and scripts
│
├── worker-server/
│   ├── src/
│   │   ├── index.js                   # Main loop to fetch and send stats
│   │   └── nats.js                    # NATS publisher setup
│   ├── .env                           # Environment config (NATS_URL)
│   ├── package.json                   # Dependencies and scripts

🛠️ Setup Instructions

1. Clone the Repo

git clone https://github.com/your-username/crypto-monitor.git
cd crypto-monitor

2. Install Dependencies

Install packages for both services:

cd api-server
npm install

cd ../worker-server
node src\index.js

cd projectname
nats-server

3. Set Up Environment Variables

Create a .env file in both api-server/ and worker-server/ folders.

🔐 For api-server/.env:

PORT=3000
MONGO_URI=mongodb://localhost:27017/crypto-monitor
COINGECKO_API=xxxxxxxxxx

🔐 For worker-server/.env:

NATS_URL=nats://localhost:4222

4. Start Required Services

Make sure these are running on your machine:

  • 🐳 MongoDB — database

🚀 Running the Services

✅ Start the API Server

cd api-server
npm start

This runs Express on the port defined in .env (default: 5000).

🔁 Start the Worker Server

cd worker-server
node src\index.js

The worker will fetch stats every minute and send to the API server via NATS.


🧪 API Endpoints

1. Get Latest Stats

GET /api/stats/latest?coin=bitcoin

Query Params:

  • coinbitcoin, ethereum, or matic-network

Response:

{
  "price": 12345.67,
  "marketCap": 234567890,
  "24hChange": 1.23
}

2. Get Price Standard Deviation (Last 100 records)

GET /api/stats/deviation?coin=bitcoin

Response:

{
  "deviation": 123.45
}

🖼️ Project Diagram / Screenshot

✅ 1. API Server Started Successfully This screenshot shows the terminal output of the api-server running successfully. 1api-server

✅ 2. Worker Server Fetching Data This screenshot shows the worker-server fetching crypto stats and publishing them via NATS. 2worker-server

✅ 3. NATS Server Running This screenshot shows the NATS server up and running, enabling message communication between services. 3Nats-server

📊 4. MongoDB Before Inserting Crypto Stats Initial state of the CryptoStats collection in MongoDB Compass (empty or with minimal data). 4before15min

📊 5. MongoDB After 15 Minutes (Crypto Data Inserted) After 15 minutes, the worker has fetched and inserted multiple crypto stats documents (Bitcoin, Ethereum, Matic). 5after15min


🧠 Tech Stack

  • Node.js (Express + NATS + Mongoose)
  • MongoDB for data storage
  • NATS for lightweight service communication
  • CoinGecko API for real-time crypto stats

📬 Contact

Created by Mohammed Vijahath. Contributions welcome!

About

build a full backend system, interact with external APIs, use databases, and work with background jobs and event queues.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published