🧠 NeuraPro Part 2: Multi-tenant AI Backoffice, Traceability Engine and Conversational Gateway

Building the technical core before chat: architecture, traceability, and the solid foundation that will allow AI to generate real value


Continuation of NeuraPro Part 1

🧠 NeuraPro – Part 2

From Idea to a System That Breathes Alone

“I dreamed of doing everything from my phone, talking to my business as if it were a person. But AI doesn’t live on magic: it lives on data with shape. That’s why I turned off the chat and built the foundation first: a solid back-office, with traceability, normalization, and services that don’t break.”


⚙️ General Architecture

Quick overview:

The NeuraPro Backoffice sits at the center of the ecosystem, with three main layers —API, Services, and Databases— connected externally with human interfaces (web/desktop) and AI agents (local and cloud).

1
2
3
4
5
6
7
8
9
10
11
12
13
Web/Desktop Clients ──┐
                       │
Telegram/WhatsApp ──▶ API Gateway (FastAPI)
                       │
             ┌─────────▼──────────┐
             │   Services Layer   │
             │ Stock | Sales |     │
             │ Traceability | Chat │
             └─────────┬──────────┘
                       │
                   SQLite Multi-tenant
                       │
     Local AI (Mistral/Ollama) ←→ Cloud AI (GPT)

📸 NeuraPro in Action


📊 Technical Snapshot – NeuraPro R2.0.0

Indicator Status
Automated tests 221 (services + endpoints)
Active services 30+
Main modules Sales, Stock, Income, Transfers, Traceability, Notifications
Performance improvement 5–10× with indexes and composite indexes
Multi-industry databases 7 templates per industry (cloned per tenant)
Deployment environment Cloud VPS (preprod/prod, Git sync)

1) Why I Paused Chat and Built the Core First

The final idea was always clear: being able to do everything from your phone using natural language. Talk to your business as if it were a person and get useful responses.

But I quickly realized that to achieve this, I first needed a solid system where the data was reliable and well-structured. It’s not just about passing data to AI: it’s about passing data the way AI needs it to make new recommendations and actually help.

So I forgot about the WhatsApp chat and all that, and told myself: I’m going to build a stable desktop system, with centralized services that can be called from other services. A secure and simple back-office that can be queried for data, both for AI and for the client in their office to easily complete and enter sales, income, manage stock, etc.

The foundation, the heart of NeuraPro, had to be that back-office. Without that, any AI I integrated would just be a nice chatbot that couldn’t generate real value.


2) The Journey: Two Steps Forward, One Back

I was inspired by other projects I’m involved with through work or hobbies, and I’d take two steps forward and one back. Hours of frustration to build a traceability system that was really painful to construct.

Traceability was the most complicated part. Every sale, transfer, or adjustment had to be recorded without duplicates or concurrency errors. I put myself in the client’s shoes to figure out what would be the most intuitive way for someone who isn’t good with computers to register and manage their business. That helped me a lot: thinking like an end user, not like an engineer. I achieved it after weeks of trial and error, sometimes rewriting the same thing three times until the system breathed stable. I had to simplify everything to the extreme: clear interfaces, direct messages, and flows anyone can follow without endless manuals.

And although there’s still much to improve, at least I feel more confident that the services I’ve created seem solid and stable.


3) API and Services: 21 Routers, 30+ Living Components

FastAPI (app/main.py) coordinates 21 routers across web portals, internal APIs, and bots. Each route checks basic permissions and hands off work to the services layer.

Inside the Services Layer live 30+ reusable pieces:

  • SalesService / SalesActionService: create, cancel, and recalc sales together with StockService and TraceabilityService.
  • StockService: get_stock_* helpers that return real stock after income, sales, transfers, and adjustments.
  • TraceabilityService + MovementsService: keep events idempotent and flows atomic when transfers spawn new batches.
  • NotificationService / MonitoringService: configurable thresholds, deduped alerts, and SQL audit trails.
  • ObservabilityService: wraps operations with context managers and applies PerformanceThresholdsService limits to spot slowdowns.

Web clients, APIs, and future AI agents all consume these same trusted services.


4) Current NeuraPro Architecture

NeuraPro R2.0.0 is built on FastAPI and SQLite multi-tenant, organised in three main layers:

  • API Layer (FastAPI): 21 modules (/sales, /stock, /income, /traceability, /chat).
  • Services Layer: more than 30 services (StockService, SalesService, TraceabilityService, NotificationService, ChatService, etc.).
  • Databases: isolated structure per client (data/users/{industry}/{client_id}/) with 7 internal DBs.
  • Frontend: HTML + Jinja2 + Bootstrap 5 + lightweight JS.

The entire system follows one rule: a single source of truth.

It doesn’t matter if a user or an AI queries: everyone uses the same routes and services.


5) Multi-tenant Data in Production

All persistence lives under data/users/{industry}/{client_id}/{db}.db, resolved at runtime by get_user_db_path. During startup, init_users_database() checks critical columns, generates the default admin tenant, sets up notification tables, and activates audit triggers.

Instead of cloning databases manually, the provisioning flow picks the industry template, applies indexes, and validates consistency before opening the tenant. That keeps data coherent even as the platform onboards new SMEs with completely different catalogs and daily operations.


6) Testing, Metrics, and Observability

  • Total tests: 257
  • Passing: 155 (96.9% of active tests)
  • Failing: 0

Core Operations

Operation Tests What we check Result
Sales 23 Register, cancel, stock/price/KPI/permission validation ✅ 23/23
Income 10 Register, normalize prices, states, totals ✅ 5/5 core (others xfail/skip)
Transfers 7 Moves, stock, traceability ✅ 7/7
Stock 10 Dynamic calculation, filters, states ✅ 10/10
Adjustments 7 Positive/negative, permissions ✅ 7/7
VAT 9 Purchases, sales, history ✅ 9/9
Chat 95 Intents, multi-channel, permissions, E2E ✅ 95/95
Bot Gateway 29 APIs, contracts, views ✅ 22/22 active (76%)
Permissions 21 Roles, endpoints, chat ✅ 21/21
Traceability 3 Events, filters ✅ 3/3
Smoke 5 Health checks (API, DB, services, UI) ✅ 5/5
Products 3 Create, configure, list ✅ 3/3

Conclusion: Full coverage across services and endpoints; core, interface, and security at 100%. Production-ready.


7) Flows That Work in Real Life

  • Income: normalizes data, creates a unique batch, records traceability, and updates stock atomically.
  • Sales: validates stock, calculates VAT, records transaction, and generates traceability; rollback if anything fails.
  • Transfers: moves stock between warehouses preserving costs and logging exit/entry events.
  • Notifications: background jobs check thresholds (stock, expirations, cancellations) and alert without duplicates.

Every flow uses the same services, so web, APIs, and future AI agents rely on the same trustworthy data.


8) Notifications: Let the System Warn Before the User

NotificationService schedules alerts; each user defines stock, expiration, or cancellation thresholds. Background jobs log audits and avoid duplicates.

Examples:

  • Minimarket: “Milk 5 units, bread 2, eggs 12—time to reorder.”
  • Bakery: “Flour will last two days at current pace.”
  • Avocado producer: “Hass stock in Lo Ovalle dropped to 45 kg; plan replenishment.”

Next step: deliver these alerts via Web/Telegram/WhatsApp and turn them into recommendations (“reorder”, “review margins”).


9) How It Feels Now

NeuraPro R2.0.0 feels stable. Running 257 tests across services and endpoints before each commit keeps me calm: if I break something, the suite catches it.

Deploying on a VPS with pre-prod/prod environments synced with Git lets me experiment safely. I’ve paid down technical debt and now trust the base.

I’m past the “will it crash?” stage. Now I can focus on what’s next: connecting AI and turning data that already breathes on its own into real value.


10) Traceability as a Bridge to AI

Every record keeps who, when, and what changed. That memory answers “why is stock lower?” by showing the sales, transfers, or adjustments involved. For AI it’s not just a number: it can see that three sales were cancelled and a transfer happened, then suggest checking customers or warehouses. Structured traceability lets agents understand what happened and why, not just how much remains.


11) What’s Next: Integration Strategy

Upcoming milestones:

  • Chat gateway (Web, Telegram, WhatsApp) running with clear permissions.
  • AI templates to package client context + question → structured answer.
  • Local AI (Ollama/Mistral) for fast, offline-friendly queries.
  • Cloud AI (GPT or similar) for deeper analysis and recommendations.
  • AI MVP in production for real queries by Q1-2026.

The business model moves in parallel, but the immediate focus stays on the tech stack and the MVP.


✨ Final Reflection

This entire journey was born thanks to AI and tools like Cursor IDE, which allowed me to think, test, and build in a completely new way.

But I also realized that my previous experience —leading projects, solving real problems, and dealing with technical frustrations— was what gave me the patience to push when nothing worked.

I’ve always been one of those who push until something moves, and NeuraPro is the result of that mindset: a mix of curiosity, discipline, and resilience.

I don’t know exactly what the future will bring, but I do know something:

the experience gained so far is invaluable, and as long as I keep the same energy, the system —and I— will keep evolving.


✍️ Claudio from ViaMind
“Dare to imagine, create, and transform.”


🔗 Connect with the Story


Comments
Comments are shared between English and Spanish versions.

Subscribe

Get a monthly email with the best posts on innovation, technology, and the future. No spam.

* required

Intuit Mailchimp