# emeraldpathways/lilicfversusai architecture

> Architecture diagram of the GitHub repository emeraldpathways/lilicfversusai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/emeraldpathways/lilicfversusai
- Repository: https://github.com/emeraldpathways/lilicfversusai

## Overview

#### Purpose and entry points
This is an academic demo that compares a collaborative-filtering (CF) recommender with an agentic/LLM-enhanced recommendation workflow using the H&M Personalized Fashion Recommendations CSV dataset. The runtime entry points are FastAPI in `backend/app/main.py` and a Next.js App Router dashboard rooted at `frontend/app/page.tsx`. The experiment is initiated through `POST /experiment/run`; the frontend calls backend APIs through `frontend/lib/api.ts`.

#### API and experiment orchestration
FastAPI routes divide the system into experiment lifecycle, users, recommendations, and metrics boundaries:
- `backend/app/api/experiment.py` starts runs and exposes setup state.
- `backend/app/api/users.py` serves inferred user intent and accepts feedback.
- `backend/app/api/recommendations.py` exposes per-user CF-versus-agentic comparisons.
- `backend/app/api/metrics.py` exposes aggregate evaluation outputs.

`backend/app/main.py` assembles the application, including frontend-origin integration configured through `backend/app/config.py`.

#### Data ingestion and local artifact boundary
The pipeline consumes uncommitted H&M source files from `backend/app/data/raw/`: transactions, articles, and customers. `backend/app/services/data_service.py` is the data-processing boundary, using pandas to load, transform, and prepare model-ready data. Derived experiment state/artifacts are retained locally under `backend/app/data/processed/`, making the system file-backed rather than database-backed.

#### Recommendation engines
The baseline recommendation path is implemented by `backend/app/services/cf_service.py`, which produces collaborative-filtering recommendations from prepared interaction data. The agentic path is implemented by `backend/app/services/agentic_service.py`; it interprets user intent and produces augmented recommendations or explanations. These engines are coordinated as part of the same run rather than exposed as independent infrastructure services.

#### Experiment state and evaluation
`backend/app/services/experiment_service.py` owns lifecycle orchestration: prepare data, execute both recommendation approaches, persist/refresh available experiment results, and provide state used by API handlers. `backend/app/models/experiment_state.py` represents experiment-level state, while request/response contracts reside in `backend/app/models/schemas.py`. `backend/app/services/evaluation_service.py` computes comparative metrics consumed by `/metrics` and the dashboard.

#### LLM and external-service boundary
The agentic service integrates with the OpenAI API, using `OPENAI_API_KEY` and optionally `OPENAI_MODEL` (default `gpt-4.1-mini`). This external dependency is specifically used for user-intent interpretation and recommendation explanations; CF and evaluation operate locally. The backend also accepts `FRONTEND_ORIGIN` to control browser access from the separately deployed Next.js frontend.

#### Frontend research workflow
The frontend is a multi-page dashboard rather than a generic consumer app. Its pages map to the experiment narrative:
- setup and processing: `frontend/app/research-setup/page.tsx`, `frontend/app/data-processing/page.tsx`
- intent inspection: `frontend/app/user-intention/page.tsx`
- side-by-side recommendation comparison: `frontend/app/comparison/page.tsx`
- aggregate evaluation: `frontend/app/evaluation/page.tsx`

Reusable visualization and exploration components, including `frontend/components/ComparisonExplorer.tsx`, `frontend/components/UserIntentExplorer.tsx`, and `frontend/components/ModelComparisonTable.tsx`, render API-derived experiment outputs.

Main entry points: [`backend/app/services/experiment_service.py`](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/experiment_service.py) (Experiment orchestrator), [`backend/app/main.py`](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/main.py) (FastAPI application), [`backend/app/data/processed/.gitkeep`](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/data/processed/.gitkeep) (Processed artifacts), [`frontend/app/research-setup/page.tsx`](https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/app/research-setup/page.tsx) (Research workflow pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Research dashboard"]
  node_dashboard["Dashboard entry<br/>Next.js page<br/>[page.tsx]"]
  node_research_pages["Research workflow pages<br/>Next.js pages<br/>[page.tsx]"]
  node_explorers["Exploration components<br/>React components"]
  node_comparison_table["Model comparison table<br/>React component"]
  node_api_client["Backend API client<br/>frontend API layer<br/>[api.ts]"]
end

subgraph group_backend["Experiment backend"]
  node_fastapi_app{{"FastAPI application<br/>API entry point<br/>[main.py]"}}
  node_api_config["Runtime configuration<br/>backend config<br/>[config.py]"]
  node_experiment_api["Experiment lifecycle API<br/>FastAPI routes<br/>[experiment.py]"]
  node_users_api["Users API<br/>FastAPI routes<br/>[users.py]"]
  node_recommendations_api["Recommendations API<br/>FastAPI routes<br/>[recommendations.py]"]
  node_metrics_api["Metrics API<br/>FastAPI routes<br/>[metrics.py]"]
  node_experiment_service{{"Experiment orchestrator<br/>lifecycle service"}}
  node_data_service["Data preparation<br/>pandas service<br/>[data_service.py]"]
  node_cf_service["CF recommender<br/>recommendation engine<br/>[cf_service.py]"]
  node_agentic_service["Agentic recommender<br/>LLM-enhanced engine<br/>[agentic_service.py]"]
  node_evaluation_service["Comparative evaluation<br/>evaluation service"]
  node_experiment_state["Experiment state<br/>state model"]
end

subgraph group_data["Local data artifacts"]
  node_raw_data[("H&amp;M source CSVs<br/>raw dataset<br/>[.gitkeep]")]
  node_processed_data[("Processed artifacts<br/>local artifact store<br/>[.gitkeep]")]
end

node_openai{{"OpenAI API<br/>external LLM"}}

node_dashboard -->|"navigates research flow"| node_research_pages
node_research_pages -->|"uses"| node_explorers
node_research_pages -->|"uses"| node_comparison_table
node_dashboard -->|"requests experiment data"| node_api_client
node_api_client -->|"HTTP API calls"| node_fastapi_app
node_api_config -.->|"configures origin access"| node_fastapi_app
node_fastapi_app -->|"routes"| node_experiment_api
node_fastapi_app -->|"routes"| node_users_api
node_fastapi_app -->|"routes"| node_recommendations_api
node_fastapi_app -->|"routes"| node_metrics_api
node_experiment_api -->|"starts and reads runs"| node_experiment_service
node_users_api -->|"reads intent and feedback state"| node_experiment_service
node_recommendations_api -->|"reads comparisons"| node_experiment_service
node_metrics_api -->|"reads metrics"| node_evaluation_service
node_experiment_service -->|"prepares data"| node_data_service
node_raw_data -->|"loads CSVs"| node_data_service
node_data_service -->|"writes prepared artifacts"| node_processed_data
node_experiment_service -->|"executes baseline"| node_cf_service
node_experiment_service -->|"executes agentic path"| node_agentic_service
node_experiment_service -->|"evaluates approaches"| node_evaluation_service
node_experiment_service -->|"maintains lifecycle state"| node_experiment_state
node_experiment_service -->|"persists results"| node_processed_data
node_processed_data -->|"supplies interactions"| node_cf_service
node_agentic_service -->|"intent and explanations"| node_openai
node_evaluation_service -->|"stores metrics"| node_processed_data

click node_dashboard "https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/app/page.tsx"
click node_research_pages "https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/app/research-setup/page.tsx"
click node_explorers "https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/components/ComparisonExplorer.tsx"
click node_comparison_table "https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/components/ModelComparisonTable.tsx"
click node_api_client "https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/lib/api.ts"
click node_fastapi_app "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/main.py"
click node_api_config "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/config.py"
click node_experiment_api "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/api/experiment.py"
click node_users_api "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/api/users.py"
click node_recommendations_api "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/api/recommendations.py"
click node_metrics_api "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/api/metrics.py"
click node_experiment_service "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/experiment_service.py"
click node_data_service "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/data_service.py"
click node_cf_service "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/cf_service.py"
click node_agentic_service "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/agentic_service.py"
click node_evaluation_service "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/evaluation_service.py"
click node_experiment_state "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/models/experiment_state.py"
click node_raw_data "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/data/raw/.gitkeep"
click node_processed_data "https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/data/processed/.gitkeep"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dashboard,node_research_pages,node_explorers,node_comparison_table,node_api_client toneBlue
class node_fastapi_app,node_api_config,node_experiment_api,node_users_api,node_recommendations_api,node_metrics_api,node_experiment_service,node_data_service,node_cf_service,node_agentic_service,node_evaluation_service,node_experiment_state toneAmber
class node_raw_data,node_processed_data toneMint
class node_openai toneNeutral
```

## Components

### Research dashboard

Next.js App Router workflow for running and inspecting the experiment.

- [Dashboard entry](https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/app/page.tsx): Next.js page · `frontend/app/page.tsx`
- [Research workflow pages](https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/app/research-setup/page.tsx): Next.js pages · Setup, processing, intent, comparison, and evaluation views. · `frontend/app/research-setup/page.tsx`
- [Exploration components](https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/components/ComparisonExplorer.tsx): React components · Renders intent and side-by-side recommendation exploration. · `frontend/components/ComparisonExplorer.tsx`
- [Model comparison table](https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/components/ModelComparisonTable.tsx): React component · `frontend/components/ModelComparisonTable.tsx`
- [Backend API client](https://github.com/emeraldpathways/lilicfversusai/blob/main/frontend/lib/api.ts): frontend API layer · `frontend/lib/api.ts`

### Experiment backend

FastAPI orchestration, recommendation engines, and evaluation.

- [FastAPI application](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/main.py): API entry point · Assembles routes and frontend-origin access control. · `backend/app/main.py`
- [Runtime configuration](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/config.py): backend config · Controls frontend origin and OpenAI settings. · `backend/app/config.py`
- [Experiment lifecycle API](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/api/experiment.py): FastAPI routes · Starts runs and exposes setup state. · `backend/app/api/experiment.py`
- [Users API](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/api/users.py): FastAPI routes · Serves inferred intent and accepts feedback. · `backend/app/api/users.py`
- [Recommendations API](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/api/recommendations.py): FastAPI routes · Returns per-user CF versus agentic comparisons. · `backend/app/api/recommendations.py`
- [Metrics API](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/api/metrics.py): FastAPI routes · Exposes aggregate comparative evaluation. · `backend/app/api/metrics.py`
- [Experiment orchestrator](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/experiment_service.py): lifecycle service · Prepares data, runs both approaches, and refreshes results. · `backend/app/services/experiment_service.py`
- [Data preparation](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/data_service.py): pandas service · Loads and transforms H&M data into model-ready interactions. · `backend/app/services/data_service.py`
- [CF recommender](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/cf_service.py): recommendation engine · Produces baseline recommendations from prepared interactions. · `backend/app/services/cf_service.py`
- [Agentic recommender](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/agentic_service.py): LLM-enhanced engine · Interprets intent and augments recommendations with explanations. · `backend/app/services/agentic_service.py`
- [Comparative evaluation](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/services/evaluation_service.py): evaluation service · Computes metrics for the two recommendation approaches. · `backend/app/services/evaluation_service.py`
- [Experiment state](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/models/experiment_state.py): state model · `backend/app/models/experiment_state.py`

### Local data artifacts

CSV inputs and file-backed derived experiment state.

- [H&M source CSVs](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/data/raw/.gitkeep): raw dataset · Transactions, articles, and customers supplied outside version control. · `backend/app/data/raw/.gitkeep`
- [Processed artifacts](https://github.com/emeraldpathways/lilicfversusai/blob/main/backend/app/data/processed/.gitkeep): local artifact store · File-backed prepared data and experiment outputs. · `backend/app/data/processed/.gitkeep`

### Other components

- **OpenAI API**: external LLM · Used only for intent interpretation and recommendation explanations.

## Connections

- Dashboard entry → Research workflow pages: navigates research flow
- Research workflow pages → Exploration components: uses
- Research workflow pages → Model comparison table: uses
- Dashboard entry → Backend API client: requests experiment data
- Backend API client → FastAPI application: HTTP API calls
- Runtime configuration → FastAPI application: configures origin access
- FastAPI application → Experiment lifecycle API: routes
- FastAPI application → Users API: routes
- FastAPI application → Recommendations API: routes
- FastAPI application → Metrics API: routes
- Experiment lifecycle API → Experiment orchestrator: starts and reads runs
- Users API → Experiment orchestrator: reads intent and feedback state
- Recommendations API → Experiment orchestrator: reads comparisons
- Metrics API → Comparative evaluation: reads metrics
- Experiment orchestrator → Data preparation: prepares data
- H&M source CSVs → Data preparation: loads CSVs
- Data preparation → Processed artifacts: writes prepared artifacts
- Experiment orchestrator → CF recommender: executes baseline
- Experiment orchestrator → Agentic recommender: executes agentic path
- Experiment orchestrator → Comparative evaluation: evaluates approaches
- Experiment orchestrator → Experiment state: maintains lifecycle state
- Experiment orchestrator → Processed artifacts: persists results
- Processed artifacts → CF recommender: supplies interactions
- Agentic recommender → OpenAI API: intent and explanations
- Comparative evaluation → Processed artifacts: stores metrics
