Part of the Billy ecosystem.
Project Links: CRM for Billy App (Frontend) • API for Billy Web (this repo) • API for Billy AI (LocalAI/Ollama)
This repository provides the backend API for the CRM for Billy App, serving as the main business logic and data layer of the system. Built with TypeScript + Express + MySQL, it exposes endpoints for products, employees, users, sales, purchases, analytics, and taxes. Additionally, it integrates with the Billy AI API to extend conversational intelligence and summarization features to the frontend application.
Swagger documentation is included for quick endpoint exploration.
src/
├── index.ts # App entry: server, middleware, routes
├── config.ts # Environment variables and constants
├── db/connection.ts # MySQL connection helper
├── routes/ # REST endpoint definitions under /api
├── controllers/ # Business logic for each resource
├── middleware/ # (Future) Authentication / validation layers
├── utils/ # Helper utilities
└── database_update.sql # SQL schema and seed data
This API is the core backend that connects the CRM for Billy App frontend with persistent storage and analytics capabilities.
- Frontend Communication: All CRUD operations for products, employees, and sales are consumed by the React frontend.
- AI Layer Communication: The
/api/chatbot/insert-textendpoint connects directly to the Billy AI API, forwarding conversation inputs for summarization and context processing. - Analytics: Endpoints such as
/api/ingresos/totalesand/api/crecimientofeed visual data to the analytics module in the main app.
- Node.js 18+
- npm, pnpm, or yarn
- A running MySQL instance (local or remote)
Example .env configuration:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=hackmty
DB_PORT=3306
PORT=3000Ensure this server runs before starting the CRM for Billy App. For AI-driven endpoints, also start the Billy AI API.
npm install
npm run dev # Development (nodemon + ts-node)
npm run build # Compile TypeScript to /dist
npm start # Run production buildWhen started, the server logs:
🚀 Server running on port <PORT>
Swagger UI available at: ➡️ http://localhost:/api-docs (Default: http://localhost:3000/api-docs)
CRUD endpoints under /api/productos.
Manage employee records under /api/empleados.
User management endpoints under /api/usuarios.
Record and retrieve transactions under /api/ventas and /api/compras.
Provide insights for the CRM for Billy App:
/api/ingresos/totales— total income./api/egresos/totales— total expenses./api/crecimiento— growth over custom date range./api/impuestos/calcular— calculate monthly taxes.
Connects to Billy AI API:
POST /api/chatbot/insert-text— forwards conversation text for processing.
Use database_update.sql to initialize or update the schema:
mysql -u root -p hackmty < ./database_update.sqlYou can also run it using GUI tools like DBeaver or MySQL Workbench.
curl http://localhost:3000/api/productoscurl -X POST http://localhost:3000/api/productos -H "Content-Type: application/json" -d '{"nombre":"Producto A","precio":100.0,"stock":50}'curl -X POST http://localhost:3000/api/chatbot/insert-text -H "Content-Type: application/json" -d '{"texto":"Hoy vendimos 20 unidades de producto B"}'- Logs startup and endpoint access to the console.
- Returns structured JSON errors (4xx and 5xx) for easy debugging.
- Future plans include integrating authentication, role-based access, and automated tests (Jest/Vitest).
- A future Docker Compose setup could orchestrate MySQL + both APIs (Billy Web API + Billy AI API) for easier deployment.
- Fork this repo.
- Create a branch (
git checkout -b feature/YourFeature). - Commit your changes.
- Push to your branch and open a PR.
To test features end-to-end, link your local clone with the CRM for Billy App frontend and the Billy AI API.
Licensed under the ISC License — see package.json.
README updated for integration with the full Billy project — (CRM Frontend + Web API + AI API) — on October 26, 2025.