Skip to content

mihailsalari/PriceTracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Real-Time Price tracker (iOS coding challenge)

A lightweight SwiftUI + Combine application that simulates a real-time stock price feed using a WebSocket echo server.

The app displays 25 stock symbols, generates random prices every 2 seconds, sends them through a WebSocket connection, receives the echoed values, and updates the UI in real time.

This project focuses on clean architecture, testability, reactive streams, and maintainability, rather than UI complexity.


๐Ÿ“ฑ Screenshots

Light Mode Dark Mode

๐ŸŽฌ Demo


๐ŸŽฏ Project Goals

The goal of this implementation was to:

  • Build a clean and testable architecture
  • Use SwiftUI and Combine
  • Implement real-time updates via WebSocket
  • Demonstrate modern iOS engineering practices
  • Provide unit tests for the business logic
  • Structure the project like a production-ready codebase

๐Ÿง  How the task was approached

The implementation followed several engineering principles.

1. Separation of concerns

Responsibilities were split across layers:

  • UI
  • ViewModels
  • Networking
  • Domain models
  • Infrastructure utilities

This allows every component to be tested independently.


2. Protocolโ€‘driven architecture

Networking components rely on protocol abstractions rather than concrete implementations.

Example:

WebSocketClientProtocol
WebSocketServiceProtocol

Benefits:

  • dependency injection
  • easier testing
  • replaceable implementations

3. MVVM architecture

The project follows the Model--View--ViewModel architecture.

    View (SwiftUI)
            โ†“
    ViewModel
            โ†“
    Service Layer
            โ†“
    WebSocket Client

The ViewModel owns the application state and exposes Combine publishers to the UI.


โš™๏ธ Application flow

  1. User presses Start
  2. ViewModel opens a WebSocket connection
  3. Every 2 seconds prices are generated
  4. Prices are sent through the WebSocket
  5. The echo server returns the message
  6. The ViewModel parses the message
  7. UI updates automatically through Combine

๐Ÿ— Architecture diagram

    +----------------------+
    |      SwiftUI View    |
    |  FeedView / Details  |
    +----------+-----------+
               |
               v
    +----------------------+\
    |  PriceFeedViewModel  |
    |   (Combine Streams)  |
    +----------+-----------+
               |
               v
    +----------------------+
    |  WebSocketService    |
    |   (Business Logic)   |
    +----------+-----------+
               |
               v
    +----------------------+
    | URLSessionWebSocket  |
    |       Client         |
    +----------------------+

๐Ÿงฐ Technologies used

Technology Purpose


SwiftUI UI layer Combine Reactive data streams URLSessionWebSocketTask WebSocket networking XCTest Unit testing Localization API Internationalization


โœจ Features

Realโ€‘time updates

Stock prices are generated every 2 seconds and propagated through the WebSocket echo server.

The UI updates automatically thanks to Combine publishers.


Start / Stop feed

Users can control the feed.

Stopping the feed:

  • cancels the timer
  • disconnects the WebSocket

Connection status indicator

A simple connection indicator shows WebSocket status:

  • ๐ŸŸข Connected
  • ๐Ÿ”ด Disconnected

Stock details screen

Selecting a stock opens a details view showing:

  • symbol
  • company name
  • price
  • price direction

๐ŸŒ Localization

The project includes localization support.

Resources are located in:

Resources/Localization

Example:

en.lproj/Localizable.strings
ro.lproj/Localizable.strings

SwiftUI automatically resolves localized strings:

Text("Start")

When a raw string is required:

String(localized: "Start", bundle: #bundle)

๐Ÿ”ง Extensions

Small extensions were added to keep code clean.

Examples include:

  • localization helpers
  • SwiftUI text helpers
  • utility improvements

These reduce boilerplate and improve readability.


๐Ÿชต Logging

Instead of using print(), a centralized logger is used.

Benefits:

  • categorized logs
  • easier debugging
  • productionโ€‘ready logging

Example categories:

    networking
    websocket
    viewmodel

โ— Error handling

Typed errors are used in the networking layer.

Example:

WebSocketError

Errors propagate through Combine publishers, allowing the ViewModel to react appropriately.


๐Ÿงช Testing

Unit tests validate the main logic.

Mocks isolate dependencies so tests do not require a real WebSocket connection.


Tested components

ViewModel

  • start feed connects socket
  • stop feed disconnects socket
  • message parsing
  • stock sorting
  • error propagation

WebSocket service

  • connection state updates
  • message propagation
  • error forwarding

Stock generator

Ensures exactly 25 symbols are produced as required.


๐Ÿ“‚ Project structure

    RealTimePriceTracker
    โ”‚
    โ”œโ”€โ”€ App
    โ”‚   โ”œโ”€โ”€ RealTimePriceTrackerApp.swift
    โ”‚   โ””โ”€โ”€ AppContainer.swift
    โ”‚
    โ”œโ”€โ”€ Configuration
    โ”‚   โ””โ”€โ”€ AppConfig.swift
    โ”‚
    โ”œโ”€โ”€ Core
    โ”‚   โ”œโ”€โ”€ Errors
    โ”‚   โ”œโ”€โ”€ Logging
    โ”‚   โ””โ”€โ”€ Localization
    โ”‚
    โ”œโ”€โ”€ Networking
    โ”‚   โ”œโ”€โ”€ Protocols
    โ”‚   โ”œโ”€โ”€ Clients
    โ”‚   โ””โ”€โ”€ Services
    โ”‚
    โ”œโ”€โ”€ Stocks
    โ”‚   โ”œโ”€โ”€ Models
    โ”‚   โ”œโ”€โ”€ Generators
    โ”‚   โ”œโ”€โ”€ ViewModels
    โ”‚   โ””โ”€โ”€ Views
    โ”‚
    โ”œโ”€โ”€ Resources
    โ”‚   โ””โ”€โ”€ Localization
    โ”‚
    โ””โ”€โ”€ Tests
        โ”œโ”€โ”€ ViewModelTests
        โ”œโ”€โ”€ ServiceTests
        โ””โ”€โ”€ UtilityTests
------------------------------------------------------------------------

๐Ÿงฉ Why this architecture

The architecture prioritizes:

  • testability
  • modular design
  • clear separation of concerns
  Decision       Reason
  -------------- ---------------------------------------
  MVVM           Clear separation between UI and logic
  Protocols      Enables dependency injection
  Combine        Reactive UI updates
  DI Container   Clean dependency management

------------------------------------------------------------------------

๐Ÿš€ Running the project

  1. Open in Xcode
  2. Select an iOS simulator iOS 26+ version
  3. Run the app
  4. Press Start to begin the feed
  5. Click on any stock item to open the detail screen

๐Ÿ”ฎ Possible improvements

Future enhancements could include:

  • animated price changes
  • UI snapshot testing
  • WebSocket reconnection strategy
  • performance optimization for large lists
  • accessibility improvements

๐Ÿ“Œ Summary

This project demonstrates how to build a clean, reactive iOS application using modern Apple frameworks.

Key highlights:

  • SwiftUI UI layer
  • Combine reactive streams
  • WebSocket networking
  • Protocolโ€‘driven architecture
  • Unit tested business logic
  • Localization support

The result is a small but productionโ€‘style codebase designed to showcase engineering best practices.

About

Real-time stock price tracker built with SwiftUI, Combine, and WebSockets using MVVM architecture.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages