How hi-day/multi_tower works
Purpose and entry points
Multi-Tower is a Python 3.12 event recommendation engine intended to learn user and event representations and return top-N recommendations. It exposes both online and offline-facing interface shells:
• FastAPI application: src/multi_tower/interfaces/api/main.py
• CLI application: src/multi_tower/interfaces/cli/main.py
• Standalone inference/proof-of-concept scripts: infer.py, poc_multi_tower.py
Architectural style
The repository follows Clean Architecture with dependency direction from interfaces and infrastructure toward application/domain. The domain is intended to remain framework-independent; application defines orchestration contracts; infrastructure supplies model and storage implementations; interfaces adapt requests/commands.
• Domain boundary: src/multi_tower/domain/entities, src/multi_tower/domain/repositories
• Application boundary: src/multi_tower/application/use_cases, src/multi_tower/application/ports
• Adapters: src/multi_tower/infrastructure, src/multi_tower/interfaces
Data ingestion and quality gate
Raw recommendation inputs are maintained as bronze CSV data: student profiles, majors, events, and interactions. The data module loads, validates, schemas, and constants before downstream training/inference should consume records.
• Source data: data/bronze/student_profile.csv, data/bronze/event_master.csv, data/bronze/interaction.csv
• Data pipeline components: src/multi_tower/data/loader.py, src/multi_tower/data/validator.py, src/multi_tower/data/schemas.py
• Synthetic-data path: scripts/generate_dummy_data.py, src/multi_tower/data/generator.py
Domain and application orchestration
Core business concepts are Users, Events, and Interactions, represented through entities/value objects and abstract repository contracts. Application use cases coordinate these concepts through DTOs and ports rather than directly coupling API or model code to storage.
• Domain model locations: src/multi_tower/domain/entities, src/multi_tower/domain/value_objects
• Repository abstractions: src/multi_tower/domain/repositories
• Use-case and boundary definitions: src/multi_tower/application/use_cases, src/multi_tower/application/dtos, src/multi_tower/application/ports
Recommendation/model infrastructure
The intended model is a PyTorch multi-tower network: separate learned representations for users and events are jointly used for relevance scoring/ranking. Infrastructure owns concrete ML and persistence concerns and should implement application-defined ports, keeping model lifecycle out of interfaces.
• Model boundary: src/multi_tower/infrastructure/model
• Persistence boundary: src/multi_tower/infrastructure/persistence
• Prototype model implementation: poc_multi_tower.py
• Inference invocation: infer.py
Serving and execution flow
For online serving, requests enter FastAPI routes, are validated by API schemas, dispatched to application use cases, then resolved through infrastructure implementations to retrieve data and score/rank events. The CLI provides a parallel non-HTTP entry point for offline evaluation or operations.
• API composition: src/multi_tower/interfaces/api/main.py, src/multi_tower/interfaces/api/routes
• API request/response boundary: src/multi_tower/interfaces/api/schemas
• Offline command entry: src/multi_tower/interfaces/cli/main.py
Material runtime and storage choices
The runtime is Python with PyTorch for neural recommendation and Polars-oriented data handling, especially Parquet-capable persistence at scale. Configuration is expected through environment variables and Pydantic Settings; .env.example documents the environment boundary. No deployed cloud, database, queue, or external recommendation service is represented in the repository tree.
• Environment template: .env.example
• Package/runtime declaration: pyproject.toml
• Data/persistence implementation area: src/multi_tower/infrastructure/persistence
Main entry points: use_cases Recommendation use cases · loader.py Data loader · model Multi-tower model · routes API routes
Components 18
Entry points
- FastAPI app
src/multi_tower/interfaces/api/main.py - API routes
src/multi_tower/interfaces/api/routes - API schemas
src/multi_tower/interfaces/api/schemas - CLI app
src/multi_tower/interfaces/cli/main.py - Inference script
infer.py
Data quality pipeline
- Student profiles
data/bronze/student_profile.csv - Event catalog
data/bronze/event_master.csv - Interactions
data/bronze/interaction.csv - Data loader
src/multi_tower/data/loader.py - Validation & schemas · Validates loaded recommendation records before model consumption.
src/multi_tower/data/validator.py - Synthetic data generator
src/multi_tower/data/generator.py
Clean Architecture core
- Users, events & interactions
src/multi_tower/domain/entities - Repository contracts
src/multi_tower/domain/repositories - Recommendation use cases
src/multi_tower/application/use_cases - Application ports
src/multi_tower/application/ports
Infrastructure
- Multi-tower model · Builds user and event representations for scoring and ranking.
src/multi_tower/infrastructure/model - Persistence adapters · Concrete Polars/Parquet-capable data access implementations.
src/multi_tower/infrastructure/persistence - Model prototype
poc_multi_tower.py
Connections 19
- FastAPI app → API routes: mounts
- API routes → API schemas: validates with
- API routes → Recommendation use cases: dispatches
- CLI app → Recommendation use cases: invokes
- Recommendation use cases → Users, events & interactions: coordinates
- Recommendation use cases → Repository contracts: uses
- Recommendation use cases → Application ports: depends on
- Persistence adapters → Repository contracts: implements
- Multi-tower model → Application ports: implements
- Recommendation use cases → Multi-tower model: scores and ranks via
- Recommendation use cases → Persistence adapters: retrieves through
- Student profiles → Data loader: loads
- Event catalog → Data loader: loads
- Interactions → Data loader: loads
- Data loader → Validation & schemas: records
- Validation & schemas → Multi-tower model: validated data
- Synthetic data generator → Data loader: produces inputs for
- Inference script → Multi-tower model: runs
- Model prototype → Multi-tower model: prototypes