- Live Demo URL (
https://stockfacil.onrender.com) is currently NON-FUNCTIONAL. - The application can be run successfully by setting up a local PostgreSQL database (see Quick Start) or by deploying to a new cloud service with an active database connection string.
A comprehensive API for inventory, customer, and supplier management built with modern technologies and best practices.
StockFacil is a full-featured inventory management API designed for small to medium businesses. It provides complete control over stock, pricing, commercial relationships, and product variants with a modern, secure, and scalable architecture.
- π’ Multi-tenant Architecture - Complete data isolation per user
- π Advanced Inventory Management - Products with variants, stock control, and alerts
- π₯ Customer & Supplier Management - Complete contact database
- π Secure Authentication - JWT with email verification system
- π§ Email Integration - Nodemailer with Gmail OAuth2
- π Real-time Statistics - Inventory and business insights
- π Advanced Search & Pagination - Efficient data handling
- π Complete API Documentation - Swagger/OpenAPI 3.0
- π Production Ready - Deployed with security best practices
- Node.js - Runtime environment
- Express 5 - Web framework
- PostgreSQL - Primary database
- Prisma ORM - Database toolkit and query builder
- JWT - Authentication and authorization
- Nodemailer - Email service with OAuth2
- Swagger - API documentation
- Helmet - Security headers
- Rate Limiting - API protection
- CORS - Cross-origin resource sharing
- Input Validation - express-validator
- Password Hashing - bcryptjs
- SQL Injection Protection - Parameterized queries
- Render - Cloud platform
- Environment-based Configuration - Development/Production
- Health Check Endpoints - System monitoring
- Node.js (v18+)
- PostgreSQL (v13+)
- Gmail account for email service
-
Clone the repository
git clone https://github.com/Maite2003/stockfacil.git cd stockfacil -
Install dependencies
npm install
-
Environment Setup
cp .env.example .env
Configure your
.envfile: IMPORTANT: Update the DATABASE_URL to point to a LOCAL or NEW PostgreSQL instance.# Database DATABASE_URL="postgresql://username:password@localhost:5432/stockfacil" # JWT JWT_SECRET="your-super-secret-jwt-key" # Email (Gmail OAuth2) GMAIL_USER="your-email@gmail.com" GMAIL_CLIENT_ID="your-google-oauth-client-id" GMAIL_CLIENT_SECRET="your-google-oauth-client-secret" GMAIL_REFRESH_TOKEN="your-google-oauth-refresh-token" # Frontend URL FRONTEND_URL="http://localhost:3000" # Server PORT=3000 NODE_ENV=development
-
Database Setup
npx prisma migrate dev npx prisma generate
-
Start the server
npm run dev
-
Visit the API
- API Base URL:
http://localhost:3000 - Documentation:
http://localhost:3000/api-docs
- API Base URL:
POST /auth/register- User registrationPOST /auth/login- User loginGET /auth/profile- Get user informationPATCH /auth/profile- Update user profileDELETE /auth/profile- Delete user accountPOST /auth/send-verification- Send email verificationGET /auth/verify-email/:token- Verify email addressGET /auth/verification-status- Check verification status
GET /products- List products (with pagination, search, sort)POST /products- Create productGET /products/:id- Get product detailsPATCH /products/:id- Update productDELETE /products/:id- Delete product
GET /products/:productId/variants- List variantsPOST /products/:productId/variants- Create variantGET /products/:productId/variants/:id- Get variantPATCH /products/:productId/variants/:id- Update variantDELETE /products/:productId/variants/:id- Delete variant
GET /customers- List customers (with pagination, search, sort)POST /customers- Create customerGET /customers/:id- Get customer detailsPATCH /customers/:id- Update customerDELETE /customers/:id- Delete customer
Similar endpoints available for /suppliers
GET /categories- List categoriesPOST /categories- Create categoryGET /categories/:id- Get categoryPATCH /categories/:id- Update categoryDELETE /categories/:id- Delete category
GET /suppliers/:supplierId/variants- Get supplier's variantsPOST /variant-suppliers- Create relationshipGET /variant-suppliers/:id- Get relationshipPATCH /variant-suppliers/:id- Update relationshipDELETE /variant-suppliers/:id- Delete relationship
GET /stats/inventory- Inventory statisticsGET /stats/agenda- Customer/supplier statisticsGET /health- Health checkGET /- API information
Every table includes user_id as a foreign key, ensuring complete data isolation between users:
-- Example: All queries automatically filter by user
SELECT * FROM products
WHERE user_id = :current_user_id AND id = :product_id;- Users - Authentication and user profiles
- Products - Product catalog with selling prices
- Product_Variants - Stock control and variant management
- Categories - Hierarchical product organization
- Customers/Suppliers - Contact management
- Variant_Suppliers - Purchase price and supplier relationships
-
Stock Control in Variants Only
- Consistent stock management across simple and complex products
- Default variants for simple products
- Independent stock per variant
-
Separate Customer/Supplier Tables
- Clear role separation
- Future scalability for role-specific features
-
JWT Authentication with Email Verification
- Secure token-based authentication
- Professional email templates with OAuth2
All list endpoints support:
- Pagination:
?page=1&limit=10 - Search:
?search=term(searches across relevant fields) - Sorting:
?sortBy=name&sortOrder=asc
Response format:
{
"products": [...],
"pagination": {
"currentPage": 1,
"totalPages": 5,
"totalItems": 48,
"itemsPerPage": 10,
"hasNextPage": true,
"hasPreviousPage": false,
"nextPage": 2,
"previousPage": null,
"startItem": 1,
"endItem": 10
}
}- Professional HTML email templates
- JWT tokens with 24-hour expiration
- Gmail OAuth2 integration for reliable delivery
- Graceful error handling
- Single-use verification tokens
- Simple Products: Automatic default variant creation
- Complex Products: Multiple variants with independent stock
- Unified API: Same interface regardless of complexity
- Stock Alerts: Configurable minimum stock notifications
npm run dev # Start development server
npm run build # Build for production
npm start # Start production server
npm run db:migrate # Run database migrations
npm run db:reset # Reset database (development only)# Reset database
npx prisma migrate reset
# Generate Prisma client
npx prisma generate
# View database
npx prisma studioNODE_ENV=production
DATABASE_URL="your-postgresql-connection-string"
JWT_SECRET="your-secure-production-jwt-secret"
GMAIL_USER="your-business-email@gmail.com"
GMAIL_CLIENT_ID="your-google-oauth-client-id"
GMAIL_CLIENT_SECRET="your-google-oauth-client-secret"
GMAIL_REFRESH_TOKEN="your-google-oauth-refresh-token"
FRONTEND_URL="https://your-frontend-domain.com"- Helmet - Security headers (XSS, clickjacking protection)
- Rate Limiting - 5 req/15min for auth, 100 req/15min for API
- CORS - Properly configured for production domains
- Input Sanitization - Protection against malicious input
- Environment-based Configuration - Different settings per environment
Complete API documentation is available at:
- Production: https://stockfacil.onrender.com/api-docs
- Local:
http://localhost:3000/api-docs
The documentation includes:
- Complete endpoint descriptions
- Request/response schemas
- Authentication requirements
- Interactive testing interface
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Maite Nigro
- GitHub: @Maite2003
- LinkedIn: maite-nigro
- Email: maitenigro03@gmail.com
- Built with modern Node.js and Express 5
- Database design inspired by multi-tenant SaaS best practices
- Email templates designed for maximum compatibility
- Security implementation following OWASP guidelines
β If you found this project helpful, please give it a star!