Skip to content

ravin00/ExpenseTracker

Repository files navigation

ExpenseTracker

.NET Docker License Build Status

A modern, microservices-based expense tracking application built with .NET 9.0, featuring robust authentication, comprehensive expense management, and advanced analytics capabilities.

📋 Table of Contents

✨ Features

Core Functionality

  • 🔐 Secure Authentication - JWT-based authentication with role management
  • 💰 Expense Management - Full CRUD operations for expense tracking
  • 📊 Analytics & Reporting - Comprehensive financial insights and trends
  • 💳 Budget Management - Budget creation, tracking, and alerts
  • 📱 RESTful APIs - Well-documented, scalable REST endpoints
  • 🐳 Containerized - Docker-ready for easy deployment

Technical Features

  • 🏗️ Microservices Architecture - Loosely coupled, independently deployable services
  • 🔒 Secure by Design - JWT authentication, input validation, SQL injection protection
  • 📈 Scalable - Horizontal scaling support with load balancing
  • 🔍 Observable - Comprehensive logging and health checks
  • 🧪 Well-Tested - Unit tests with high coverage
  • 📖 API Documentation - Interactive Swagger/OpenAPI documentation

🏗️ Architecture

graph TB
    Client[Client Application] --> Gateway[API Gateway<br/>Nginx:8080]
    
    Gateway --> Auth[Auth Service<br/>:5001]
    Gateway --> Expense[Expense Service<br/>:5002]
    Gateway --> Budget[Budget Service<br/>:5003]
    Gateway --> Analytics[Analytics Service<br/>:5004]
    
    Auth --> AuthDB[(Auth Database)]
    Expense --> ExpenseDB[(Expense Database)]
    Budget --> BudgetDB[(Budget Database)]
    Analytics --> AnalyticsDB[(Analytics Database)]
    
    AuthDB --> SQL[SQL Server<br/>:1433]
    ExpenseDB --> SQL
    BudgetDB --> SQL
    AnalyticsDB --> SQL
    
    style Client fill:#e1f5fe
    style Gateway fill:#f3e5f5
    style SQL fill:#fff3e0
Loading

Service Overview

Service Port Responsibility Database
API Gateway 8080 Request routing, load balancing -
Auth Service 5001 Authentication, user management ExpenseTrackerAuth
Expense Service 5002 Expense CRUD operations ExpenseTrackerExpenses
Budget Service 5003 Budget management, alerts ExpenseTrackerBudgets
Analytics Service 5004 Financial analytics, reporting ExpenseTrackerAnalytics
SQL Server 1433 Database server Multiple databases

🚀 Quick Start

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/your-username/ExpenseTracker.git
    cd ExpenseTracker
  2. Start all services

    docker-compose up --build -d
  3. Verify deployment

    # Check service health
    curl http://localhost:8080/health
    
    # View service status
    docker-compose ps
  4. Access the application

First Run

  1. Register a new user

    curl -X POST http://localhost:8080/api/auth/register \
      -H "Content-Type: application/json" \
      -d '{
        "username": "demo_user",
        "email": "demo@example.com", 
        "password": "SecurePassword123!"
      }'
  2. Login and get JWT token

    curl -X POST http://localhost:8080/api/auth/login \
      -H "Content-Type: application/json" \
      -d '{
        "email": "demo@example.com",
        "password": "SecurePassword123!"
      }'
  3. Create your first expense

    curl -X POST http://localhost:8080/api/expense \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer YOUR_JWT_TOKEN" \
      -d '{
        "description": "Coffee",
        "amount": 4.50,
        "category": "Food & Drink",
        "date": "2025-10-10T10:30:00Z"
      }'

📚 API Documentation

Authentication Endpoints

Method Endpoint Description Auth Required
POST /api/auth/register Register new user
POST /api/auth/login User login
GET /api/auth/profile Get user profile
PUT /api/auth/profile Update profile
POST /api/auth/refresh Refresh JWT token

Expense Management

Method Endpoint Description Auth Required
GET /api/expense List user expenses
POST /api/expense Create new expense
GET /api/expense/{id} Get expense details
PUT /api/expense/{id} Update expense
DELETE /api/expense/{id} Delete expense
GET /api/expense/categories Get expense categories

Budget Management

Method Endpoint Description Auth Required
GET /api/budget List user budgets
POST /api/budget Create budget
GET /api/budget/{id} Get budget details
PUT /api/budget/{id} Update budget
DELETE /api/budget/{id} Delete budget
GET /api/budget/{id}/status Get budget status

Analytics & Reporting

Method Endpoint Description Auth Required
GET /api/analytics/dashboard Financial dashboard
GET /api/analytics/summary Expense summary
GET /api/analytics/categories Category breakdown
GET /api/analytics/trends Spending trends
GET /api/analytics/health-status Financial health

Interactive Documentation

Access comprehensive API documentation with interactive testing:

🛠️ Development

