# Platform Web Migration - Phase 1 Checkpoint

## Status: Phase 1 (Core Infrastructure) - PARTIAL COMPLETE

**Date**: March 1, 2026  
**Time Investment**: ~20 minutes  
**Approach**: Incremental, safety-first migration

---

## ✅ What Was Completed

### 1. Core Infrastructure Modules Created

All core modules have been created in `apps/platform_web/lib/platform_web/`:

- ✅ **`endpoint.ex`** - Phoenix endpoint with proper configuration
  - Updated module name: `DaProductAppWeb.Endpoint` → `PlatformWeb.Endpoint`
  - Updated otp_app: `:da_product_app` → `:platform_web`
  - Updated session key and static paths
  - Updated router reference to `PlatformWeb.Router`
  - Updated CheckRepoStatus to use `:platform_core`

- ✅ **`platform_web.ex`** - Main module with use macros
  - Complete rewrite with all helper functions
  - `router/0`, `controller/0`, `live_view/0`, `live_component/0`, `html/0`, `view/0`
  - Updated all module references to `PlatformWeb.*`
  - Verified routes now point to `PlatformWeb.Endpoint` and `PlatformWeb.Router`

- ✅ **`gettext.ex`** - Internationalization module
  - Updated otp_app: `:da_product_app` → `:platform_web`
  - Module name: `DaProductAppWeb.Gettext` → `PlatformWeb.Gettext`

- ✅ **`telemetry.ex`** - Telemetry metrics and supervision
  - Updated database metrics to `platform_core.repo.*`
  - Module name: `DaProductAppWeb.Telemetry` → `PlatformWeb.Telemetry`

### 2. Directory Structure

Created proper directory structure:
```
apps/platform_web/lib/platform_web/
├── endpoint.ex ✅
├── gettext.ex ✅
├── telemetry.ex ✅
├── controllers/ (empty, ready for migration)
├── live/ (empty, ready for migration)
├── components/ (empty, ready for migration)
└── templates/ (empty, ready for migration)
```

---

## ⏸️ What Remains (Estimated: 3-5 hours)

### Phase 2: Dependencies & Configuration (30 minutes)
- [ ] Update `apps/platform_web/mix.exs` with Phoenix dependencies
  - phoenix, phoenix_html, phoenix_live_view
  - phoenix_live_reload, phoenix_live_dashboard
  - esbuild, tailwind, heroicons
  - gettext, telemetry, jason
  - floki, swoosh, finch
  - petal_components, saas_kit, cors_plug
  - Add umbrella dependencies: platform_core, tms_core, settlement_core, risk_core
  
- [ ] Update `apps/platform_web/lib/platform_web/application.ex`
  - Add endpoint to supervision tree
  - Add telemetry
  - Configure for web serving

- [ ] Update configurations:
  - `config/config.exs` - Add PlatformWeb.Endpoint config
  - `config/dev.exs` - Development port and watchers
  - `config/test.exs` - Test endpoint config
  - `config/runtime.exs` - Production endpoint config

### Phase 3: Router & Core Web Modules (30 minutes)
- [ ] Move `router.ex` → Update all route module references
- [ ] Move `user_auth.ex` - Session and authentication plugs
- [ ] Move `fallback.ex` - Error handling
- [ ] Move `emails.ex` - Email module

### Phase 4: Components & Templates (45 minutes)
- [ ] Move `components/` directory (~15 files)
  - core_components.ex
  - layouts.ex
  - sidebar_component.ex
  - And all other components
- [ ] Move `templates/` directory
- [ ] Update all component module references

### Phase 5: Controllers (1 hour)
- [ ] Move `controllers/api/` - API controllers
- [ ] Move `controllers/` - Web controllers
- [ ] Update module names from `DaProductAppWeb.*Controller` → `PlatformWeb.*Controller`
- [ ] Update context calls:
  - `DaProductApp.TerminalManagement.*` → `TmsCore.TerminalManagement.*`
  - `DaProductApp.Settlements.*` → `SettlementCore.*`
  - `DaProductApp.RiskManagement.*` → `RiskCore.*`

### Phase 6: LiveViews (2-3 hours) ⚠️ **LARGEST TASK**
- [ ] Move `live/` directory (~60 files)
- [ ] Update module names for each LiveView
- [ ] Update context calls in all LiveViews
- [ ] Update component references
- [ ] Test each major LiveView group:
  - Dashboard LiveViews
  - Terminal LiveViews (terminal_live/, terminal_group_live/)
  - Settlement LiveViews (settlement_live/, alipay_plus_live/)
  - Risk LiveViews
  - User management LiveViews
  - Parameter management LiveViews
  - OTA/Package management LiveViews

### Phase 7: Assets (30 minutes)
- [ ] Move `priv/static/` to `apps/platform_web/priv/static/`
- [ ] Move assets configuration (if `apps/da_product_app/assets/` exists)
- [ ] Update esbuild configuration in config.exs
- [ ] Update tailwind configuration in config.exs
- [ ] Run `mix assets.setup`
- [ ] Run `mix assets.build`
- [ ] Verify assets compile and serve correctly

### Phase 8: Testing & Validation (1 hour)
- [ ] Run `mix deps.get`
- [ ] Run `mix compile` - Fix all compilation errors
- [ ] Run `mix test` - Fix failing tests
- [ ] Start server: `mix phx.server`
- [ ] Manual UI testing:
  - [ ] Home page loads
  - [ ] User login works
  - [ ] Dashboard displays
  - [ ] Terminal management pages work
  - [ ] Settlement pages work
  - [ ] Risk management pages work
  - [ ] LiveView interactions work (forms, modals, real-time updates)

### Phase 9: Cleanup (15 minutes)
- [ ] Remove old files from `lib/da_product_app_web/` (after verification)
- [ ] Update any documentation references
- [ ] Final smoke test

---

## 📋 Key Files Created

1. `apps/platform_web/lib/platform_web/endpoint.ex` (1,751 bytes)
2. `apps/platform_web/lib/platform_web.ex` (3,856 bytes)
3. `apps/platform_web/lib/platform_web/gettext.ex` (823 bytes)
4. `apps/platform_web/lib/platform_web/telemetry.ex` (3,008 bytes)

**Total: 4 files, ~9.4 KB**

---

## 🔧 Configuration Changes Needed

### mix.exs Template
```elixir
defp deps do
  [
    # Umbrella dependencies
    {:platform_core, in_umbrella: true},
    {:tms_core, in_umbrella: true},
    {:settlement_core, in_umbrella: true},
    {:risk_core, in_umbrella: true},
    
    # Phoenix dependencies
    {:phoenix, "~> 1.7.18"},
    {:phoenix_html, "~> 4.1"},
    {:phoenix_live_reload, "~> 1.6", only: :dev},
    {:phoenix_live_view, "~> 1.1.8"},
    {:phoenix_live_dashboard, "~> 0.8.3"},
    {:floki, ">= 0.30.0", only: :test},
    
    # Assets
    {:esbuild, "~> 0.10", runtime: Mix.env() == :dev},
    {:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
    {:heroicons, github: "tailwindlabs/heroicons", tag: "v2.1.1", sparse: "optimized", app: false, compile: false, depth: 1},
    
    # UI Components
    {:petal_components, "~> 2.0"},
    {:saas_kit, "~> 0.1.0"},
    
    # Web utilities
    {:gettext, "~> 0.20"},
    {:jason, "~> 1.4"},
    {:finch, "~> 0.13"},
    {:swoosh, "~> 1.5"},
    {:telemetry_metrics, "~> 1.0"},
    {:telemetry_poller, "~> 1.0"},
    {:cors_plug, "~> 3.0"},
    
    # Auth
    {:bcrypt_elixir, "~> 3.1"},
    
    # Misc
    {:cachex, "~> 4.1.1"},
    {:premailex, "~> 0.3.20"}
  ]
end
```

### config/config.exs Addition
```elixir
# Configure PlatformWeb endpoint
config :platform_web, PlatformWeb.Endpoint,
  url: [host: "localhost"],
  adapter: Bandit.PhoenixAdapter,
  render_errors: [
    formats: [html: PlatformWeb.ErrorHTML, json: PlatformWeb.ErrorJSON],
    layout: false
  ],
  pubsub_server: DaProductApp.PubSub,
  live_view: [signing_salt: "Rs4sgrNR"]

# Configure esbuild for platform_web
config :esbuild,
  version: "0.17.11",
  platform_web: [
    args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
    cd: Path.expand("../apps/platform_web/assets", __DIR__),
    env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
  ]

# Configure tailwind for platform_web
config :tailwind,
  version: "3.4.3",
  platform_web: [
    args: ~w(--config=tailwind.config.js --input=css/app.css --output=../priv/static/assets/app.css),
    cd: Path.expand("../apps/platform_web/assets", __DIR__)
  ]
```

---

## ⚠️ Important Notes

### Module Reference Pattern
When updating files, use this pattern:

**OLD:**
```elixir
defmodule DaProductAppWeb.SomeController do
  use DaProductAppWeb, :controller
  
  alias DaProductApp.TerminalManagement
  alias DaProductAppWeb.SomeLive
end
```

**NEW:**
```elixir
defmodule PlatformWeb.SomeController do
  use PlatformWeb, :controller
  
  alias TmsCore.TerminalManagement
  alias PlatformWeb.SomeLive
end
```

### Context Migration Pattern
Replace direct context calls:
- `DaProductApp.TerminalManagement` → `TmsCore.TerminalManagement`
- `DaProductApp.Settlements` → `SettlementCore`
- `DaProductApp.RiskManagement` → `RiskCore`
- `DaProductApp.Repo` → `PlatformCore.Repo`

---

## 🎯 When You Resume

### Quick Start Checklist:
1. Read this document
2. Start with Phase 2 (Dependencies & Configuration)
3. Test after each phase
4. Expect compilation errors - fix systematically
5. Use grep to find remaining `DaProductAppWeb` references

### Useful Commands:
```bash
# Find all DaProductAppWeb references
grep -r "DaProductAppWeb" apps/platform_web/lib/

# Find all DaProductApp context calls
grep -r "DaProductApp\." apps/platform_web/lib/ | grep -v "DaProductApp.Utils"

# Count files to migrate
find lib/da_product_app_web -type f | wc -l

# Test compilation
mix compile

# Test server
mix phx.server
```

---

## 📊 Progress Summary

```
Phase 1: Core Infrastructure     [████████░░] 80% (4/5 files)
Phase 2: Dependencies             [░░░░░░░░░░]  0%
Phase 3: Router & Modules         [░░░░░░░░░░]  0%
Phase 4: Components & Templates   [░░░░░░░░░░]  0%
Phase 5: Controllers              [░░░░░░░░░░]  0%
Phase 6: LiveViews                [░░░░░░░░░░]  0%
Phase 7: Assets                   [░░░░░░░░░░]  0%
Phase 8: Testing                  [░░░░░░░░░░]  0%
Phase 9: Cleanup                  [░░░░░░░░░░]  0%

Overall Progress: ~5% complete
Estimated Remaining: 3-5 hours
```

---

## 🚀 Next Session Goals

**Primary Goal**: Complete Phases 2-3 (Dependencies, Configuration, Router)  
**Stretch Goal**: Start Phase 4 (Components)  
**Timeline**: 1-1.5 hours

This will get the basic infrastructure compilable and testable before tackling the large LiveView migration.

---

## 📝 Additional Resources

- Original Plan: `/home/prem/.copilot/session-state/68dbfd1d-219c-416a-b556-155721fb56e1/web-migration-plan.md`
- Source Files: `/home/prem/mercurypay/tmsuat/lib/da_product_app_web/`
- Target Location: `/home/prem/mercurypay/tmsuat/apps/platform_web/`

---

**Migration Status**: ⏸️ PAUSED - Safe to commit current progress  
**Ready to Resume**: ✅ Yes - Clear documentation and next steps provided
