How to build a ChartMogul alternative

How to build a ChartMogul alternative with reviewed invoice imports, explicit MRR rules, and a churn table. Follow the model, prompts, checks, and deployment.

  • vibe-coding
  • guide

How to build a ChartMogul alternative starts with a recurring revenue ledger from a reviewed CSV.

We will build a private recurring revenue report from a CSV you review before import. Start with the ChartMogul catalog prompt. Read the ChartMogul post for the narrower replacement idea. The calculations here are chosen rules for your tool; document them before comparing them with another service.

How to build a ChartMogul alternative with explicit MRR rules

Choose one currency and subscription invoices only. Keep one-off work, taxes and refunds outside recurring revenue. Store them separately when they appear in the source file, rather than accidentally treating them as subscriptions. Use integer minor units for money and a decimal or rational intermediate for annual normalization.

For this v1, a monthly subscription worth 1200 cents contributes 1200 cents MRR while active. An annual subscription worth 12000 cents contributes 1000 cents. Define rounding at the aggregate boundary and preserve the original amount. These example numbers are fixtures, not claims about any vendor’s revenue methodology.

Table Purpose Important fields
Import batch Reviewed source Hash, status, mapping version
Subscription Stable recurring agreement External id, customer id, currency
Period Service coverage Start, end, amount, interval
Cancellation Explicit ending Effective date, reason

Step 1 Preview an import before writing it

Require explicit column mapping for subscription id, customer id, amount, currency, service dates and billing interval. Do not guess dates from locale. Show the normalized value next to the original cell. A bad row should identify its row number and reason without putting the entire customer file into logs.

Build a CSV preview importer for one currency and monthly or annual plans.
Require stable subscription and source-row ids. Validate integer minor
units, ISO dates, service boundaries and supported intervals. Preview
new rows, duplicates and conflicts. Save the reviewed file hash and column
mapping. Confirmation imports exactly that preview in one transaction.

Upload a file containing one invalid currency, a duplicated id and a reversed date range. Confirm that nothing is imported before approval. Change the file after preview and ensure its old confirmation token cannot import the new bytes. Bound the number of rows and file size, including quoted multiline fields.

Step 2 Normalize recurring value without double counting

Keep the original interval and amount alongside normalized MRR. The first version accepts only clean non-overlapping coverage periods for each subscription. If an imported adjustment overlaps an existing period, show a conflict for review. Avoid summing two invoice rows merely because both mention the same customer.

Implement MRR normalization for monthly and annual subscription periods.
Preserve original amount and interval. Reject overlapping service periods
for the same subscription unless explicitly resolved in preview. Exclude
one-time charges and taxes. Use exact decimal arithmetic for intermediate
values and a documented rounding policy for display totals.

Use one monthly subscription and one annual subscription with the same normalized value. Their contributions should match. Then add a second subscription for the same customer. Customer count stays one while subscription count becomes two. Test an annual amount that does not divide evenly by twelve and inspect the exported precision.

Step 3 Build month-end snapshots

Choose the instant represented by a month-end snapshot. Use a named reporting timezone and half-open coverage periods. A period is active when its start is at or before the snapshot and its end is after it. Show this convention near the report so someone reviewing a cancellation can reproduce the result.

Build month-end MRR snapshots using documented timezone and half-open
coverage periods. For each subscription, select one valid active period.
Return normalized revenue, active subscription count and unique customer
count. Include source batch ids. Show unavailable when unresolved import
conflicts affect the requested snapshot instead of inventing a total.

Create a subscription ending exactly at the snapshot and another starting exactly there. Only the second is active under this rule. Add a gap between two periods and confirm it stays a gap. A paid invoice with no service dates should remain an import problem until someone supplies the missing context.

Step 4 Derive churn from transitions

For this build, subscription churn means positive recurring value in the previous snapshot and zero in the next. Customer churn requires all of that customer’s subscriptions to end. A customer dropping one of two subscriptions is contraction, rather than customer churn. Keep these labels separate on the dashboard.

Compare consecutive snapshots and classify new, expansion, contraction,
reactivation and churn using documented subscription history. Show a
reconciliation table where opening MRR plus changes equals closing MRR.
Distinguish subscription churn from customer churn. Preserve source ids
for every change so the owner can inspect the underlying coverage periods.

Test a plan upgrade, a cancelled subscription and a customer keeping a second subscription. Hand-calculate the reconciliation with a tiny fixture before using a real file. Late imports should recompute affected snapshots and carry a changed-source marker. Do not silently rewrite a report someone already exported without providing its source batch references.

Keep live billing sync outside the first release

Skip bank reconciliation, foreign exchange, payment collection and live billing webhooks. Add a second source only after its identifiers and correction rules are defined. Use the FreshBooks guide if you need invoice creation. This tool answers questions about recurring agreements after data has been reviewed.

Keep the server responsible for ownership

Use Astro server rendering with ordinary forms, HTMX for partial updates, and Alpine for local preview state. A Node.js server and SQLite are enough for the first deployment. Use a single persistent disk with backups. If your hosting platform cannot keep a local database across deployments, choose a managed relational database before adding real records.

Put the authenticated account id in server session state. Never trust a hidden owner field submitted by a form. Every lookup should constrain the record by both its id and its account. A record that exists for another account should remain inaccessible through exports, detail pages, background jobs and attachment downloads too.

Implement an authenticated Astro application with server-rendered forms.
All reads and mutations enforce account ownership on the server. Add CSRF
protection, bounded inputs and parameterized queries. HTMX responses use
the same authorization as full pages. Keep credentials server-only. Provide
a complete empty state and a separate recoverable database-error state.

Create two test accounts. Save a record under one, then substitute its id in requests from the other. Exercise a normal HTML request and the partial-update endpoint. Both must refuse access. Signing out must invalidate the session rather than only hiding the navigation. Keep sensitive values out of request logs and exception pages.

Make writes safe to retry

A browser can lose the response after a database commit. Refreshing the page or pressing the button again should return the result of that operation. Give important mutations a unique request id and save it with the outcome inside the transaction. Reusing that id with different input should produce a conflict, rather than quietly reusing an unrelated result.

Use revision checks for edits from multiple tabs. The form submits the revision it loaded. A stale revision gets a clear conflict screen that preserves the attempted input. The owner can reload the current record and choose which change to make. Avoid automatically merging fields whose relationship affects a calculation or publication decision.

Add idempotency tokens to important mutations and revision checks to edits.
Persist the request token and state change together. Duplicate identical
requests return the saved outcome. A reused token with different input is
rejected. A stale edit preserves the attempted values and offers reload.
Test a lost response after commit and two concurrent edits.

Check the database after retrying. A reassuring success message is insufficient if duplicate rows remain underneath. Also stop the process during a write in a test database. On restart, the operation should be complete or absent. Document where an external service would require a separate retry policy before introducing one.

Deploy with a restore path

Build the app, run its migrations against an empty staging database, and create the first owner through a private setup route or command. Disable that setup route afterwards. Configure HTTPS, secure session cookies and a persistent volume. Keep the database outside the release directory so replacing application files cannot replace live data.

Make a consistent database backup with the database engine’s supported backup mechanism. Copying an actively written file without understanding its journal mode can produce an incomplete backup. Encrypt backup storage through your hosting provider or an established backup tool, and keep access credentials outside the source repository.

Write deployment instructions for the chosen Node.js host, persistent
SQLite volume, migrations, HTTPS and server secrets. Add a health endpoint
that reports readiness without exposing records. Back up the database and
restore it into an isolated instance. Verify representative records and
permissions after restore. Document rollback with schema compatibility.

After deployment, use the real hostname. Sign in, create a harmless fixture, complete the core workflow, export it and sign out. Check the index and detail view after each change. Then try a missing id, a request with an expired session, and an intentionally unavailable database in staging. Each failure should tell the owner what they can do next.

Keep operational logs small. Record action ids, elapsed time and error categories, while omitting private payloads. Set an explicit retention policy and check disk usage. Before inviting anyone else, restore one backup into a separate environment and confirm that the application starts with the restored data. Save the recovery instructions beside the deployment configuration.

Related articles

Read all articles →