556 字
3 分鐘
瀏覽次數
Tricount Web: Turning Your Existing Ledger into Your Own Reporting Tool
2026-10-06

Conclusion#

By using GitHub Pages for the user interface and reports, and Cloudflare Worker to connect with Tricount, you can extend its functionality to include adding expenses, settlement, statistics, and export features.

Where It’s Suitable#

  • You already have a Tricount ledger and wish to continue using its existing data.
  • You want to add custom reports such as category statistics, expense trends, and member contributions.
  • The frontend aims to maintain static deployment via GitHub Pages.
  • You are comfortable using a non-official API and accept the risk of needing adjustments if the API changes.

Workflow Steps#

1. Connecting to Tricount with Cloudflare Worker#

The overall architecture remains simple:

GitHub Pages
↓ HTTPS
Cloudflare Worker
↓
Tricount API

The frontend only needs to call its own Worker:

const API_BASE = "https://example.workers.dev";
// 前端透過 Worker 取得帳本資料
const response = await fetch(`${API_BASE}/api/group`);
const data = await response.json();

The Worker is mainly responsible for:

  • Calling the Tricount API.
  • Handling necessary Request Headers.
  • Controlling allowed API operations.
  • Preventing sensitive configurations from appearing directly in frontend code. The Worker doesn’t need to be a full backend; it only serves as an API Proxy.

2. Implementing Accounting, Settlement, and Reports on the Frontend#

After obtaining ledger data, most statistical functions can be processed directly in the browser.

FeatureProcessing Location
Read LedgerWorker → Tricount
Add / Modify ExpenseWorker → Tricount
Member DataWorker → Tricount
Category StatisticsBrowser
Monthly Expense TrendBrowser
Individual Payments / ContributionsBrowser
Settlement SuggestionsBrowser
CSV ExportBrowser

For example, calculating category totals:

const totals = {};
expenses.forEach(item => {
// 依分類累計支出
totals[item.category] =
(totals[item.category] ?? 0) + item.amount;
});

Features like pie charts, monthly expense trends, and member statistics can all be calculated on the frontend and then displayed using charting libraries like Chart.js.

3. Automating Website Publication with GitHub Actions#

If the source code is in a private repository and GitHub Pages is in another public repository, you can use GitHub Actions for automatic deployment.

Private Repository
↓ git push
GitHub Actions
↓ build
Public Pages Repository
↓
指定子目錄
↓
GitHub Pages

The deployment token is stored in:

Settings
→ Secrets and variables
→ Actions
→ Repository secrets

For example:

TOOLS_DEPLOY_TOKEN = ********

Non-sensitive settings like the Worker URL are stored in Repository Variables:

API_BASE = https://example.workers.dev

After that, you only need to:

git push

GitHub Actions will automatically build and update GitHub Pages.

Flowchart#

flowchart TD
A[使用者開啟 GitHub Pages] --> B[輸入 Tricount 分享連結]
B --> C[前端呼叫 Cloudflare Worker]
C --> D[Worker 呼叫 Tricount API]
D --> E[取得帳本資料]
E --> F[回傳 GitHub Pages]
F --> G[記帳 / 結算]
F --> H[報表 / 統計]

Additional Notes#

  • Non-official API carries maintenance risks: After Tricount updates, the Endpoint or Header originally used might need adjustment.
  • Do not put tokens in the frontend: JavaScript sent to the browser can essentially be viewed by anyone.
  • Worker should restrict API behavior: Do not make it a public proxy that can forward any URL.

Commands / Examples Summary#

Click to expand
# 前端
GitHub Pages
→ 呼叫 API_BASE
# API Proxy
Cloudflare Worker
→ 呼叫 Tricount API
# GitHub Actions Secret
TOOLS_DEPLOY_TOKEN
# GitHub Actions Variable
API_BASE=https://example.workers.dev
# 發布
git push

Wrap-up#

The core of this architecture is simple: Tricount handles ledger data, GitHub Pages manages operations and reports, and Cloudflare Worker handles API integration.

Each component does its part, making it much cleaner and less likely to evolve into a backend monolith ( ˘ω˘ )

Tricount Web: Turning Your Existing Ledger into Your Own Reporting Tool
https://joyceowo.github.io/posts/en/3f1a78ea09fa80738d61e3f4ae658f60/
作者
JoyceOwO
發佈於
2026-10-06
許可協議
CC BY-NC-SA 4.0