App Client Base Swift / Ứng Dụng Client iOS
EN: Native iOS client application for GoodGo platform, built with Swift and SwiftUI following MVVM architecture. VI: Ứng dụng iOS native cho nền tảng GoodGo, xây dựng bằng Swift và SwiftUI theo kiến trúc MVVM.
📱 Features / Tính Năng
| Feature / Tính năng | Description / Mô tả |
|---|---|
| 🔐 Authentication | Login, Register, Forgot Password với form validation |
| 🏠 Home Dashboard | Greeting động, Featured items, Activity feed |
| 🔍 Explore | Khám phá địa điểm và dịch vụ |
| 👤 Profile | Quản lý thông tin cá nhân và cài đặt |
| 🌓 Dark Mode | Hỗ trợ chế độ tối tự động |
| 🌐 i18n | Đa ngôn ngữ (Tiếng Việt & English) |
🛠️ Tech Stack / Công Nghệ
| Technology | Version | Purpose / Mục đích |
|---|---|---|
| Swift | 5.9+ | Primary language / Ngôn ngữ chính |
| SwiftUI | iOS 15+ | Declarative UI framework |
| Xcode | 15.0+ | IDE development |
| URLSession | Native | HTTP networking |
| Keychain | Native | Secure token storage / Lưu trữ token bảo mật |
| Combine | Native | Reactive programming |
<EFBFBD> Prerequisites / Yêu Cầu
- macOS: 14.0+ (Sonoma)
- Xcode: 15.0+
- iOS Target: 15.0+
- Apple Developer Account: Required for device deployment / Cần thiết cho deploy lên thiết bị
🚀 Quick Start / Bắt Đầu Nhanh
1. Clone và mở project
cd apps/app-client-base-swift
open AppClientBaseSwift/AppClientBaseSwift.xcodeproj
2. Chọn Simulator
- Xcode menu: Product > Destination > iPhone 15 Pro (hoặc simulator khác)
3. Build và Run
# Sử dụng shortcut
⌘R (Command + R)
# Hoặc từ terminal
xcodebuild -project AppClientBaseSwift/AppClientBaseSwift.xcodeproj \
-scheme AppClientBaseSwift \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro' \
build
4. Mock Login (để test)
Email: admin@goodgo.com
Password: 123456
📂 Project Structure / Cấu Trúc Project
AppClientBaseSwift/
├── App/
│ └── AppClientBaseSwiftApp.swift # @main entry point
│
├── Core/
│ ├── Constants/
│ │ └── Constants.swift # API, App, Storage, DesignSystem
│ └── Extensions/
│ ├── View+Extensions.swift # SwiftUI modifiers
│ └── String+Extensions.swift # Validation, formatting
│
├── Models/
│ └── User.swift # User entity + extensions
│
├── ViewModels/ # MVVM ViewModels
│ ├── AuthViewModel.swift # Login/Register/ForgotPassword
│ ├── HomeViewModel.swift # Home screen logic
│ └── ProfileViewModel.swift # Profile management
│
├── Views/
│ ├── Auth/ # Authentication screens
│ │ ├── AuthContainerView.swift # Auth navigation container
│ │ ├── LoginView.swift # Login UI
│ │ ├── RegisterView.swift # Registration UI
│ │ └── ForgotPasswordView.swift # Password reset UI
│ │
│ ├── Home/ # Home components
│ │ ├── WalletCard.swift # Wallet balance card
│ │ ├── PromoCarousel.swift # Promotions carousel
│ │ ├── ServiceGrid.swift # Services grid
│ │ └── ActivityFeed.swift # Recent activities
│ │
│ └── Screens/ # Main screens
│ ├── ContentView.swift # Root container + TabBar
│ ├── SplashView.swift # Splash animation
│ ├── WelcomeView.swift # Onboarding
│ ├── HomeView.swift # Home tab
│ ├── ExploreView.swift # Explore tab
│ └── ProfileView.swift # Profile tab
│
├── Services/
│ ├── APIService.swift # HTTP client với URLSession
│ └── AuthManager.swift # Auth state + Keychain
│
└── Resources/
├── Assets.xcassets/ # Images & Colors
├── en.lproj/ # English localization
└── vi.lproj/ # Vietnamese localization
🎨 Architecture / Kiến Trúc
MVVM Pattern
┌─────────────────────────────────────────────────────────────┐
│ VIEW (SwiftUI) │
│ HomeView, ProfileView, AuthContainerView, LoginView... │
├─────────────────────────────────────────────────────────────┤
│ @StateObject / @EnvironmentObject │
│ │ │
├────────────────────────────▼────────────────────────────────┤
│ VIEWMODEL (ObservableObject) │
│ HomeViewModel, AuthViewModel, ProfileViewModel │
│ • @Published properties for reactive UI │
│ • async/await methods for data loading │
│ • Business logic and validation │
├─────────────────────────────────────────────────────────────┤
│ Protocol-based Dependency Injection │
│ │ │
├────────────────────────────▼────────────────────────────────┤
│ SERVICES │
│ APIService (HTTP) • AuthManager (Auth State + Keychain) │
└─────────────────────────────────────────────────────────────┘
Authentication Flow
stateDiagram-v2
[*] --> SplashScreen
SplashScreen --> CheckAuth: App Launch
CheckAuth --> Authenticated: Token Valid
CheckAuth --> Unauthenticated: No Token
Unauthenticated --> Login
Login --> Authenticated: Success
Login --> Register: Sign Up
Register --> Authenticated: Success
Authenticated --> HomeScreen
HomeScreen --> Unauthenticated: Logout
Data Flow
User Action → View → ViewModel.method() → Service.request() → API
↓
@Published update
↓
View rerender
📋 Coding Conventions / Quy Ước Code
File Structure
// MARK: - Imports
import SwiftUI
// MARK: - Type Definition
/// Description in English
/// Mô tả bằng tiếng Việt
struct/class/enum TypeName {
// MARK: - Properties
// MARK: - Init
// MARK: - Public Methods
// MARK: - Private Methods
}
// MARK: - Extensions
// MARK: - Preview Provider (DEBUG only)
ViewModel Pattern
@MainActor
final class FeatureViewModel: ObservableObject {
// Published properties for UI binding
@Published var isLoading = false
@Published var errorMessage: String?
@Published var data: [Model] = []
// Dependencies via init
private let apiService: APIServiceProtocol
init(apiService: APIServiceProtocol = APIService.shared) {
self.apiService = apiService
}
// Async methods
func loadData() async {
isLoading = true
defer { isLoading = false }
do {
data = try await apiService.get(endpoint: "/data")
} catch {
errorMessage = error.localizedDescription
}
}
}
Bilingual Comments
/// Load user profile data
/// Tải dữ liệu hồ sơ người dùng
func loadProfile() async { }
⚙️ Configuration / Cấu Hình
API Configuration
// Core/Constants/Constants.swift
enum APIConfig {
static let baseURL = "https://api.goodgo.vn"
static let apiVersion = "/api/v1"
static let timeout: TimeInterval = 30.0
}
Environment Variables
| Key | Description / Mô tả | Default |
|---|---|---|
API_BASE_URL |
Backend API URL | https://api.goodgo.vn |
API_VERSION |
API version prefix | /api/v1 |
🧪 Testing / Kiểm Thử
Run Unit Tests
xcodebuild test \
-project AppClientBaseSwift/AppClientBaseSwift.xcodeproj \
-scheme AppClientBaseSwift \
-destination 'platform=iOS Simulator,name=iPhone 15 Pro'
Test Plan
Located at: AppClientBaseSwift.xctestplan
🔐 Security / Bảo Mật
| Feature | Implementation / Triển khai |
|---|---|
| Token Storage | Keychain Services (not UserDefaults) |
| Secure Requests | HTTPS only, Bearer token auth |
| Session Management | Auto token refresh, secure logout |
| Data Protection | Sensitive data encrypted at rest |
📱 Supported Devices / Thiết Bị Hỗ Trợ
- iPhone: 8 and later (iOS 15+)
- iPad: All iPads with iOS 15+
- Orientations: Portrait (primary), Landscape (supported)
🔗 Related Projects / Dự Án Liên Quan
- app-client-base-net - .NET MAUI cross-platform client
- iam-service-net - Authentication backend
- web-client - Web application
📚 Additional Documentation / Tài Liệu Bổ Sung
- ARCHITECTURE.md - Chi tiết kiến trúc và design decisions
- Swift Enterprise Skills - Swift development guidelines
📄 License
Copyright © 2026 GoodGo. All rights reserved.