# Templ Migration Guide
Convert HTML prototypes to Go `templ` templates with HTMX for server-driven UI.
## Architecture
```
Browser Go Server
------- ---------
[Web Awesome UI] <-- HTMX --> [Templ Renderer]
| |
| hx-post="/api/sign" |
| hx-target="#result" |
+--------------------------------->+
|
[Handler Logic]
|
+<---------------------------------+
| HTML Fragment Response
|
[DOM Update via HTMX]
```
## Directory Structure
```
project/
├── views/
│ ├── welcome.templ
│ ├── login.templ
│ ├── register.templ
│ ├── authorize.templ
│ ├── accounts.templ
│ ├── nfts.templ
│ └── service.templ
├── layouts/
│ ├── base.templ
│ ├── centered.templ # Auth pages
│ └── dashboard.templ # Authenticated pages
├── components/
│ ├── stepper.templ
│ ├── auth_method_card.templ
│ ├── permission_item.templ
│ ├── token_row.templ
│ ├── nft_card.templ
│ └── session_item.templ
└── handlers/
└── routes.go
```
## Page Overview
### Auth Pages (Popup/Webview Optimized)
| Page | File | Viewport | Description |
|------|------|----------|-------------|
| Welcome | `welcome.templ` | 360-480px | 3-step onboarding stepper |
| Login | `login.templ` | 360-480px | WebAuthn sign-in with passkey/security key/QR |
| Register | `register.templ` | 360-480px | Device detection + registration wizard |
| Authorize | `authorize.templ` | 360-480px | OAuth consent for connect/sign/transaction |
### Dashboard Pages
| Page | File | Description |
|------|------|-------------|
| Accounts | `accounts.templ` | Token balances, transactions, drawers |
| NFTs | `nfts.templ` | Gallery with collections, filters, actions |
| Service | `service.templ` | Connected service detail with permissions |
---
## Component Extraction
### Shared Components
```go
// components/stepper.templ
templ ProgressDots(current int, total int)
templ OnboardingStepper(current int, steps []string)
// components/auth_method_card.templ
templ AuthMethodCard(method, icon, title, desc string, disabled bool)
// components/permission_item.templ
templ PermissionItem(icon, iconClass, title, desc string)
// components/qr_section.templ
templ QRCodeSection(value, label, fallbackText string)
```
### Page-Specific Components
#### Login
```go
templ LoginStep1(caps DeviceCapabilities)
templ QRAuthStep()
templ RecoveryStep()
templ SuccessStep(title, redirectUrl string)
```
#### Register
```go
templ DeviceDetectionStep(caps DeviceCapabilities)
templ RegistrationMethodStep(method string)
templ RegistrationSuccessStep()
templ CapabilityItem(id, label string, supported, loading bool)
templ RecoveryKeyDisplay(publicKey, recoveryKey string)
```
#### Authorize
```go
templ AppIdentityHeader(app AppInfo)
templ WalletSelector(wallets []Wallet, selected string)
templ PermissionList(permissions []Permission)
templ MessagePreview(message, signType string)
templ TransactionPreview(tx Transaction)
templ SwapPreview(from, to TokenAmount)
templ GasEstimate(network, gas, maxFee string)
```
#### Accounts
```go
templ StatsGrid(stats WalletStats)
templ TokenBalancesCard(tokens []Token)
templ TokenRow(token Token)
templ RecentTransactionsCard(txs []Transaction)
templ TransactionRow(tx Transaction)
templ ConnectedAccountsCard(accounts []Account)
templ ReceiveDrawer(token string)
templ SendDrawer(tokens []Token)
templ SwapDrawer(tokens []Token)
templ CreateAccountDialog(step int, network string)
```
#### NFTs
```go
templ NFTsStatsGrid(stats NFTStats)
templ CollectionsCard(collections []Collection)
templ CollectionCard(collection Collection)
templ NFTsGalleryCard(nfts []NFTItem, filter NFTFilter)
templ NFTFilterBar(filter NFTFilter)
templ NFTGrid(nfts []NFTItem)
templ NFTCard(nft NFTItem)
templ NFTBadge(badgeType string)
```
#### Service
```go
templ ServiceHero(info ServiceInfo, status ServiceStatus)
templ UsageStatsGrid(stats UsageStats)
templ PermissionsCard(permissions []Permission)
templ PermissionToggle(scope string, enabled bool, desc string)
templ ServiceInfoCard(oauth OAuthInfo)
templ SessionLogCard(sessions []SessionEvent)
templ SessionLogItem(event SessionEvent)
templ DataAccessCard(access DataAccess)
```
---
## State Types
### Auth Pages
```go
type DeviceCapabilities struct {
PlatformAuth bool // Face ID, Touch ID, Windows Hello
CrossPlatform bool // Security keys (YubiKey)
ConditionalUI bool // Passkey autofill support
}
type LoginState struct {
Step string
SelectedMethod string // "passkey", "security-key", "qr-code"
Username string
Error string
}
type RegisterState struct {
Step int
SelectedMethod string
Username string
DisplayName string
PublicKey string
RecoveryKey string
Error string
}
type AuthRequest struct {
Type string // "connect", "sign", "transaction"
App AppInfo
Scopes []string
Message string
Transaction *TxDetails
State string
Nonce string
}
type AppInfo struct {
Name string
Domain string
LogoURL string
Verified bool
}
```
### Dashboard Pages
```go
type WalletData struct {
Stats WalletStats
Tokens []Token
Transactions []Transaction
Accounts []Account
}
type WalletStats struct {
TotalBalance float64
Change24h float64
ChangePercent float64
AssetCount int
PendingCount int
}
type Token struct {
Symbol string
Name string
Balance float64
ValueUSD float64
IconColor string
}
type NFTsData struct {
Stats NFTStats
Collections []Collection
NFTs []NFTItem
Filter NFTFilter
}
type NFTFilter struct {
Tab string // "all", "listed", "unlisted"
Collection string
Sort string // "recent", "value-high", "value-low", "name"
View string // "grid", "list"
}
type ServiceData struct {
Info ServiceInfo
Status ServiceStatus
Stats UsageStats
Permissions []Permission
OAuth OAuthInfo
Sessions []SessionEvent
DataAccess DataAccess
}
```
---
## HTMX Patterns
### Step Navigation
```html