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
git clone https://github.com/your-username/crypto-monitor.git
cd crypto-monitorInstall packages for both services:
cd api-server
npm install
cd ../worker-server
node src\index.js
cd projectname
nats-server
Create a .env file in both api-server/ and worker-server/ folders.
PORT=3000
MONGO_URI=mongodb://localhost:27017/crypto-monitor
COINGECKO_API=xxxxxxxxxx
NATS_URL=nats://localhost:4222
Make sure these are running on your machine:
- 🐳 MongoDB — database
cd api-server
npm startThis runs Express on the port defined in .env (default: 5000).
cd worker-server
node src\index.jsThe worker will fetch stats every minute and send to the API server via NATS.
GET /api/stats/latest?coin=bitcoinQuery Params:
coin—bitcoin,ethereum, ormatic-network
Response:
{
"price": 12345.67,
"marketCap": 234567890,
"24hChange": 1.23
}GET /api/stats/deviation?coin=bitcoinResponse:
{
"deviation": 123.45
}✅ 1. API Server Started Successfully
This screenshot shows the terminal output of the api-server running successfully.

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

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

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

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

- Node.js (Express + NATS + Mongoose)
- MongoDB for data storage
- NATS for lightweight service communication
- CoinGecko API for real-time crypto stats
Created by Mohammed Vijahath. Contributions welcome!