expense-tracker-bot

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2025 License: MIT

README ΒΆ

πŸš— Expense Tracker Bot

Go Version License PostgreSQL Docker Go Report Card

A robust, enterprise-grade Telegram bot for tracking personal expenses with PostgreSQL backend, built with Go. Features comprehensive expense management, category organization, vehicle expense tracking, and detailed analytics.

πŸš€ Quick Start β€’ 🌟 Features β€’ πŸ—οΈ Architecture β€’ πŸ§ͺ Testing β€’ πŸ”§ Development β€’ πŸš€ Deployment

🌟 Features

πŸ’° Core Functionality
  • πŸ“ Expense Tracking: Add, edit, delete, and list expenses with ease
  • πŸ“‚ Category Management: Organized expense categories with emojis
  • πŸš— Vehicle Expenses: Special handling for fuel, service, and maintenance costs
  • πŸ“Š Reports & Analytics: Generate comprehensive expense reports and statistics
  • πŸ“ˆ Dashboard: Visual overview of spending patterns and trends
🏒 Enterprise Features
  • πŸ›‘οΈ Robust Error Handling: Custom error types with proper error categorization
  • βœ… Input Validation: Comprehensive validation for all user inputs
  • πŸ—οΈ Service Layer Architecture: Clean separation of business logic
  • πŸ”§ Middleware Support: Cross-cutting concerns like logging, rate limiting, and metrics
  • πŸ§ͺ Comprehensive Testing: Unit tests with mocking and test coverage
  • πŸ“ Structured Logging: JSON logging with context and correlation IDs
  • πŸ—„οΈ Database Abstraction: Interface-based database layer with PostgreSQL support
  • βš™οΈ Configuration Management: Environment-based configuration with validation
  • 🚦 Rate Limiting: Built-in rate limiting to prevent abuse
  • πŸ“Š Metrics Collection: Application metrics for monitoring

πŸ—οΈ Architecture

High-Level Architecture
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Telegram API  β”‚    β”‚   Bot Handler   β”‚    β”‚  Service Layer  β”‚
β”‚                 │◄──►│                 │◄──►│                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                       β”‚
                                β–Ό                       β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   Middleware    β”‚    β”‚   Validation    β”‚
                       β”‚                 β”‚    β”‚                 β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                       β”‚
                                β–Ό                       β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚  Database Layer β”‚    β”‚   Error Handler β”‚
                       β”‚                 β”‚    β”‚                 β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   PostgreSQL    β”‚
                       β”‚                 β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

For the fastest setup experience, use our automated setup script:

# Clone the repository
git clone https://github.com/MitulShah1/expense-tracker-bot.git
cd expense-tracker-bot

# Run the quick start script
./scripts/quick-start.sh

This script will automatically:

  • βœ… Check all prerequisites (Go, Docker)
  • πŸ“ Create and configure your .env file
  • πŸ—„οΈ Start PostgreSQL database with Docker
  • πŸ”§ Install dependencies and run migrations
  • πŸ—οΈ Build the application
  • πŸ§ͺ Run tests
  • πŸš€ Provide next steps
πŸ“‹ Prerequisites
βš™οΈ Manual Setup

If you prefer manual setup or the automated script doesn't work:

Step 1: Clone the Repository
git clone https://github.com/MitulShah1/expense-tracker-bot.git
cd expense-tracker-bot
Step 2: Run Complete Setup Script
# Make scripts executable
chmod +x scripts/*.sh

# Run the complete setup
./scripts/setup.sh
Step 3: Manual Environment Configuration
  1. Create the environment file:

    cp .env.example .env  # if .env.example exists
    # or create manually:
    
  2. Configure your environment variables:

    # Telegram Bot Configuration
    TELEGRAM_TOKEN=your_telegram_bot_token
    BOT_ID=your_bot_id
    
    # Database Configuration
    DATABASE_URL=postgres://postgres:password@localhost:5432/expense_tracker?sslmode=disable
    
    # Application Configuration
    LOG_LEVEL=info
    IS_DEV_MODE=true
    
    # Database Connection Pool (optional)
    DB_MAX_OPEN_CONNS=25
    DB_MAX_IDLE_CONNS=5
    DB_CONN_MAX_LIFETIME=5m
    

    Note: You'll need to create a Telegram bot first. Visit @BotFather on Telegram to create your bot and get the token.

Step 4: Manual Database Setup
  1. Start PostgreSQL using Docker Compose:

    docker-compose up -d postgres
    
  2. Run database migrations:

    make migrate
    
Step 5: Manual Application Setup
  1. Install dependencies:

    make deps
    
  2. Build the application:

    make build
    
  3. Run the application:

    make run
    
🎯 After Setup

Once setup is complete:

  1. Update your bot token: Edit .env file and replace your_telegram_bot_token_here with your actual bot token
  2. Start the bot: ./expense-tracker-bot or make run
  3. Test the bot: Use ./scripts/test_bot.sh to test functionality
  4. Access pgAdmin: Visit http://localhost:8080 (admin@expense-tracker.com / admin)
πŸ”§ Available Scripts
  • ./scripts/quick-start.sh - One-command setup with confirmation
  • ./scripts/setup.sh - Complete automated setup
  • ./scripts/setup_database.sh - Database-only setup
  • ./scripts/test_bot.sh - Test the bot functionality

πŸ§ͺ Testing

πŸƒβ€β™‚οΈ Running Tests
# Run all tests
make test

# Run tests with coverage
make test-coverage

# Run specific test package
go test ./internal/services/...
πŸ“Š Test Coverage

The application includes comprehensive unit tests with:

  • βœ… Service layer testing with mocked dependencies
  • βœ… Input validation testing
  • βœ… Error handling testing
  • βœ… Database operation testing

πŸ”§ Development

🎯 Code Quality
# Format code
make fmt

# Run linter
make lint

# Run all quality checks
make all
πŸš€ Adding New Features
  1. Service Layer: Add business logic in internal/services/
  2. Validation: Add input validation in internal/validation/
  3. Database: Add database operations in internal/database/
  4. Tests: Add corresponding tests in the same package
  5. Documentation: Update this README and add inline documentation
⚠️ Error Handling

The application uses custom error types for better error categorization:

  • ValidationError: Input validation errors
  • NotFoundError: Resource not found errors
  • DatabaseError: Database operation errors
  • TelegramError: Telegram API errors
  • UnauthorizedError: Authorization errors
  • RateLimitError: Rate limiting errors

πŸ“Š Monitoring & Observability

πŸ“ Logging

The application uses structured JSON logging with:

  • πŸ”— Request correlation IDs
  • πŸ‘€ User context
  • ⚑ Performance metrics
  • ❌ Error details
πŸ“ˆ Metrics

Built-in metrics collection for:

  • πŸ“Š Request counts
  • ❌ Error rates
  • ⏱️ Response times
  • πŸ‘₯ Active users
πŸ₯ Health Checks

Database connectivity and application health monitoring.

πŸ”’ Security

πŸ›‘οΈ Input Validation
  • βœ… Comprehensive validation for all user inputs
  • πŸ›‘οΈ SQL injection prevention through parameterized queries
  • 🚦 Rate limiting to prevent abuse
  • πŸ” User authorization checks
πŸ” Data Protection
  • πŸ”’ Secure database connections
  • βš™οΈ Environment-based configuration
  • 🚫 No sensitive data in logs

πŸš€ Deployment

🐳 Docker Deployment
# Build Docker image
docker build -t expense-tracker-bot .

# Run with Docker Compose
docker-compose up -d
🏭 Production Considerations
  • βš™οΈ Use environment-specific configurations
  • πŸ“ Set up proper logging aggregation
  • πŸ—„οΈ Configure database connection pooling
  • πŸ“Š Implement monitoring and alerting
  • πŸ’Ύ Set up backup strategies

🀝 Contributing

We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Contribution Guidelines
  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/amazing-feature)
  3. ✏️ Make your changes
  4. πŸ§ͺ Add tests for new functionality
  5. βœ… Ensure all tests pass (make test)
  6. πŸ“€ Commit your changes (git commit -m 'Add some amazing feature')
  7. πŸš€ Push to the branch (git push origin feature/amazing-feature)
  8. πŸ“‹ Open a Pull Request
πŸ“ Code Standards
  • πŸ“š Follow Go coding standards and conventions
  • πŸ§ͺ Add comprehensive tests for new functionality
  • πŸ“– Update documentation for any new features
  • πŸ’¬ Use meaningful commit messages
  • πŸ” Ensure code passes linting (make lint)

πŸ“ License

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

πŸ†˜ Support

Need help? Here are your options:

  • πŸ› Create an issue in the GitHub repository
  • πŸ“š Check the documentation in the docs/ directory
  • πŸ§ͺ Review the code examples in the test files
  • πŸ’¬ Join our community discussions

πŸ™ Acknowledgments


Made with ❀️ using Go and PostgreSQL

⬆️ Back to top

Directories ΒΆ

Path Synopsis
internal
application
Package application provides the main application struct and lifecycle management for the expense tracker bot.
Package application provides the main application struct and lifecycle management for the expense tracker bot.
bot
Package bot implements the Telegram bot functionality for expense tracking.
Package bot implements the Telegram bot functionality for expense tracking.
config
Package config provides configuration management for the expense tracker bot.
Package config provides configuration management for the expense tracker bot.
database
Package database provides PostgreSQL database operations for the expense tracker bot.
Package database provides PostgreSQL database operations for the expense tracker bot.
errors
Package errors provides custom error types for the expense tracker bot.
Package errors provides custom error types for the expense tracker bot.
logger
Package logger provides logging functionality for the application.
Package logger provides logging functionality for the application.
models
Package models defines the data structures used throughout the application.
Package models defines the data structures used throughout the application.
services
Package services provides business logic services for the expense tracker bot.
Package services provides business logic services for the expense tracker bot.
validation
Package validation provides input validation utilities for the expense tracker bot.
Package validation provides input validation utilities for the expense tracker bot.
pkg
utils
Package utils provides utility functions used throughout the expense tracker application.
Package utils provides utility functions used throughout the expense tracker application.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL