trafficjs-v
v1.0.1
Published
A lightweight TypeScript library for calculating system architecture metrics including traffic analysis, storage requirements, cost estimation, and availability planning.
Maintainers
Readme
🚦 TrafficJS-V
TrafficJS-V is a TypeScript toolkit and server for system architecture, traffic analysis, storage, cost estimation, and real-time metrics monitoring.
📦 Installation
npm install trafficjs-vUsage
1. As a Library
Import and use calculation functions in your app:
# 🚦 TrafficJS-V
**TrafficJS-V** is a TypeScript toolkit and server for system architecture, traffic analysis, storage, cost estimation, and real-time metrics monitoring.
---
## 📦 Installation
```bash
npm install trafficjs-vUsage
1. As a Library
Import and use calculation functions in your app:
import { trafficMetrics } from 'trafficjs-v';
import { storageMetrics } from 'trafficjs-v';
import { costEstimate } from 'trafficjs-v';
import { availabilityMetrics } from 'trafficjs-v';
const traffic = trafficMetrics({ users: 100000, reqPerUserPerDay: 100, payloadKB: 2 });
const storage = storageMetrics({ dailyDataGB: traffic.dailyDataGB, retentionDays: 30 });
const cost = costEstimate({ storageGB: storage.totalStorageGB, storageCostPerGB: 0.023, servers: 10, serverCostPerMonth: 30 });
const availability = availabilityMetrics({ sla: 99.9 });2. As a Server (Metrics Exporter)
Run the built-in Express server to expose system metrics via HTTP endpoints:
npm run dev
# or
npx tsx src/server.tsEndpoints:
/metrics— JSON system metrics/metrics/traffic— Prometheus/traffic-compatible metrics/trends— Trend tracking/health— Health check
Set the port with the PORT environment variable:
$env:PORT=8080; npm run dev # Windows PowerShell
PORT=8080 npm run dev # BashScripts
npm run dev— Start the metrics servernpm run example— Run usage examplenpm run demo— Run real-time demonpm run monitor— Run monitor loop
Project Structure
TrafficJS/
├── src/
│ ├── features/ # Core calculation modules (traffic, storage, cost, availability, etc.)
│ ├── core/ # Real-time system metrics and monitor
│ ├── exporter/ # HTTP metrics exporter modules
│ ├── demo/ # Example/demo scripts
│ ├── server.ts # Main Express server entry point
│ └── index.ts # Main library entry point (for npm)
├── package.json
├── tsconfig.json
└── README.mdAPI Reference
trafficMetrics(input: TrafficInput): TrafficResult
Calculate requests per second and daily data volume.
Parameters:
interface TrafficInput {
users: number; // Daily active users
reqPerUserPerDay: number; // Requests per user per day
payloadKB: number; // Average request size in KB
}Returns:
interface TrafficResult {
rps: number; // Requests per second
dailyDataGB: number; // Daily data volume in GB
}storageMetrics(input: StorageInput): StorageResult
Calculate total storage requirements with replication.
Parameters:
interface StorageInput {
dailyDataGB: number; // Daily data volume in GB
retentionDays: number; // Data retention period in days
replicationFactor?: number; // Replication factor (default: 3)
}Returns:
interface StorageResult {
totalStorageGB: number; // Total storage needed in GB
}costEstimate(input: CostInput): CostResult
Calculate monthly infrastructure costs.
Parameters:
interface CostInput {
storageGB: number; // Storage in GB
storageCostPerGB: number; // Cost per GB of storage
servers: number; // Number of servers
serverCostPerMonth: number; // Monthly cost per server
}Returns:
interface CostResult {
monthlyCost: number; // Total monthly cost
}availabilityMetrics(input: AvailabilityInput): AvailabilityResult
Calculate downtime based on SLA.
Parameters:
interface AvailabilityInput {
sla: number; // SLA percentage (e.g., 99.9)
}Returns:
interface AvailabilityResult {
downtimePerMonthMinutes: number; // Monthly downtime in minutes
downtimePerYearHours: number; // Yearly downtime in hours
}📋 Usage Examples
E-commerce Platform Planning
import { trafficMetrics, storageMetrics, costEstimate } from 'trafficjs-v';
// Black Friday traffic spike
const peakTraffic = trafficMetrics({
users: 5_000_000,
reqPerUserPerDay: 200,
payloadKB: 5
});
console.log(`Peak RPS: ${peakTraffic.rps.toFixed(0)}`);
// → Peak RPS: 11574
// Storage for 6 months of data
const storage = storageMetrics({
dailyDataGB: peakTraffic.dailyDataGB,
retentionDays: 180,
replicationFactor: 3
});
// AWS-like pricing
const cost = costEstimate({
storageGB: storage.totalStorageGB,
storageCostPerGB: 0.023,
servers: 50,
serverCostPerMonth: 100
});
console.log(`Monthly cost: $${cost.monthlyCost.toLocaleString()}`);Microservice Architecture
import { trafficMetrics, availabilityMetrics } from 'trafficjs-v';
// API Gateway traffic
const apiTraffic = trafficMetrics({
users: 100_000,
reqPerUserPerDay: 50,
payloadKB: 1
});
// Service availability requirements
const availability = availabilityMetrics({ sla: 99.99 });
console.log(`API RPS: ${apiTraffic.rps.toFixed(2)}`);
console.log(`Allowed downtime: ${availability.downtimePerMonthMinutes.toFixed(1)} min/month`);🛠️ Development
# Clone the repository
git clone https://github.com/Viswesh934/TrafficJS.git
cd TrafficJS
# Install dependencies
npm install
# Run the server
npm run dev
# Run example/demo scripts
npm run example
npm run demo
npm run monitor🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📄 License
This project is licensed under the ISC License — see the LICENSE file for details.
🔗 Links
📊 Use Cases
- System Architecture Planning: Estimate infrastructure requirements for new projects
- Capacity Planning: Calculate scaling requirements for growing applications
- Cost Optimization: Analyze and optimize infrastructure spending
- SLA Planning: Understand availability requirements and downtime implications
- Performance Benchmarking: Establish baseline metrics for system performance
Made with 🔥 by Viswesh934 }
### `costEstimate(input: CostInput): CostResult`
Calculate monthly infrastructure costs.
**Parameters:**
```typescript
interface CostInput {
storageGB: number; // Storage in GB
storageCostPerGB: number; // Cost per GB of storage
servers: number; // Number of servers
serverCostPerMonth: number; // Monthly cost per server
}Returns:
interface CostResult {
monthlyCost: number; // Total monthly cost
}availabilityMetrics(input: AvailabilityInput): AvailabilityResult
Calculate downtime based on SLA.
Parameters:
interface AvailabilityInput {
sla: number; // SLA percentage (e.g., 99.9)
}Returns:
interface AvailabilityResult {
downtimePerMonthMinutes: number; // Monthly downtime in minutes
downtimePerYearHours: number; // Yearly downtime in hours
}📋 Usage Examples
E-commerce Platform Planning
import { trafficMetrics, storageMetrics, costEstimate } from 'trafficjs';
// Black Friday traffic spike
const peakTraffic = trafficMetrics({
users: 5_000_000,
reqPerUserPerDay: 200,
payloadKB: 5
});
console.log(`Peak RPS: ${peakTraffic.rps.toFixed(0)}`);
// → Peak RPS: 11574
// Storage for 6 months of data
const storage = storageMetrics({
dailyDataGB: peakTraffic.dailyDataGB,
retentionDays: 180,
replicationFactor: 3
});
// AWS-like pricing
const cost = costEstimate({
storageGB: storage.totalStorageGB,
storageCostPerGB: 0.023,
servers: 50,
serverCostPerMonth: 100
});
console.log(`Monthly cost: $${cost.monthlyCost.toLocaleString()}`);Microservice Architecture
import { trafficMetrics, availabilityMetrics } from 'trafficjs';
// API Gateway traffic
const apiTraffic = trafficMetrics({
users: 100_000,
reqPerUserPerDay: 50,
payloadKB: 1
});
// Service availability requirements
const availability = availabilityMetrics({ sla: 99.99 });
console.log(`API RPS: ${apiTraffic.rps.toFixed(2)}`);
console.log(`Allowed downtime: ${availability.downtimePerMonthMinutes.toFixed(1)} min/month`);🛠️ Development
# Clone the repository
git clone https://github.com/Viswesh934/TrafficJS.git
cd TrafficJS
# Install dependencies
npm install
# Run the server
npm run dev
# Run example/demo scripts
npm run example
npm run demo
npm run monitor🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📄 License
This project is licensed under the ISC License — see the LICENSE file for details.
🔗 Links
📊 Use Cases
- System Architecture Planning: Estimate infrastructure requirements for new projects
- Capacity Planning: Calculate scaling requirements for growing applications
- Cost Optimization: Analyze and optimize infrastructure spending
- SLA Planning: Understand availability requirements and downtime implications
- Performance Benchmarking: Establish baseline metrics for system performance
Made with 🔥 by Viswesh934
