How kamrulhasan12345/nodecommerce-backend works
1. What this repo is
This is a Python 3.14 monorepo for a Bangladesh demand-intelligence platform. The main production loop is: transactions and inventory data go into PostgreSQL, feature jobs build typed features, LightGBM produces forecasts, agent signals adjust them, and the API serves dashboard/forecast reads.
2. Shared platform boundary
packages/core/ is the common foundation: config, logging, DB clients, Redis client, Neo4j client, and the canonical layer-oriented models. Most other packages depend on it rather than talking to infrastructure directly.
3. Primary storage and infrastructure
The runtime infrastructure is PostgreSQL 16, Redis 7, and Neo4j Community, with Prometheus/Grafana for observability. Docker Compose and infra/ define local service setup, and Alembic migrations under packages/migrations/ own schema evolution.
4. Raw-data and seeding path
The raw layer includes nodes, products, transactions, customers, and inventory state. data_generation/ plus scripts/ produce synthetic/demo datasets and coordinate metadata so the system can be seeded without the full ML pipeline.
5. Feature engineering subsystem
packages/feature_store/ is the main feature computation layer. It builds calendar, lag, node/product, event, graph, cold-start, and agent-aggregate features, then writes them to the feature store tables that downstream inference consumes.
6. Forecasting subsystem
packages/forecasting/ owns model training, inference, imputation, trust update logic, and persistence of model artifacts and predictions. The README indicates LightGBM is the main model, and daily inference also emits SHAP-style explanation components for the dashboard.
7. Agentic signal subsystem
packages/agents/ splits into local and central agents. Local agents ingest or scrape signals, apply guardrails, and write back local signal data; central agents preprocess, detect spikes, and write centralized findings. This layer is partially migrated to the v3 schema and still has some transitional code.
8. Knowledge-graph subsystem
packages/knowledge_graph/ wraps Neo4j-backed graph data. It has separate EKG and SKG writer/query modules, embedding support, and materialization logic. feature_store can consume graph-derived signals, and some pipeline jobs are intended to refresh graph features hourly.
9. API and dashboard serving boundary
packages/api/ is the HTTP serving layer. It exposes dashboard, forecast, inventory, signal, health, ACO, and HITL routers, and serves the static Leaflet-based investor dashboard from packages/api/src/api/static/. The read path is mostly PostgreSQL-backed; no model training happens here.
10. Pipeline orchestration
packages/pipeline/ contains the scheduled job entry points and Airflow DAG definitions. The active path is job-centric: daily feature generation, daily inference, weekly training, weekly recsys, hourly graph-RAG refresh, and monitoring. The README notes some Airflow DAG files are stale or partially incompatible with v3 schemas.
11. Recommendations and supporting analytics
packages/recsys/ builds product affinity scores and cold-start support used by the forecasting/feature layers. packages/monitoring/ computes drift, data quality, health checks, and metrics that feed Prometheus/Grafana dashboards and alerting rules.
12. Legacy and not-currently-primary subsystems
packages/aco/ and packages/router/ represent the older fulfillment-routing direction. The repository treats them as v2/legacy and not part of the current v3 production flow, while the README’s “hierarchical fulfillment routing” is described as planned future work rather than an active subsystem.
Main entry points: daily_inference.py Jobs · core/__init__.py Core · main.py Feature store · knowledge_graph/__init__.py Knowledge graph
Components 17
Shared platform
Common foundation and cross-cutting infrastructure clients
- Core · Config, logging, DB/Redis/Neo4j clients, and canonical models
packages/core/src/core/__init__.py
Data and storage
Raw data seeding and schema evolution
- Migrations · Alembic-managed PostgreSQL schema changes
packages/migrations/alembic/env.py - Seed data · Generators and demo dataset creation for raw-layer bootstrapping
data_generation/README.md
Feature and forecasting
Feature computation, forecasting, and recommendation models
- Feature store · Builds typed calendar, lag, node, product, event, graph, cold-start, and agent features
packages/feature_store/src/feature_store/main.py - Forecasting · Training, inference, imputation, trust updates, and prediction persistence
packages/forecasting/src/forecasting/pipeline.py - Recsys · Product affinity and cold-start support used by downstream layers
packages/recsys/src/recsys/pipeline.py
Agentic and graph
Local/central agents and Neo4j-backed knowledge graph
- Local agents · Local ingestion, guardrails, tools, graph-RAG, and writeback
packages/agents/src/agents/local/agent.py - Central agents · Scrape, preprocess, spike detection, and central finding writeback
packages/agents/src/agents/central/agent.py - Knowledge graph · EKG/SKG writers, queries, embeddings, and materialization
packages/knowledge_graph/src/knowledge_graph/__init__.py
Serving
HTTP API and dashboard reads
Orchestration
Scheduled jobs and workflow entry points
- Jobs · Daily, weekly, hourly, and monitoring job entry points
packages/pipeline/src/pipeline/jobs/daily_inference.py - Airflow DAGs · Workflow scheduling layer, partly stale relative to v3 schemas
packages/pipeline/src/pipeline/airflow/dag_daily_inference.py
Monitoring
Health, drift, metrics, and alerting
- Monitoring · Data quality, drift, health checks, metrics, and alerting inputs
packages/monitoring/src/monitoring/__init__.py
Connections 25
- Seed data → Migrations: seed schema · Synthetic data and metadata align with evolved tables
- Migrations → Core: models · Schema and table shape follow canonical shared models
- Local agents → Knowledge graph: write signals · Local agents can persist graph-derived or graph-adjacent signals
- Central agents → Knowledge graph: write findings · Central agents materialize findings into Neo4j-backed graph data
- Knowledge graph → Feature store: graph features · Graph materialization feeds graph-derived feature computation
- Core → Feature store: db clients · Feature jobs use shared clients and models
- Core → Forecasting: db clients · Forecasting reads/writes through shared infrastructure clients
- Core → Local agents: clients · Local agent runtime uses common config and connectors
- Core → Central agents: clients · Central agent runtime uses common config and connectors
- Core → Knowledge graph: neo4j client · Graph layer depends on the shared Neo4j connector
- Recsys → Feature store: support features · Affinity and cold-start outputs feed feature computation
- Feature store → Forecasting: typed features · Downstream inference consumes stored engineered features
- Feature store → Monitoring: quality signals · Feature jobs expose drift and data-quality inputs
- Forecasting → API: predictions · API serves forecast reads from persisted predictions
- API → Dashboard: routes · Dashboard endpoints and static UI live behind the API boundary
- API → Forecasts: routes · Forecast read endpoints are mounted in the API
- Jobs → Feature store: daily features · Scheduled jobs invoke feature generation
- Jobs → Forecasting: daily inference · Scheduled jobs run inference and persist outputs
- Jobs → Central agents: central agent job · Scheduled jobs refresh centralized agent signals
- Jobs → Knowledge graph: graph refresh · Hourly jobs refresh graph-RAG/materialized graph data
- Jobs → Recsys: weekly recsys · Recommendation training and scoring are scheduled here
- Jobs → Monitoring: monitor jobs · Operational jobs collect health, drift, and quality signals
- Airflow DAGs → Jobs: orchestrate · Airflow definitions wrap the job entry points
- Monitoring → API: health data · Metrics and health checks surface through API read paths
- ACO → Router: legacy flow · Older routing components remain connected as a legacy path