Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/akevalion/life_cost/llms.txt

Use this file to discover all available pages before exploring further.

Wallets are the top-level organizational unit in Life Cost. Every transaction belongs to exactly one wallet, so you can keep separate accounts — for example a personal wallet, a household wallet, or a travel budget — without mixing their numbers together. All registered users automatically have access to every wallet, making Life Cost suited to shared finances across a household or team.

How Wallets Work

When a new wallet is created via the API, the server immediately adds every existing user to it through the user_wallet association table. This means no manual permission grants are ever required: all wallets are visible to all users from the moment they are created. Each user remembers which wallet they were browsing last. When the page loads, the app reads current_user.last_visited_wallet_id to decide which wallet’s transactions and calendar data to show. Switching wallets from the UI writes this value back to the database immediately.

Wallet Data Model

The Wallet model is defined in app/models.py:
class Wallet(db.Model):
    id          = db.Column(db.Integer, primary_key=True)
    name        = db.Column(db.String(150), unique=True, nullable=False)
    description = db.Column(db.String(300))

    users = db.relationship(
        "User",
        secondary=user_wallet,
        back_populates="wallets"
    )
FieldTypeNotes
idInteger (PK)Auto-incremented primary key
nameString (150)Unique across the system; required
descriptionString (300)Optional free-text description
usersRelationshipMany-to-many via the user_wallet table
The many-to-many join table carries a created_at timestamp recording when each user was linked to each wallet:
user_wallet = db.Table(
    'user_wallet',
    db.Column('user_id',    db.Integer, db.ForeignKey('user.id'),    primary_key=True),
    db.Column('wallet_id',  db.Integer, db.ForeignKey('wallet.id'),  primary_key=True),
    db.Column('created_at', db.DateTime, default=datetime.utcnow)
)

Switching Wallets in the UI

The page header contains a <select> dropdown (#groupSelector) pre-populated with every wallet the logged-in user belongs to. The currently active wallet is pre-selected based on last_visited_wallet_id. When the user picks a different wallet, the change handler in ajax.js fires a POST /update_last_visited_wallet request and then reloads the page so every widget (table, calendar, charts) refreshes for the newly selected wallet:
$('#groupSelector').change(function () {
    let selectedGroupId = $(this).val();
    $.ajax({
        url: '/update_last_visited_wallet',
        method: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({ wallet_id: selectedGroupId }),
        success: function (response) {
            location.reload();
        }
    });
});
The server endpoint accepts a JSON body with a single wallet_id field, updates current_user.last_visited_wallet_id, and commits to the database:
@app.route('/update_last_visited_wallet', methods=['POST'])
@login_required
def update_last_visited_wallet():
    data = request.get_json()
    wallet_id = data.get('wallet_id')
    current_user.last_visited_wallet_id = wallet_id
    db.session.commit()
    return jsonify({"message": "Last group updated successfully"}), 200

Multi-User Wallet Sharing

Every wallet is shared across all users automatically. When POST /add_wallet is called, the handler iterates over every User row and appends the new wallet to each user’s wallets relationship before committing:
all_users = User.query.all()
for user in all_users:
    user.wallets.append(new_wallet)
db.session.commit()
Likewise, when a brand-new user logs in for the first time via Google OAuth, the set_user_wallets helper assigns all existing wallets to that user and sets last_visited_wallet_id to the first wallet found.
When a new wallet is created, every existing user is automatically added to it via the user_wallet association table. No manual permission step is required.

Get Wallet

GET /wallet/<id> — Retrieve a single wallet by ID.

Add Wallet

POST /add_wallet — Create a wallet and assign it to all users.

Update Last Visited

POST /update_last_visited_wallet — Persist the active wallet for the current user.

Build docs developers (and LLMs) love