Skip to content
Analytics & operations platform

BI & Operations Platform

Role-based analytics with an alert engine and an AI assistant on a live ERP API.

The internal operations platform of a 30-store fashion retailer: live sales BI, campaign impact measurement, a P&L per store, shelf and warehouse stock, a daily action list for every role, and an AI assistant that answers questions on live ERP data, all on top of a custom ERP API.

Internal company system, not public
Role
Sole developer (app + ERP API)
Timeline
Aug 2026 – present
Status
In production since Sep 2026
Scale
30 stores · 5 user roles
BI & Operations Platform main screen
01

The problem

A multi-brand fashion retailer with 30 stores and a central warehouse ran its promotions, sales reporting and stock decisions out of a legacy ERP. Management couldn't tell whether a campaign actually worked, store managers had no quick view of what was selling or missing on their own shelves, and the warehouse team decided which stores to restock by hand.

02

What I built

Designed and built the full-stack application and the ERP API it consumes as sole developer. It launched in September 2026 as a campaign tracker and grew into the company's daily operations platform. A BI module compares sales, margin and categories against last year for the whole chain or any single store, with a store table each user can arrange for themselves.

Each campaign gets a "Did it work?" report that measures it against the 28 days before, the same dates last year, and the stores that weren't in the campaign as a control group. A Today list gives every role its actions for the day (refill a size, move stock between stores, mark down what isn't selling, follow up on transfers from the warehouse) and measures a week later whether each action paid off. Finance gets a P&L per store that ranks the stores needing attention by the euros at stake and compares every cost line with the chain's median store.

An "On the floor" view flags each store's best sellers, missing sizes and items running out, a warehouse view suggests which stores to send stock to, and a global product search (Ctrl+K) opens a stock matrix across every location, including transfers still in transit. An AI assistant answers questions about the figures in plain language and builds Excel files on request. Every view exports to Excel, and the app installs on phones as a PWA in English and Albanian, with five roles (admin, head office, store manager, stock manager, finance) that each see only their own stores and data.

03

Under the hood

Built on Next.js 16 (App Router, Server Components, Server Actions) with Prisma and PostgreSQL, on top of a custom ERP REST API with API-key auth. The ERP client is server-only, so the key never reaches the browser, and a per-user rate limit keeps one stuck tab or script from flooding the ERP's query queue for everyone. Every page, Server Action and ERP request goes through a single access layer that reads the user's role from the database on each request, so a demotion takes effect immediately and cost data never reaches store-level roles.

An alert engine runs inside the Next.js server process every 30 minutes: it fetches each data need once per round instead of once per user, evaluates everyone's rules (sales drops against last year, best sellers out of stock, campaigns starting or ending), skips anything already reported, and delivers the results as web push notifications. The AI assistant uses the Claude API with tool use: 17 read-only tools wrap the same ERP endpoints the pages use and run as the signed-in user, its daily suggestions are written once per person and reused all day, and usage and cost are logged per user. Phones running the installed app pick up a new deploy on their own: the build carries its git commit, and the app reloads once when it comes back to the screen.

It runs under PM2 on a shared Windows Server alongside a legacy app, using host-based Nginx routing behind Cloudflare.

  • TypeScript
  • Next.js
  • React
  • Tailwind CSS
  • Prisma
  • PostgreSQL
  • Claude API
  • Zod
  • JWT
  • Web Push
  • ExcelJS
  • PWA
  • Nginx
  • PM2
  • Cloudflare
04

Results

  • Campaigns are judged on evidence: every report compares the campaign with the 28 days before, the same dates last year and a control group of stores that weren't in it.
  • Manual ERP reports were replaced by live dashboards, and any view can be exported to Excel in one click.
  • Every role starts the day with a short list of concrete actions, and each action is checked a week later for whether it actually paid off.
  • Finance sees which stores need attention and why, ranked by the money at stake, instead of reading a P&L per store.
  • Anyone can ask the AI assistant a question about the figures and get an answer or an Excel file back, within the data their role is allowed to see.
  • Head office, store managers, the stock team and finance each get their own view through dedicated roles, with cost data kept to head office.
  • Push alerts flag sales drops and best sellers out of stock without anyone having to open a report.
05

Technical challenges

Problems I ran into while building and running it, and how I solved them.

  1. A headline KPI that didn't double-count+

    Summing revenue across live campaigns counted the same sales twice whenever two campaigns overlapped in the same stores. The headline metric became a weighted gross margin (Σ profit ÷ Σ net) across live campaigns, deduplicated by identical store and date scope.

  2. Authentication that actually verifies+

    The first middleware only checked that a session cookie existed. It now verifies the JWT signature and expiry, rotates refresh tokens in middleware (Server Components can't set cookies), and every Server Action re-checks the session and role. Roles are read from the database on each request, so a demotion takes effect immediately.

  3. Protecting the ERP from its own users+

    A report page fires around ten ERP queries, so one stuck tab or script could fill the ERP's queue for everyone. Each user gets a rate limit (requests per minute and in flight), responses are cached for two minutes, and the ERP client is server-only so its API key never reaches the browser.

  4. An AI assistant that can't leak data+

    Instructions in a prompt can't be trusted to enforce permissions. Each of the assistant's 17 tools runs as the signed-in user, so a store manager's question only ever reaches their own store and cost data only reaches head office, whatever the model asks for. Answers are rounded and trimmed so each question stays cheap, and the model is told when a list was cut.

  5. Phones stuck on yesterday's version+

    Staff use the app installed on their phones, which kept running an old version after a deploy until someone forced a refresh. Each build now carries its git commit as its id, and the app reloads itself once when it comes back to the screen after a new deploy.

  6. Background alerts without a job server+

    Instead of adding another process, the alert scheduler starts inside the Next.js server through instrumentation. Each 30-minute round fetches every data need once (not once per user), evaluates all rules in memory, remembers what it already reported so nothing is sent twice, and pauses at night.

  7. Time zones in two places+

    Locale-dependent date formatting caused hydration mismatches, fixed with deterministic UTC formatting and a server-provided "now". Later, presence timestamps written in the Windows server's local time made everyone look online for two hours; writes now store UTC explicitly.