01 - Introduction
From code to business value
Confidentiality note (NDA): This case study describes a real B2B deployment (print / e-commerce). The client's name and hard financial figures are withheld to protect trade secrets and operational advantage. The focus is business logic, system architecture (workflows), and API integrations only.
Many junior developers obsess over frameworks and reinventing the wheel. While growing an automation agency (AIAA / MaDevo) and shipping B2B systems, I internalized a core product-engineering rule: businesses do not buy code. They buy reclaimed time, scalability, and fewer mistakes.
Our client hit classic growing pains. Rapid sales growth and a rising volume of B2B orders created operational chaos. Data lived in fragments across Trello, email, BaseLinker, and accounting in wFirma.
Manual re-entry by the sales team created massive bottlenecks:
Human error: Mistyped VAT IDs and amounts carry serious legal and accounting risk under Poland's KSeF regime.
SEO damage: Pasting duplicate product copy (duplicate content) across marketplaces crushed listing visibility.
Wasted hours: Sales spent time copy-pasting statuses instead of selling and serving customers.
Solution architecture
After a deep process review, we designed and shipped an integrated ecosystem. Instead of a bespoke greenfield app, we leaned on agentic workflows on n8n.
Disparate systems were wired with strict REST API contracts; where unstructured text needed a human-quality judgment, we used LLMs (GPT-4o) as decision and analysis engines.
Below, I break down two core processes that transformed document flow and product lifecycle for this client.
02 - Workflow #1
Workflow #1: Intelligent product factory (BaseLinker API)
Business problem: Creating new e-commerce product variants was a repetitive bottleneck. The sales team spent hours manually pairing images with SKU codes and copying descriptions. Reused copy (duplicate content) also hurt SEO rankings.
We built a system that fully automated this path while preserving strict data integrity.
Architecture and data flow
We shipped a hybrid setup (smart frontend + agentic backend) to stay reliable even under heavy batch processing:
Smart queueing (rate-limit protection): users upload CSV plus image packs in a web panel. The frontend queues requests and sends them sequentially instead of blasting all API calls at once (HTTP 429).
Edge security: the n8n flow starts with a webhook that validates an encrypted password embedded in the payload. Unauthorized traffic is rejected before it touches business logic or API limits.
Inventory-state validation: before AI is invoked, the workflow performs a GET query to BaseLinker, resolves a reference product by SKU, and aborts early with a Discord alert when the reference is missing.
Plain JavaScript > blind low-code trust
Visual workflow engines are excellent for API orchestration, but complex data transformations can become fragile when composed only from low-code blocks. The hardest engineering task was deterministic mapping of dozens of images to correct product variants.
[ engineering detail ]
AI as an SEO engine (LLM)
When the operator enabled AI mode, raw product parameters were sent to GPT-4o. The model did not control business logic - it acted as a specialized copywriting engine, producing unique titles and rich HTML descriptions from strict prompts.
The final payload (new SKU, JS image mapping, AI-generated HTML) was sent to BaseLinker via addInventoryProduct, creating a sell-ready offer immediately.
Business ROI: Time to list 50 products dropped from hours of manual work to minutes of background processing, with fewer image-mapping mistakes and stronger marketplace visibility from unique descriptions.
03 - Workflow #2
Workflow #2: Autonomous accountant (Trello → wFirma)
Business problem: invoicing recurring B2B orders meant manually copying technical notes from Trello cards into wFirma. Multi-line orders could take ~15 minutes each. With KSeF tightening compliance, even tiny VAT ID or amount mistakes create legal exposure and correction work.
The fix: an AI agent for unstructured text, paired with hard validation against public registries and the accounting API.
Data architecture: from chaos to JSON
We followed a human-in-the-loop pattern: the automation does the grunt work, but a human still owns the final send decision.
Event-driven trigger: moving a Trello card to “ready for invoice” fires a webhook into n8n.
AI data extraction (Gemini / GPT-4o): the LLM reads messy card copy, extracts the VAT ID, and turns line items into a clean JSON array (product name + net price).
JS guardrail: why we do not trust AI in finance
Language models infer context well, but arithmetic and strict accounting precision are not their strength. There is no room for hallucinated totals.
[ data sanitization & math ]
LLM output never goes straight to the ERP. A JavaScript data sanitizer enforces:
- Comma-to-dot normalization for decimal numbers.
- Mathematical checks on rates and totals.
- Counting how often “Produkt” appears in the source text so skipped line items surface before money moves.
GUS validation and booking (wFirma API)
Before issuing a document, contractor data must be legal and current:
Official VAT whitelist lookup (MF registry): query the Polish VAT taxpayer list with the extracted NIP, pull the legal name and address, and overwrite casual typos from the card.
wFirma REST API: iterate the sanitized product array (e.g. .map()) and create one multi-line invoice.
Draft status: the document lands in normal_draft; the operator gets Discord + Trello signals, reviews the draft in wFirma in seconds, and accepts when satisfied.
Business ROI: removed manual retyping (tens of hours monthly), NIP checks keep contractor master data consistent, and drafts preserve financial oversight before issuance.
04 - Cost optimization
Cost optimization: from event-driven to batch (AU03)
Automation can backfire: once it is reliable, volume rises. With KSeF rolling out, accounting firms started charging per processed document (on the order of ~PLN 0.80 / invoice in this story). Issuing one invoice per tiny Trello job for recurring B2B clients created avoidable operational cost.
The architectural fix was a shift from event-driven invoicing to batch processing.
Relational buffer (PostgreSQL)
Rather than hitting wFirma the moment a card closes, we buffered state in the database:
Storage (deferral): when sales closes a card, n8n still extracts data with AI, but instead of invoicing immediately it inserts a row into PendingOrders in PostgreSQL as pending and updates Trello labels.
Scheduled job (CRON): on the last day of the month at 15:00, the server kicks off the batch run.
[ sql aggregation ]
Heavy transformation stays in SQL: a GROUP BY VAT ID (NIP) pass collapses hundreds of micro-orders into one optimized JSON payload per B2B client.
Single API call
After SQL aggregation, n8n performs exactly one wFirma API call per contractor - one consolidated multi-line invoice (for example ~20 jobs in a month). Rows in the buffer flip to invoiced.
Business ROI: replacing dozens of small invoices with a handful of consolidated ones slashed per-document accounting fees (north of 90% in this deployment narrative), reduced ERP noise, and simplified financial reporting.
05 - Takeaways
Key takeaways: a process engineer's mindset
Running an automation agency (AIAA) and shipping B2B systems reframed engineering for me. Businesses rarely pay for "clean code" or the trendiest framework. They pay for reliability, reclaimed time, and a budget that does not leak.
Key takeaways
01 - Never trust AI blindly (data sanitization)
LLMs (Gemini, GPT-4o) excel at unstructured text, not at precise arithmetic. In finance-grade document flows, AI must sit inside hard validation gates - for example sum checks in JavaScript.
02 - APIs are the foundation; low-code is the orchestrator
Tools like n8n do not replace an engineer; they accelerate integration. A dependable workflow still demands deep REST literacy-auth headers, pagination, rate limits. When blocks fall short, you write code and SQL.
03 - Human-in-the-loop as a safety shield
For ERP and invoicing, automation should augment people, not erase accountability. Draft documents can collapse 15 minutes of work into ~10 seconds while keeping humans in control of what ships.
Final reflection: as a product engineer I try to see systems whole. .NET, React, Python, SQL, n8n are just kit in the toolbox. The real leverage is walking into a business, finding data-flow bottlenecks, and shipping an architecture that works-and earns-for the client around the clock.
MaDevo - current offer and contact at madevo.pl.