Local Development Setup

  1. Install .NET 9.0 SDK

    # macOS (using Homebrew)
    brew install dotnet
    
    # Windows (using Chocolatey)
    choco install dotnet-9.0-sdk
    
    # Or download from: https://dotnet.microsoft.com/download
  2. Start dependencies

    # Start only database
    docker-compose up sqlserver -d
  3. Run services locally

    # Auth Service
    cd Backend/AuthService
    dotnet run
    
    # Expense Service  
    cd Backend/ExpenseService
    dotnet run
    
    # Budget Service
    cd Backend/BudgetService
    dotnet run
    
    # Analytics Service
    cd Backend/AnalyticsService
    dotnet run

Project Structure

ExpenseTracker/
├── Backend/                    # .NET microservices
│   ├── AuthService/           # Authentication service
│   ├── ExpenseService/        # Expense management
│   ├── BudgetService/         # Budget management
│   ├── AnalyticsService/      # Analytics & reporting
│   └── Backend.sln            # Solution file
├── Gateway/                   # Nginx configuration
├── Tests/                     # Test projects
├── Docs/                      # Documentation
├── Scripts/                   # Deployment scripts
├── docker-compose.yml         # Container orchestration
├── docker-compose.override.yml # Development overrides
└── README.md                  # This file

Testing

# Run all tests
dotnet test Backend/Backend.sln

# Run tests with coverage
dotnet test --collect:"XPlat Code Coverage"

# Run specific service tests
dotnet test Backend/AuthService.Tests/
dotnet test Backend/ExpenseService.Tests/
dotnet test Backend/BudgetService.Tests/
dotnet test Backend/AnalyticsService.Tests/

Code Quality

# Format code
dotnet format Backend/Backend.sln

# Static analysis
dotnet build --verbosity normal

🚀 Deployment

Production Deployment

  1. Environment Configuration

    # Copy and customize environment file
    cp .env.example .env
    
    # Edit configuration
    vim .env
  2. Production Build

    # Build for production
    docker-compose -f docker-compose.yml -f docker-compose.prod.yml build
    
    # Deploy
    docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d

Environment Variables

Variable Description Default Required
DB_PASSWORD SQL Server password ExpenseTracker123!
JWT_SECRET JWT signing key Generated
ASPNETCORE_ENVIRONMENT Environment Development
AUTH_SERVICE_PORT Auth service port 5001
EXPENSE_SERVICE_PORT Expense service port 5002
BUDGET_SERVICE_PORT Budget service port 5003
ANALYTICS_SERVICE_PORT Analytics service port 5004
GATEWAY_PORT API Gateway port 8080

Health Checks

Monitor service health using built-in endpoints:

# Overall system health
curl http://localhost:8080/health

# Individual service health
curl http://localhost:5001/health  # Auth Service
curl http://localhost:5002/health  # Expense Service
curl http://localhost:5003/health  # Budget Service
curl http://localhost:5004/health  # Analytics Service

📖 Documentation

Comprehensive documentation is available in the docs/ folder:

📂 Documentation Overview

🎯 Quick Documentation Links

Role Recommended Starting Point
Developers Quality StatusGeneral Improvements
DevOps Engineers Infrastructure ImprovementsArgoCD Deployment
Security Teams Security GuideInfrastructure Improvements
Project Managers Documentation IndexGeneral Improvements

📈 Infrastructure Features

  • Production-ready Kubernetes manifests with Kustomize overlays
  • GitOps deployment with ArgoCD for multiple environments
  • Security hardening with RBAC, network policies, and security contexts
  • Auto-scaling with HPA and resource management
  • Monitoring stack with Prometheus and Grafana
  • Backup strategy with automated PostgreSQL backups
  • TLS ingress with rate limiting and security headers

🤝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Make your changes
  4. Add tests for your changes
  5. Ensure all tests pass
    dotnet test Backend/Backend.sln
  6. Commit with conventional commits
    git commit -m "feat: add amazing feature"
  7. Push to your fork
    git push origin feature/amazing-feature
  8. Create a Pull Request

Code Standards

🔧 Troubleshooting

Common Issues

Port Conflicts
# Check which process is using a port
lsof -i :8080
lsof -i :5001

# Kill process using port
sudo kill -9 $(lsof -t -i:8080)
Database Connection Issues
# Check SQL Server status
docker-compose logs sqlserver

# Test database connection
docker-compose exec sqlserver /opt/mssql-tools/bin/sqlcmd \
  -S localhost -U sa -P ExpenseTracker123! -Q "SELECT 1"

# Reset database
docker-compose down -v
docker-compose up sqlserver -d
Service Not Starting
# Check service logs
docker-compose logs [service-name]

# Rebuild specific service
docker-compose build [service-name]
docker-compose up [service-name] -d

# Full reset
docker-compose down -v
docker system prune -f
docker-compose up --build -d
JWT Token Issues
# Verify JWT configuration
echo $JWT_SECRET

# Check token expiration in logs
docker-compose logs auth-service | grep -i jwt

# Test with new token
curl -X POST http://localhost:8080/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"password"}'

Performance Optimization

# Monitor resource usage
docker stats

# Scale services
docker-compose up --scale expense-service=3

# View detailed logs
docker-compose logs -f --tail=100 [service-name]

Getting Help

📄 License

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

🙏 Acknowledgments


About

No description, website, or topics provided.

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages