Skip to content

dwbessa/MakeMyDriveFun

Repository files navigation

MakeMyDriveFun

Architecture Overview

The application follows a layered architecture pattern with clear separation of concerns:

๐Ÿ“‚ Project Structure

MakeMyDriveFun/
โ”œโ”€โ”€ Domain/                    # Business Logic Layer
โ”‚   โ”œโ”€โ”€ Entities/             # Domain models
โ”‚   โ”œโ”€โ”€ UseCases/             # Business use cases
โ”‚   โ””โ”€โ”€ Repositories/         # Repository protocols
โ”œโ”€โ”€ Data/                     # Data Layer
โ”‚   โ”œโ”€โ”€ DataSources/          # Remote/Local data sources
โ”‚   โ”œโ”€โ”€ Models/               # Data Transfer Objects (DTOs)
โ”‚   โ””โ”€โ”€ Repositories/         # Repository implementations
โ”œโ”€โ”€ Infrastructure/           # External Dependencies
โ”‚   โ”œโ”€โ”€ Network/              # Network services
โ”‚   โ””โ”€โ”€ Location/             # Location services
โ”œโ”€โ”€ Presentation/             # UI Layer
โ”‚   โ”œโ”€โ”€ RouteSearch/          # Route search feature
โ”‚   โ”œโ”€โ”€ FunLocations/         # Fun locations feature
โ”‚   โ””โ”€โ”€ Common/               # Shared UI components
โ””โ”€โ”€ DI/                       # Dependency Injection

๐Ÿ—๏ธ Clean Architecture Layers

1. Domain Layer

  • Entities: Core business objects (Route, RoutePoint, RouteRequest)
  • Use Cases: Business logic implementations (GetRouteUseCase)
  • Repository Protocols: Abstractions for data access

2. Data Layer

  • DTOs: Data transfer objects for API communication
  • Data Sources: Remote API data sources
  • Repository Implementations: Concrete repository implementations

3. Infrastructure Layer

  • Network Service: HTTP client for API communication
  • Location Service: Core Location wrapper

4. Presentation Layer

  • View Controllers: UIKit view controllers
  • View Models: MVVM pattern implementation
  • UI Components: Custom UI elements

5. Dependency Injection

  • DependencyContainer: Service locator pattern for dependency management

๐Ÿงน Clean Code Principles Applied

1. Single Responsibility Principle (SRP)

  • Each class has a single, well-defined purpose
  • View controllers only handle UI logic
  • Use cases contain only business logic
  • Data sources only handle data fetching

2. Open/Closed Principle (OCP)

  • Classes are open for extension but closed for modification
  • Protocol-based architecture allows easy testing and mocking

3. Dependency Inversion Principle (DIP)

  • High-level modules don't depend on low-level modules
  • Both depend on abstractions (protocols)
  • Dependencies are injected, not created

4. Interface Segregation Principle (ISP)

  • Protocols are focused and specific
  • Clients depend only on interfaces they use

5. Liskov Substitution Principle (LSP)

  • Implementations can be substituted without breaking functionality
  • Mock implementations for testing

๐Ÿ”ง Key Improvements

Before Refactoring

  • Monolithic view controllers with mixed responsibilities
  • Direct API calls from UI components
  • Tight coupling between layers
  • Difficult to test and maintain

After Refactoring

  • โœ… Separation of Concerns: Each layer has a clear responsibility
  • โœ… Testability: Protocol-based design enables easy unit testing
  • โœ… Maintainability: Code is organized and follows consistent patterns
  • โœ… Scalability: New features can be added without affecting existing code
  • โœ… Error Handling: Comprehensive error handling throughout the application
  • โœ… Async/Await: Modern Swift concurrency patterns
  • โœ… Constants: Centralized configuration and constants

๐Ÿ“ฑ Features

Route Search

  • Input start and end addresses
  • Select departure and return dates
  • Specify maximum route deviation
  • Real-time location services integration

Fun Locations

  • Display points of interest along the route
  • Categorized location types
  • Detailed location information

๐Ÿƒโ€โ™‚๏ธ How to Run

  1. Open MakeMyDriveFun.xcodeproj in Xcode
  2. Select your development team in Signing & Capabilities (if needed)
  3. Choose a simulator or device
  4. Build and run the project

โœ… Build Status: The project compiles successfully with no errors!

๐Ÿงช Testing

The new architecture makes testing straightforward:

// Example unit test for GetRouteUseCase
class GetRouteUseCaseTests: XCTestCase {
    func testExecuteWithValidRequest() async throws {
        // Given
        let mockRepository = MockRouteRepository()
        let useCase = GetRouteUseCase(repository: mockRepository)
        let request = RouteRequest(...)
        
        // When
        let result = try await useCase.execute(request: request)
        
        // Then
        XCTAssertEqual(result.points.count, 5)
    }
}

๐Ÿ”„ Data Flow

  1. User Interaction โ†’ View Controller
  2. View Controller โ†’ View Model
  3. View Model โ†’ Use Case
  4. Use Case โ†’ Repository (Protocol)
  5. Repository โ†’ Data Source
  6. Data Source โ†’ Network Service
  7. Network Service โ†’ API
  8. Response flows back through the same layers

๐Ÿ› ๏ธ Technologies Used

  • Swift 5.0+
  • UIKit - UI framework
  • MapKit - Map integration
  • Core Location - Location services
  • URLSession - Network requests
  • Async/Await - Concurrency
  • MVVM - Presentation pattern

๐ŸŽฏ Benefits

  1. Maintainability: Easy to modify and extend
  2. Testability: Each layer can be tested independently
  3. Readability: Clear code structure and naming conventions
  4. Scalability: Easy to add new features
  5. Reusability: Components can be reused across features
  6. Flexibility: Easy to swap implementations

๐Ÿ”ฎ Future Enhancements

  • Add Core Data for local persistence
  • Implement Combine for reactive programming
  • Add unit and integration tests
  • Implement caching strategies
  • Add analytics and logging
  • Implement offline support

๐Ÿ› Recent Bug Fixes

Fixed Issues:

  • โœ… Loading Indicator: Added proper loading state with button text changes and user interaction blocking
  • โœ… API Response Format: Fixed decoding error by updating DTOs to match API response structure
  • โœ… Input Validation: Added validation to prevent API calls with empty required fields
  • โœ… Debug Logging: Added network request/response logging for easier debugging
  • โœ… Location Permissions: Fixed Info.plist location permission keys
  • โœ… Keyboard Handling: Added proper keyboard dismissal and text field navigation

API Integration:

The app now correctly handles the API response format from https://makedrivefunbr.vercel.app/get-route which returns data wrapped in an ai_response object.

๐Ÿงช Testing the API

You can test the API directly using:

curl -X POST \
  https://makedrivefunbr.vercel.app/get-route \
  -H 'Content-Type: application/json' \
  -d '{
    "start_address": "Praรงa da Sรฉ, Sรฃo Paulo, SP",
    "end_address": "Praia de Copacabana, Rio de Janeiro, RJ",
    "date_of_going": "2025-07-01",
    "date_of_returning": "2025-07-10",
    "max_route_desviation": "30"
  }'

This refactored architecture provides a solid foundation for building scalable iOS applications while maintaining clean, testable, and maintainable code.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages