Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PedroFlores1996/Xchange

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’° Xchange

An expense-sharing web application built with Flask πŸš€

A pet project designed to consolidate Python, Flask, and SQL integration skills through real-world application development. This expense-sharing platform demonstrates modern web development practices, database design, and full-stack implementation while providing a practical tool for managing shared expenses with friends and groups.

Python Flask


✨ Features

πŸ’Έ Expense Management

  • Flexible Splitting: Split expenses equally, by custom amounts, or by percentages
  • Multiple Categories: Organize expenses by category (Food, Travel, Utilities, etc.)
  • Real-time Calculations: Instant balance updates and debt tracking

πŸ‘₯ Group Management

  • Create Groups: Organize expenses by groups (trips, roommates, projects)
  • Group Overview: Visual dashboards showing balances and recent activity

🀝 Social Features

  • User Profiles: Manage your account and view your expense history
  • Activity Feed: Track all expense activities and updates

πŸ’° Debt Settlement

  • Smart Calculations: Automatic debt optimization to minimize transactions
  • Settlement Tracking: Mark debts as settled with confirmation
  • Balance Overview: Clear view of who owes what to whom

πŸ”’ Security & Reliability

  • User Authentication: Secure login and registration system
  • Data Validation: Comprehensive form validation and error handling
  • Database Integrity: Robust data models with proper relationships

πŸš€ Quick Start

Local Development

# Clone and setup
git clone <your-repo-url>
cd Xchange

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Initialize database
flask database create-tables

# Run the application
python runserver.py

πŸ—οΈ Architecture

Tech Stack

🐍 Backend Framework    β†’ Flask 3.1.0
πŸ—„οΈ Database           β†’ SQLite / PostgreSQL
🎨 Frontend           β†’ Jinja2 Templates + Vanilla JS
πŸ” Authentication     β†’ Flask-Login
πŸ“ Forms              β†’ WTForms + Flask-WTF
πŸ”„ Migrations         β†’ Flask-Migrate (Alembic)

Project Structure

Xchange/
β”œβ”€β”€ πŸ”§ Application Core
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ __init__.py         # App factory
β”‚   β”‚   β”œβ”€β”€ config.py           # Configuration classes
β”‚   β”‚   └── database.py         # Database setup
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ” Authentication (app/auth/)
β”‚   β”‚   β”œβ”€β”€ views.py            # Login, logout, registration
β”‚   β”‚   └── forms.py            # Auth forms
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ‘€ User Management (app/user/)
β”‚   β”‚   β”œβ”€β”€ views.py            # Dashboard, friends, profile
β”‚   β”‚   └── forms.py            # User forms
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ‘₯ Group Management (app/group/)
β”‚   β”‚   β”œβ”€β”€ views.py            # Groups, members, overview
β”‚   β”‚   └── forms.py            # Group forms
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ’° Expense Management (app/expense/)
β”‚   β”‚   β”œβ”€β”€ views.py            # Create, view expenses
β”‚   β”‚   β”œβ”€β”€ forms.py            # Expense forms
β”‚   β”‚   β”œβ”€β”€ mapper.py           # Data transformation
β”‚   β”‚   └── submit.py           # Expense processing
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ”’ Splitting Logic (app/split/)
β”‚   β”‚   β”œβ”€β”€ equally.py          # Equal split algorithm
β”‚   β”‚   β”œβ”€β”€ amount.py           # Custom amount splits
β”‚   β”‚   └── percentage.py       # Percentage-based splits
β”‚   β”‚
β”‚   β”œβ”€β”€ πŸ’³ Debt Management (app/debt/)
β”‚   β”‚   └── __init__.py         # Debt calculations
β”‚   β”‚
β”‚   └── πŸ—ƒοΈ Data Models (app/model/)
β”‚       β”œβ”€β”€ user.py             # User model
β”‚       β”œβ”€β”€ group.py            # Group model
β”‚       β”œβ”€β”€ expense.py          # Expense model
β”‚       β”œβ”€β”€ balance.py          # Balance model
β”‚       └── debt.py             # Debt model
β”‚
β”œβ”€β”€ 🎨 Frontend (app/templates/)
β”‚   β”œβ”€β”€ auth/                   # Login, registration pages
β”‚   β”œβ”€β”€ user/                   # Dashboard, profile pages
β”‚   β”œβ”€β”€ group/                  # Group management pages
β”‚   └── expense/                # Expense forms and summaries
β”‚
β”œβ”€β”€ πŸ§ͺ Tests (tests/)
β”‚   β”œβ”€β”€ auth/                   # Authentication tests
β”‚   β”œβ”€β”€ user/                   # User feature tests
β”‚   β”œβ”€β”€ group/                  # Group feature tests
β”‚   β”œβ”€β”€ expense/                # Expense feature tests
β”‚   └── model/                  # Data model tests
β”‚
└── πŸ“š Documentation
    β”œβ”€β”€ README.md               # This file
    └── CLAUDE.md              # Development instructions

🎯 Usage Examples

Creating an Expense

# Example: Dinner for 4 people, split equally
Expense(
    description="Dinner at Italian Restaurant",
    amount=120.00,
    category="Food",
    payers=[user1],           # Who paid
    owers=[user1, user2, user3, user4],  # Who owes
    split_type="Equally"      # How to split
)
# Result: Everyone owes $30

Custom Split Example

# Example: Unequal split by amount
Expense(
    description="Vacation Rental",
    amount=400.00,
    payers=[user1],
    owers=[user1, user2, user3],
    split_type="Amount",
    amounts={
        user1: 200.00,  # Gets larger room
        user2: 100.00,  # Standard room
        user3: 100.00   # Standard room
    }
)

πŸ§ͺ Testing

Run All Tests

# With pytest
pytest

# With coverage
pytest --cov

# Specific test modules
pytest tests/expense/
pytest tests/user/

Test Categories

  • Unit Tests: Model logic, splitting algorithms
  • Integration Tests: View functions, form handling
  • Feature Tests: End-to-end user workflows

πŸ› οΈ Development

Prerequisites

  • Python 3.13+
  • SQLite (included) or PostgreSQL

Development Commands

# Database operations
flask database create-tables    # Create all tables
flask database clear-data       # Clear all data
flask database test-data        # Create test data

# Database migrations
flask db migrate -m "message"   # Create migration
flask db upgrade                # Apply migrations

# Code quality
black .                         # Format code
mypy .                          # Type checking
pytest                          # Run tests

Contributing

  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. Run the test suite (pytest)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

πŸ“Š Database Schema

erDiagram
    User ||--o{ Balance : has
    User ||--o{ Expense : creates
    User ||--o{ Debt : owes
    Group ||--o{ Expense : contains
    Group }o--o{ User : members
    Expense ||--o{ Balance : splits_into
    
    User {
        int id PK
        string username
        string email
        string password_hash
        datetime created_at
    }
    
    Group {
        int id PK
        string name
        string description
        int creator_id FK
        datetime created_at
    }
    
    Expense {
        int id PK
        string description
        float amount
        string category
        int creator_id FK
        int group_id FK
        datetime created_at
    }
    
    Balance {
        int id PK
        int expense_id FK
        int user_id FK
        float amount_owed
        float amount_paid
    }
    
    Debt {
        int id PK
        int debtor_id FK
        int creditor_id FK
        float amount
        datetime created_at
    }
Loading

🎨 Screenshots

Dashboard

Dashboard Clean, intuitive dashboard showing your expenses and balances

Expense Form

Expense Form Flexible expense creation with multiple split options

Group Overview

Group Overview Comprehensive group management with member balances


🀝 Contributing

We welcome contributions! Here's how you can help:

  • πŸ› Report Bugs: Open an issue with details
  • πŸ’‘ Suggest Features: Share your ideas for improvements
  • πŸ”§ Submit PRs: Fix bugs or add new features
  • πŸ“š Improve Docs: Help make our documentation better
  • πŸ§ͺ Add Tests: Increase our test coverage

πŸ“„ License

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


Made with ❀️ by Your Name

⬆️ Back to Top

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •