A progressive Node.js framework for building efficient and scalable server-side applications.
RedFox API - Backend API for RedFox Point of Sale system built with NestJS, TypeORM, and supporting MySQL/PostgreSQL databases.
$ npm installThe application requires the following environment variables. Create a .env file in the root directory with the following configuration:
| Variable | Description | Default | Required |
|---|---|---|---|
NODE_ENV |
Environment mode (development/production) | development |
No |
PORT |
Server port | 3000 |
No |
HOST |
Server host | 0.0.0.0 |
No |
CORS_ORIGIN |
Allowed CORS origin | * |
No |
APP_KEY |
Application key (used for JWT) | - | Yes |
APP_PUBLIC_URL |
Public base URL of this API (used to build absolute asset URLs like the company logo). Example: https://your-api.com (no /api) |
- | No |
| Variable | Description | Default | Required |
|---|---|---|---|
APP_DB_PROVIDER |
Database provider (mysql or postgres) |
mysql |
No |
| Variable | Description | Default | Required |
|---|---|---|---|
MYSQL_DB_HOST |
MySQL host | localhost |
No |
MYSQL_DB_PORT |
MySQL port | 3306 |
No |
MYSQL_DB_USER |
MySQL username | root |
No |
MYSQL_DB_PASSWORD |
MySQL password | `` (empty) | No |
MYSQL_DB_NAME |
MySQL database name | redfox-db |
No |
| Variable | Description | Default | Required |
|---|---|---|---|
PG_DB_HOST |
PostgreSQL host | localhost |
No |
PG_DB_PORT |
PostgreSQL port | 5432 |
No |
PG_DB_USER |
PostgreSQL username | postgres |
No |
PG_DB_PASSWORD |
PostgreSQL password | postgres |
No |
PG_DB_NAME |
PostgreSQL database name | redfox-db |
No |
| Variable | Description | Default | Required |
|---|---|---|---|
DB_SYNC |
Auto-sync database schema (true/false) | false |
No |
DB_LOGGING |
Enable query logging (true/false) | false |
No |
| Variable | Description | Default | Required |
|---|---|---|---|
APP_KEY |
JWT secret key (same as application key) | - | Yes |
| Variable | Description | Default | Required |
|---|---|---|---|
FACTURAPI_API_KEY |
FacturaAPI API key | - | Yes |
| Variable | Description | Default | Required |
|---|---|---|---|
UPLOAD_DEST |
Upload directory path | ./uploads |
No |
- Uploaded files are served by the API under:
/api/uploads/* - Example (company logo):
GET /api/uploads/company/<filename> - Notes:
- The storage folder is resolved from the process working directory (typically
<redfox-api>/uploads). - If you set
APP_PUBLIC_URL, thecompany-settingsendpoint will returnlogoUrlas an absolute URL.
- The storage folder is resolved from the process working directory (typically
# Application
NODE_ENV=development
PORT=3000
HOST=0.0.0.0
CORS_ORIGIN=*
APP_KEY=your-super-secret-app-key-change-this-in-production
# Database Provider
APP_DB_PROVIDER=mysql
# MySQL Configuration
MYSQL_DB_HOST=localhost
MYSQL_DB_PORT=3306
MYSQL_DB_USER=root
MYSQL_DB_PASSWORD=your_password
MYSQL_DB_NAME=redfox-db
# PostgreSQL Configuration (alternative)
# PG_DB_HOST=localhost
# PG_DB_PORT=5432
# PG_DB_USER=postgres
# PG_DB_PASSWORD=your_password
# PG_DB_NAME=redfox-db
# Database Options
DB_SYNC=false
DB_LOGGING=false
# FacturaAPI
FACTURAPI_API_KEY=sk_test_your_api_key_here
# Uploads
UPLOAD_DEST=./uploads# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod# Generate migration
$ npm run migration:generate -- -n MigrationName
# Run migrations
$ npm run migration:run
# Revert last migration
$ npm run migration:revert
# Show migration status
$ npm run migration:show
# Drop schema (development only)
$ npm run migration:drop
# Reset DB: drop all tables and run migrations (development only)
$ npm run db:reset# Run all seeds
$ npm run seed
# Run permissions seed only
$ npm run seed:permissions# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:covThe API is available at http://localhost:3000/api with the following main endpoints:
/api/health- Health check endpoint/api/auth- Authentication endpoints/api/company-settings- Company settings (singleton) + logo uploadGET /api/company-settingsPUT /api/company-settingsPOST /api/company-settings/logo(multipart/form-data, field:logo)- Logo is served at:
GET /api/uploads/company/<filename>
/api/users- User management/api/products- Product management/api/inventory- Inventory management/api/invoices- Invoice management (with FacturaAPI integration)/api/sales- Sales management/api/warehouses- Warehouse management- And more...
For detailed API documentation, see INVOICE_API.md for invoice-related endpoints.
See DOCKER.md for detailed Docker setup and deployment instructions.
redfox-api/
├── src/
│ ├── config/ # Configuration files (database, app)
│ ├── controllers/ # API controllers
│ ├── services/ # Business logic services
│ ├── models/ # TypeORM entities
│ ├── dtos/ # Data Transfer Objects
│ ├── modules/ # NestJS modules
│ ├── guards/ # Authentication guards
│ ├── decorators/ # Custom decorators
│ ├── db/
│ │ ├── migrations/ # Database migrations
│ │ └── seeds/ # Database seeds
│ └── main.ts # Application entry point
├── uploads/ # Uploaded files directory
└── package.json
- Multi-database support: MySQL and PostgreSQL
- JWT Authentication: Secure token-based authentication
- FacturaAPI Integration: Electronic invoicing (CFDI) support
- Certification pack sync: Clients are synced with the pack on create/update (
ClientPackSyncService;pack_client_id/pack_client_responsein client). Products are catalog only; sync to the pack runs when applying a reception or when closing a warehouse (aperturas → inventory). Pack data is stored in inventory (pack_product_id,pack_product_response). See Certification pack sync below. - File Uploads: Image and document upload support
- TypeORM: Database ORM with migrations
- Validation: Class-validator for DTOs
- CORS: Configurable CORS support
- Clients: On create/update,
ClientPackSyncServicesyncs the client with the active certification pack (Facturapi). The client entity storespack_client_idandpack_client_response. Create/update endpoints return{ client, pack_sync_success, pack_sync_error? }. - Products: Products are catalog only (no price in the
productstable; price comes from inventory via reception or warehouse opening). Sync to the pack runs when:- A reception is applied (products are transferred to inventory with price), or
- A warehouse is closed (warehouse openings are transferred to inventory with price).
InventoryPackSyncServicebuilds product data from inventory (product + price), calls FacturapicreateProduct/updateProduct, and storespack_product_idandpack_product_responsein the inventory record. Product create/update no longer sync with the pack.
- NestJS Documentation
- TypeORM Documentation
- FacturaAPI Documentation
- Docker Setup Guide
- Invoice API Documentation
This project is private and proprietary.