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 ↓ HTTPSCloudflare Worker ↓Tricount APIThe 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.
| Feature | Processing Location |
|---|---|
| Read Ledger | Worker → Tricount |
| Add / Modify Expense | Worker → Tricount |
| Member Data | Worker → Tricount |
| Category Statistics | Browser |
| Monthly Expense Trend | Browser |
| Individual Payments / Contributions | Browser |
| Settlement Suggestions | Browser |
| CSV Export | Browser |
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 pushGitHub Actions ↓ buildPublic Pages Repository ↓指定子目錄 ↓GitHub PagesThe deployment token is stored in:
Settings→ Secrets and variables→ Actions→ Repository secretsFor example:
TOOLS_DEPLOY_TOKEN = ********Non-sensitive settings like the Worker URL are stored in Repository Variables:
API_BASE = https://example.workers.devAfter that, you only need to:
git pushGitHub 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 ProxyCloudflare Worker→ 呼叫 Tricount API
# GitHub Actions SecretTOOLS_DEPLOY_TOKEN
# GitHub Actions VariableAPI_BASE=https://example.workers.dev
# 發布git pushWrap-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 ( ˘ω˘ )