Skip to content

PRITAM-TU/AI-Token-Tracker-Dashboard-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Token Tracker Dashboard

A full-stack web application that helps AI developers, students, and companies track, optimize, and visualize token usage across different AI models. Monitor your API consumption, estimate costs, and analyze performance through an intuitive dashboard.

✨ Features

  • πŸ” User Authentication - Secure JWT-based registration and login system
  • πŸ€– Multi-Model Support - Compatible with GPT-3.5, GPT-4, Claude-2, Llama 2, and more
  • πŸ“Š Real-time Analytics - Track token usage, costs, and response times
  • πŸ’° Cost Estimation - Automatic cost calculation based on model pricing
  • πŸ“ˆ Interactive Dashboard - Beautiful charts and visualizations
  • πŸ’Ύ Data Export - Download usage reports as CSV files
  • 🎨 Modern UI - Glass morphism design with neural network backgrounds

πŸ› οΈ Technology Stack

Frontend

  • React.js - User interface library
  • Vite - Fast build tool and development server
  • Tailwind CSS - Utility-first CSS framework
  • Recharts - Interactive charting library
  • Axios - HTTP client for API calls
  • React Router DOM - Client-side routing
  • Lucide React - Modern icons

Backend

  • Node.js - JavaScript runtime environment
  • Express.js - Web application framework
  • MongoDB - NoSQL database
  • Mongoose - MongoDB object modeling
  • JWT - JSON Web Tokens for authentication
  • bcryptjs - Password hashing
  • CORS - Cross-origin resource sharing

AI Services

  • Hugging Face API - AI model inference
  • Custom Token Counter - Token calculation utilities

πŸš€ Quick Start

Prerequisites

  • Node.js (version 18 or higher)
  • MongoDB (local or MongoDB Atlas)
  • Hugging Face API account (optional)

Installation

  1. Clone the repository

    git clone <your-repository-url>
    cd ai-token-tracker
  2. Backend Setup

    cd backend
    npm install
  3. Frontend Setup

    cd ../client
    npm install

Configuration

  1. Backend Environment Variables (backend/.env)

    PORT=5000
    MONGODB_URI=mongodb://localhost:27017/ai_token_tracker
    JWT_SECRET=your_super_secret_jwt_key
    JWT_EXPIRE=30d
    HUGGING_FACE_API_KEY=your_hugging_face_api_key
    HF_API_URL=https://api-inference.huggingface.com/models
    CLIENT_URL=http://localhost:3000
  2. Frontend Configuration (client/vite.config.js)

    export default {
      plugins: [react()],
      server: {
        port: 3000,
        proxy: {
          '/api': {
            target: 'http://localhost:5000',
            changeOrigin: true,
          },
        },
      },
    }

Running the Application

  1. Start the Backend Server

    cd backend
    npm run dev

    Server runs on: http://localhost:5000

  2. Start the Frontend Development Server

    cd client
    npm run dev

    Application runs on: http://localhost:3000

  3. Access the Application

    • Open your browser and go to http://localhost:3000
    • Register a new account or login
    • Start tracking your AI token usage!

πŸ“ Project Structure

ai-token-tracker/
β”œβ”€β”€ client/                 # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Login.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Register.jsx
β”‚   β”‚   β”‚   └── Layout.jsx
β”‚   β”‚   β”œβ”€β”€ contexts/      # React contexts
β”‚   β”‚   β”‚   └── AuthContext.jsx
β”‚   β”‚   β”œβ”€β”€ App.jsx        # Main App component
β”‚   β”‚   └── main.jsx       # Application entry point
β”‚   β”œβ”€β”€ public/            # Static files
β”‚   └── package.json       # Frontend dependencies
β”œβ”€β”€ backend/               # Node.js backend
β”‚   β”œβ”€β”€ controllers/       # Route controllers
β”‚   β”‚   β”œβ”€β”€ authController.js
β”‚   β”‚   β”œβ”€β”€ tokenLogController.js
β”‚   β”‚   └── aiController.js
β”‚   β”œβ”€β”€ models/           # Database models
β”‚   β”‚   β”œβ”€β”€ User.js
β”‚   β”‚   └── TokenLog.js
β”‚   β”œβ”€β”€ routes/           # API routes
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   β”œβ”€β”€ logs.js
β”‚   β”‚   └── ai.js
β”‚   β”œβ”€β”€ middleware/       # Custom middleware
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   └── validation.js
β”‚   β”œβ”€β”€ services/         # Business logic
β”‚   β”‚   └── aiService.js
β”‚   β”œβ”€β”€ utils/            # Utility functions
β”‚   β”‚   └── tokenCounter.js
β”‚   β”œβ”€β”€ server.js         # Server entry point
β”‚   └── package.json      # Backend dependencies
└── README.md             # Project documentation

πŸ”Œ API Endpoints

Authentication

  • POST /api/auth/register - Create new user account
  • POST /api/auth/login - User login
  • GET /api/auth/me - Get current user profile

Token Logs

  • GET /api/logs - Get user's token logs
  • GET /api/logs/stats - Get usage statistics
  • POST /api/logs - Create new token log
  • GET /api/logs/export - Export logs as CSV

AI Processing

  • POST /api/ai/process - Process AI prompt
  • GET /api/ai/models - Get available AI models

🎯 Key Features Explained

Token Tracking

  • Prompt Tokens: Count of input tokens sent to AI model
  • Completion Tokens: Count of output tokens received from AI model
  • Total Tokens: Sum of prompt and completion tokens
  • Cost Calculation: Automatic cost estimation based on model pricing

Supported AI Models

  • GPT-3.5 Turbo ($0.002 per 1K tokens)
  • GPT-4 ($0.06 per 1K tokens)

Dashboard Analytics

  • Real-time Stats: Live updating usage statistics
  • Interactive Charts: Token usage trends and cost analysis
  • Model Distribution: Pie charts showing model usage patterns
  • Response Time Tracking: Performance monitoring across requests

πŸ”§ Development

Adding New AI Models

  1. Update the models array in Dashboard.jsx
  2. Add pricing in utils/tokenCounter.js
  3. Implement API integration in services/aiService.js

Customizing the UI

  • Modify Tailwind classes in components
  • Update color schemes in tailwind.config.js
  • Add new charts using Recharts components

Database Schema

User Model:

  • name, email, password, company, subscription type

TokenLog Model:

  • user reference, prompt, response, model used
  • token counts, estimated cost, response time
  • timestamps and status fields

πŸš€ Deployment

Frontend (Vercel)

cd client
npm run build
# Deploy dist folder to Vercel

Backend (Render)

cd backend
# Set environment variables in Render dashboard
# Deploy from GitHub repository

Database (MongoDB Atlas)

  • Create free cluster on MongoDB Atlas
  • Update MONGODB_URI in environment variables
  • Whitelist deployment IP addresses

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Hugging Face for providing AI model APIs
  • Tailwind CSS for the amazing utility-first CSS framework
  • Recharts for beautiful and interactive charts
  • React Community for excellent documentation and support

πŸ“ž Support

If you have any questions or need help with setup:

  1. Check the existing GitHub issues
  2. Create a new issue with detailed description
  3. Provide steps to reproduce any bugs

⭐ Don't forget to star this repository if you find it helpful!


Built with ❀️ using the MERN stack

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors