


















BGV Mayorista
Cordoba, Argentina
B2B platform for a wholesale distributor, with access through approved accounts, per-customer pricing and discounts, minimum orders and integrated payments. It includes an AI assistant for inquiries and lead capture, plus a panel to manage products, orders, analytics and content.
IncludesWholesale-only pricingMercado PagoAI assistant










Overview
The challenge
Links
Private — client project
System architecture
A monorepo with npm workspaces and two applications. The Next.js 15 frontend acts as a backend-for-frontend: its API routes forward the session and the visitor's IP to the Express backend, which owns the business logic, authentication and integrations. PostgreSQL with Prisma is the single source of truth, and every commercial rule BGV needs to adjust (minimum order, approval, bank details, site copy) lives in configuration tables, so changing it needs no deploy.
Application Architecture
- Next.js App Router frontend with API routes as a proxy to the backend, forwarding the session and the visitor’s IP.
- Express backend with around 100 REST handlers split into public, customer and admin routes.
- Persistence organized in per-entity DAOs over Prisma.
- The AI assistant is a package split into core and adapters, kept in sync with a dedicated script.
- The chat streams its responses through a proxy, with a body parser separate from the rest of the API.
Platform Features
- Public catalog by category, with search by product code and prices only for approved accounts.
- Wholesale sign-up that creates the user and the company in a single transaction.
- Cart by closed pack or single unit, with minimum-order validation.
- Checkout with Mercado Pago or bank transfer (5% discount), plus coupons.
- Order tracking with two separate states: payment, and fulfilment and shipping.
- AI assistant with lead capture and an editable knowledge base.
- SEO: robots, sitemap, canonicals and entity schema.
Data Model
- 25 Prisma models and 32 versioned migrations.
- Single-row configuration tables for bank details, wholesale rules and currency.
- Soft-deleted orders and a unique payment id, which makes repeated notifications idempotent.
- Hierarchical categories (parent and children) with persisted ordering.
- Chat conversations and leads stored as full JSON, with indexed columns to sort and deduplicate.
Authentication
- JWT
- bcrypt
- Google Sign-In
- Token versioning
- Account linking
- Password reset
- Customer / admin roles
- Company status
Infrastructure & deployment
Deployed on a dedicated Ubuntu 24.04 VPS with atomic releases and automatic rollback, without managed services: PostgreSQL 16, Nginx and PM2 run on the same server.
Hosting & Deploy
- Each release is built in a new folder; only then are migrations applied and the current symlink switched.
- If any step fails, a trap rolls back to the previous release, and the last 5 releases are kept.
- PM2 runs two frontend and two backend instances in cluster mode, with reloads, backoff restarts and a memory limit.
- Nginx as reverse proxy with Let’s Encrypt HTTPS for the domain with and without www.
Secrets & Storage
- Environment files encrypted with dotenvx; the keys live in a shared folder that each release links to.
- Uploaded photos and optimized variants live in a shared folder, so they survive every deploy.
- A diagnostics script shows the resolved configuration without exposing values.
Logs & Monitoring
- PM2 logs
- Log rotation
- Diagnostics script
Built with
One-time payment per order, in Argentine pesos, through Mercado Pago Checkout Pro or bank transfer. The backend recalculates the amount on the server and creates a preference that carries the order id as its external reference, which is what makes it possible to reconcile a payment even when the notification never arrives.
Mercado Pago
- Preferences created with external reference and notification URL; paying requires an approved wholesale account.
- The webhook validates the HMAC-SHA256 signature with a constant-time compare and logs the detail of every rejection.
- When the buyer returns to the site, a sync endpoint updates the payment.
- A job reconciles pending orders between 5 minutes and 24 hours old every 5 minutes, 20 at a time.
- An existing pending order is reused instead of creating a new one.
Bank Transfer
- The order stays pending with a 5% discount applied.
- The customer receives the bank details by email and the BGV team gets a notice.
- If the bank details are incomplete or disabled, the option is hidden at checkout.
Order States
- Pending
- In process
- Approved
- Rejected
- Cancelled
- Refunded
Sandbox & Testing
- A sandbox testing guide and a script that detects whether the credentials are test or production.
- End-to-end tests for the purchase flow, bank transfer, webhook and reconciliation.
A complete wholesale e-commerce platform: public site, customer area, admin panel with an AI assistant, catalog loading scripts and documented deploy infrastructure.
Public Site & Customers
- Home with an editable hero, categories, FAQ and coverage map.
- Catalog and product detail pages.
- About, How to buy and Contact pages.
- Wholesale sign-up, login (including Google) and password recovery.
- Cart, checkout and payment result screens.
- Profile with orders and account security.
Admin Panel
- Dashboard, products, categories with drag-and-drop ordering, orders with detail, coupons, statistics, transfer details and site content.
- AI assistant: conversations, leads, unanswered questions, knowledge base and settings.
Internal Tools
- Catalog extraction from the supplier’s PDF, with photo mapping and optimization.
- Seed of the real catalog.
- Email previews and an end-to-end check of the shared cache.
Documentation
- README
- VPS deploy
- AI assistant
- Payments
- Google OAuth
- Security
- SEO