A demand forecasting and sales analytics platform that predicts product demand using machine learning based on historical sales data.
Chronos helps businesses optimize inventory management and understand sales patterns through:
- Sales Analytics Dashboard - Real-time metrics with month-over-month comparisons
- ML-Based Demand Forecasting - 10-day rolling predictions using Facebook Prophet
- Automated Data Synchronization - ETrade ERP integration with scheduled syncing
- Multi-Tenant Architecture - Company-scoped data isolation and user management
Chronos follows a microservices architecture with five main services orchestrated via Docker Compose:
-
chronos-ui (Port 3000)
- Tech Stack: Next.js 14, React 18, TypeScript, Tailwind CSS
- Purpose: Web application frontend with authentication, dashboards, and analytics
- Features: React Query for state management, Radix UI components, Recharts for visualization
-
chronos-app-api (Port 5001)
- Tech Stack: ASP.NET Core, Entity Framework Core, SQL Server
- Purpose: Main REST API with JWT authentication and business logic
- Features: Swagger/OpenAPI, Quartz.NET scheduling, handler-based architecture
-
chronos-data-science (Port 8000)
- Tech Stack: Python, Flask, Facebook Prophet, Pandas
- Purpose: Machine learning service for demand forecasting
- Features: Time series analysis, seasonal patterns, log transformation
-
chronos-app-integration
- Tech Stack: .NET Background Service, Quartz.NET, SQLite
- Purpose: Automated ETrade ERP data synchronization
- Features: Batch processing, incremental sync, duplicate tracking
-
mssql (Port 14333)
- Tech Stack: Microsoft SQL Server 2022
- Purpose: Primary database for application data
- Docker (20.10 or higher)
- Docker Compose (2.0 or higher)
- Minimum 4GB RAM allocated to Docker
- Ports 3000, 5001, 8000, and 14333 available
git clone <repository-url>
cd chronosSet the database password in compose.yaml or via environment variable:
export MSSQL_PASSWORD="YourSecurePassword123!"The password must meet SQL Server requirements (uppercase, lowercase, numbers, special characters, minimum 8 characters).
docker compose upThis will:
- Build all service images
- Start SQL Server and wait for health check
- Run database migrations
- Start the API, frontend, data science service, and integration worker
- Frontend: http://localhost:3000
- API: http://localhost:5001
- Swagger UI: http://localhost:5001/swagger
- Data Science API: http://localhost:8000
On first run, the application will:
- Initialize the database schema via EF Core migrations
- Trigger immediate background jobs (predictions and ETrade sync)
- Be ready for user registration and login
docker compose downTo remove volumes and reset the database:
docker compose down -vChronos uses JWT-based authentication:
- Login:
POST /api/authwith email and password - Receive: JWT token valid for 6 hours
- Authorize: Include token in
Authorization: Bearer <token>header
Passwords are hashed using SHA-256 before storage.
POST /api/auth- User login
GET /api/user/product- List products (paginated, filterable, sortable)GET /api/user/product/top-sold- Top selling productsGET /api/user/prediction- Fetch demand predictionsGET /api/user/metrics/sales- Sales metrics with MoM comparisonGET /api/user/sale- Sales history- User and company management endpoints
POST /api/sync/product- Create products from external systemPUT /api/sync/product- Update productsPOST /api/sync/sale- Create sales from external system
Full API documentation is available via Swagger UI at http://localhost:5001/swagger when the API service is running.
The dashboard provides comprehensive sales metrics:
- Monthly Revenue - Total sales with month-over-month percentage change
- Sales Quantity - Total items sold with MoM comparison
- Average Ticket - Average sale value with trend analysis
- Products Sold - Unique products sold count
- Average Selling Price - Mean product price across sales
- Daily Breakdown Charts - Visual comparison of current vs. previous month
Navigate to the dashboard after login to view real-time analytics.
Chronos predicts future product demand using Facebook Prophet:
- 10-Day Rolling Forecast - Daily predictions for the next 10 days
- Seasonal Pattern Recognition - Accounts for weekend effects and trends
- Historical Comparison - Predictions displayed alongside actual sales data
- Per-Product Analysis - Individual forecasts for each product
- Algorithm: Facebook Prophet (time series forecasting)
- Features: Log transformation, day-of-week indicators, weekend regressors
- Training Data: Historical daily sales aggregated by product
- Output: Date and predicted quantity for 10 future days
Access predictions via the Analytics page after sales data is synced.
Chronos runs two automated background jobs using Quartz.NET:
- Schedule: Every Sunday at 2:00 AM
- Trigger: Also runs immediately on application startup
- Process:
- Iterates through all companies
- Deletes previous predictions
- Aggregates daily sales statistics per product
- Calls data science service for ML predictions
- Stores new predictions in database
- Schedule: Every Monday at 2:00 AM
- Trigger: Also runs immediately on application startup
- Process:
- Syncs products from ETrade database (create/update)
- Syncs sales since last successful sync (incremental)
- Updates sync timestamp in SQLite tracking database
- Batch processing (1,000 records per batch)
- Concurrent processing with semaphore limits
Job execution is logged and can be monitored via application logs.
All entities inherit from a base class with Id (Guid), CreatedAt, and UpdatedAt timestamps.
- Multi-tenant base entity
- Fields: Name, SocialReason, CNPJ, Address, City, State, ZipCode
- Purpose: Data isolation and tenant management
- Scoped to Company
- Fields: Name, Email, Password (hashed)
- Purpose: Authentication and authorization
- Scoped to Company
- Fields: Name, Price
- Relations: Many SaleItems, One Prediction
- Scoped to Company
- Fields: Date, Total
- Relations: Collection of SaleItems
- Line items for individual sales
- Fields: Quantity, Price, Total
- Relations: Product (FK), Sale (FK)
- One per Product
- Relations: Collection of PredictionSales
- Individual prediction data points
- Fields: Date, Quantity (predicted)
- Relations: Prediction (FK)
Company
↓ (1:N)
├─ User
├─ Product ──→ Prediction ──→ PredictionSale (1:N)
│ ↓ (1:N)
└─ Sale ──→ SaleItem (1:N)
↓ (N:1)
Product
mssql (database)
↓
chronos-app-api (REST API)
↓
chronos-ui (frontend)
chronos-data-science (ML service, called by API)
chronos-app-integration (worker, writes to API)
After code changes, rebuild specific services:
# Rebuild all services
docker compose build
# Rebuild specific service
docker compose build chronos-app-api
# Rebuild and restart
docker compose up --build# All services
docker compose logs -f
# Specific service
docker compose logs -f chronos-app-apiMigrations are automatically applied on API startup. To create new migrations:
# Enter API container
docker compose exec chronos-app-api bash
# Add migration (requires .NET SDK)
dotnet ef migrations add MigrationName --project Chronos.ApiSQL Server won't start:
- Ensure password meets complexity requirements
- Check Docker has sufficient memory (4GB minimum)
- Verify port 14333 is not in use
API can't connect to database:
- Wait for SQL Server health check to pass
- Check database password matches in connection string
- Review API logs:
docker compose logs chronos-app-api
Frontend shows connection errors:
- Verify API is running on port 5001
- Check CORS configuration in API
- Clear browser cache and cookies
[Specify your license here]
For issues, questions, or contributions, please [contact information or repository issues link].