Skip to content

Update#23

Closed
farhanmahee wants to merge 12 commits intofreestyle-sh:mainfrom
farhanmahee:main
Closed

Update#23
farhanmahee wants to merge 12 commits intofreestyle-sh:mainfrom
farhanmahee:main

Conversation

@farhanmahee
Copy link

@farhanmahee farhanmahee commented Nov 19, 2025

TL;DR

This PR pivots the project from an AI application builder to a comprehensive, production-ready Enterprise Resource Planning (ERP) system, complete with a new backend, frontend, database schema, and extensive documentation.

Why we made these changes

To build and launch a complete ERP solution with modules for sales, purchasing, inventory, accounting, and reporting. This change establishes the foundational backend, frontend, and database for the new system, replacing the previous project scope entirely.

What changed?

  • Project Pivot: Replaced the previous AI-centric codebase with a new ERP system. This includes a complete overhaul of the README.md, the main application page (src/app/page.tsx), and the entire database schema.
  • Backend API: Added a full suite of RESTful API endpoints to manage all core ERP functions, including organizations, users, master data (customers, products, suppliers), and transactions (sales, purchases, inventory, accounting).
  • Frontend UI: Implemented a new modular frontend with a shared layout (src/app/erp/layout.tsx) and dedicated pages for Sales, Purchase, Inventory, Accounting, Masters, and Reports. A new login page was also added using @stackframe/stack.
  • Database: Introduced a comprehensive new database schema (src/db/schema.ts) using Drizzle ORM to support all ERP modules, along with the initial database migration script.
  • DevOps & Documentation:
    • Added a GitHub Actions workflow to automate the creation of Neon database branches for PRs.
    • Added extensive project documentation covering setup, API reference, deployment, and feature roadmaps.
  • Configuration: Updated .gitignore to exclude .env files and added VS Code extension recommendations and settings.

Validation

No validation steps were provided.

Description generated by Mesa. Update settings

…ers, payment receipts, products, purchase orders, sales orders, and reports

- Added GET and POST endpoints for journal vouchers to manage journal entries and ledger updates.
- Implemented payment receipts handling with invoice payment status updates.
- Created product management routes for fetching and adding products.
- Developed purchase order routes with item management and total calculations.
- Added sales order routes for managing sales and associated items.
- Implemented various report generation endpoints for purchase, sales, stock, and trial balance.
- Introduced user management routes with password handling and organization-specific settings.
- Added utility functions for API responses, currency formatting, date formatting, and document number generation.
- Integrated multi-language support for English and Bangla in the application.
…les, masters, and reports

- Created ERP layout with sidebar navigation and user menu
- Developed Masters page for managing master data (customers, suppliers, products, users)
- Implemented Purchase page for tracking purchase orders with statistics and search functionality
- Added Sales page for managing sales orders with analytics and quick actions
- Created Reports page for generating various financial reports with date range filtering
Copy link
Author

@farhanmahee farhanmahee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update branch by branch

Copy link

@mesa-dot-dev mesa-dot-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performed full review of 74316d1...3037bc1

Analysis

  1. Complete Lack of Authentication/Authorization: All API routes are unprotected with no session validation or permission checks, allowing any client to access any organization's data simply by manipulating the orgId parameter - a critical security vulnerability.

  2. Database Schema Issues: Multiple definitions exist for the same logical entities (customers, suppliers, purchaseOrders), creating conflicts. The schema also lacks proper indexing and essential constraints on required fields.

  3. Financial Data Integrity Risks: Financial operations lack database transaction management, creating risk of data corruption. Critical issues include incorrect weighted average cost calculation, no validation that debits equal credits in journal entries, and race conditions in stock balance updates.

  4. Data Type Inconsistencies: The system uses string storage for financial amounts in the API layer but decimal precision in the database, leading to precision loss. Direct use of parseFloat() on financial calculations introduces compounding rounding errors.

  5. Inadequate Error Handling: Financial operations that fail mid-process don't have rollback mechanisms, potentially leaving the system in an inconsistent state during failures.

Tip

Help

Slash Commands:

  • /review - Request a full code review
  • /review latest - Review only changes since the last review
  • /describe - Generate PR description. This will update the PR body or issue comment depending on your configuration
  • /help - Get help with Mesa commands and configuration options

53 files reviewed | 8 comments | Edit Agent SettingsRead Docs

});

// Supplier Master
export const supplierTable = pgTable("suppliers", {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High

Critical: Duplicate table definition. Both supplierTable (line 179) and suppliersTable (line 403) are defined, which will cause database migration failures. The same issue exists for customers (lines 229 & 383) and purchase orders (lines 82 & 497). You must remove the duplicate definitions and ensure all foreign key references point to the correct table name.

Agent: 🤖 General • Fix in Cursor

} = body;

// Create payment receipt
const newReceipt = await db
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High

Race condition and missing transaction: The payment receipt creation (line 40) and invoice status update (line 70) are not atomic. If multiple concurrent payments are made for the same invoice, the status could be incorrectly calculated or one payment could overwrite another's status update. Wrap lines 40-73 in db.transaction() and add optimistic locking.

Agent: 🤖 General • Fix in Cursor

.from(invoiceTable)
.where(eq(invoiceTable.id, invoiceId));

if (invoice.length > 0) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High

Critical business logic flaw: The payment status calculation (lines 59-68) only considers the current payment amount against the invoice total, but doesn't account for previous payments. If a customer makes multiple partial payments, only the last payment amount is compared to the invoice total, causing incorrect status. You need to query and sum all existing payments for this invoice before determining the status.

Agent: 🤖 General • Fix in Cursor

): number {
const totalQuantity = previousQuantity + newQuantity;
if (totalQuantity === 0) return 0;
return (previousCost + newCost) / totalQuantity;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High

Critical mathematical error: The weighted average cost calculation is incorrect. Currently: (previousCost + newCost) / totalQuantity. This should be: (previousQuantity * previousCost + newQuantity * newCost) / totalQuantity. The current formula will produce severely incorrect inventory valuations, leading to financial misstatements.

Agent: 🤖 General • Fix in Cursor

debit: decimal("debit", { precision: 15, scale: 2 }).default("0"),
credit: decimal("credit", { precision: 15, scale: 2 }).default("0"),
balance: decimal("balance", { precision: 15, scale: 2 }).default("0"),
transactionDate: timestamp("transaction_date
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High

Critical syntax error: Line 258-259 has a corrupted timestamp definition with a line break inside the string "transaction_date\n". This will prevent the schema from compiling. Should be timestamp("transaction_date").defaultNow().

Agent: 🤖 General • Fix in Cursor

).toString(),
});

// Update or create stock balance
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High

Critical race condition: Stock balance updates (lines 78-117) are not wrapped in a database transaction. If multiple GRNs are processed concurrently for the same product/warehouse, this will cause lost updates and incorrect stock quantities. Wrap the entire GRN creation and stock update logic in db.transaction() to ensure atomicity.

Agent: 🤖 General • Fix in Cursor

.select()
.from(stockBalanceTable)
.where(
eq(stockBalanceTable.warehouseId, warehouseId) &
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High

Critical SQL syntax error: Using bitwise AND operator & instead of logical AND for combining WHERE conditions. This will cause the query to fail. Use Drizzle's and() helper: where(and(eq(stockBalanceTable.warehouseId, warehouseId), eq(stockBalanceTable.productId, item.productId))).

Agent: 🤖 General • Fix in Cursor

@farhanmahee farhanmahee closed this by deleting the head repository Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant