Precivox is a Multi-Tenant Software as a Service (SaaS) platform engineered to serve as the business intelligence core for small and medium-sized enterprises (SMEs). The platform's flagship feature is its Advanced Costing Engine, which replaces fragmented spreadsheets with a unified, data-driven ecosystem for precise recipe costing, inventory management, and real-time profitability analysis.
The heart of Precivox is a sophisticated mathematical engine designed to provide 100% visibility into production costs and profit margins:
-
Granular Recipe Costing: Automatically calculates the total cost of products by aggregating individual ingredient and packaging costs.
-
Operational Expense Integration: Factors in indirect costs such as labor, utilities, and operational expenses to provide a true "cost to produce".
-
Asset Depreciation Tracking: Includes equipment depreciation in the costing logic, ensuring long-term business sustainability.
-
Dynamic Profit Margin Analysis: Allows owners to set desired profit margins and instantly see the recommended selling price vs. actual costs.
-
Forensic Waste (Merma) Management: Implements specialized logic where ingredient waste is calculated by cost, while finished product waste is calculated by sale price to measure lost revenue potential.
The project utilizes a decoupled architecture consisting of a robust RESTful API and a modern administrative frontend.
-
Language/Framework: Python 3.9+ with Flask.
-
Database: PostgreSQL, chosen for its relational integrity and complex aggregations required for the costing engine.
-
Multi-Tenancy: Implements logical data isolation where every query is strictly scoped via a
tenant_id. -
Services: Cloudinary (Image Storage) and SendGrid (Transactional Emails).
-
Library/Framework: React 18+ powered by Vite.
-
UI/UX: Bootstrap 5 and custom CSS, featuring responsive dashboards.
-
BI Visualization: Interactive charts for cost vs. sales trends using Recharts.
-
Super Admin (Platform Owner): Manages the tenant lifecycle, global statistics, and verified payment history through a dedicated
tenant_paymentsAPI. -
Admin (Tenant/Business Owner): Operates within a completely isolated workspace to manage the entire supply chain, from raw ingredients to final sales orders.
The platform recently underwent a comprehensive engineering sprint to ensure the reliability of the Costing Engine and core infrastructure:
-
Costing Engine Optimization
- SQL Precision: Implemented
COALESCElogic in backend queries to prevent$ NaNerrors in pricing displays when data is missing. - Formula Standardization: Standardized fields like
costo_por_unidadandunidad_medidaacross the stack to ensure calculation accuracy between the React frontend and Flask backend. - Waste Logic Refactoring: Corrected a critical bug in ingredient waste calculation (previously defaulting to $0) to ensure accurate loss tracking.
- SQL Precision: Implemented
-
Infrastructure & Security
- URL Sanitization: Implemented custom middleware in
app.pyto handle malformed URLs and prevent broken redirect chains during API calls. - CORS & Auth: Unified the security layer and resolved persistent "Failed to fetch" errors by standardizing
@admin_requireddecorators. - Data Serialization: Standardized JSON conversion for all modules to ensure seamless data flow to the frontend dashboards.
- URL Sanitization: Implemented custom middleware in
- Node.js (v18+ recommended)
- Python (v3.9+ recommended)
- A running PostgreSQL server
-
Navigate to the backend directory:
cd backend -
Create and activate a virtual environment:
# On macOS/Linux python3 -m venv venv source venv/bin/activate # On Windows python -m venv venv .\venv\Scripts\activate
-
Install the required Python packages:
pip install -r requirements.txt
-
Create a
.envfile in thebackenddirectory and populate it with your credentials. You can use.env.exampleas a template. Key variables include:DATABASE_URLSECRET_KEYSENDGRID_API_KEYCLOUDINARY_CLOUD_NAME,CLOUDINARY_API_KEY,CLOUDINARY_API_SECRETGOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRETSUPPORT_EMAIL_ADDRESS
-
Initialize the database by running the SQL commands in
schema.sqlagainst your PostgreSQL instance.
- Navigate to the frontend directory:
cd admin-panel/mi-app - Install the required Node.js packages:
npm install
- Create a
.envfile in theadmin-panel/mi-appdirectory and add the following line, pointing to your running backend server:VITE_API_URL=http://127.0.0.1:5000
-
Start the Backend Server: In the
backenddirectory, run:python app.py
The API will be available at
http://127.0.0.1:5000. -
Start the Frontend Development Server: In a new terminal, navigate to the
admin-panel/mi-appdirectory and run:npm run dev
The admin panel will be accessible at
http://localhost:5173.
- Multi-Tenant Landing Pages: Dynamic, customizable public-facing pages for individual tenants.
- Internationalization: Full codebase and UI migration to English standards.
- Security Audit: End-to-end forensic audit of data isolation and RBAC.
- Dockerization: Full containerization for scalable deployment on environments like Render.
├── admin-panel/ # React frontend application
│ └── mi-app/
├── backend/ # Flask backend API
├── landing-page/ # Public-facing static website
└── README.md # You are here