# jonesstoen/fiskeklar architecture

> Architecture diagram of the GitHub repository jonesstoen/fiskeklar, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jonesstoen/fiskeklar
- Repository: https://github.com/jonesstoen/fiskeklar

## Overview

##### Project Type and Purpose
- This is a full-stack mobile application (Android) named **FiskeKlar**, built in Kotlin with Jetpack Compose.
- Its goal is to display real-time maritime data (vessel AIS, weather alerts, currents, wind, waves) on an interactive map, let users log catches and favorites, and provide SOS/emergency features.

##### High-Level Architectural Patterns
- **MVVM (Model-View-ViewModel)** throughout the app:
- **Presentation**: Jetpack Compose UI + Navigation
- **ViewModel**: State + LiveData/StateFlow, injected via KSP (Room, Hilt optional)
- **Domain/Use Cases**: Pure business logic (drift calculations, parsing)
- **Data**: Repositories coordinating between local (Room, DataStore) and remote (Retrofit services, GRIB parser)
- **Layered Architecture** with clear separation of concerns
- **Repository Pattern** for decoupling data sources
- **Dependency Injection** (KSP) to wire ViewModels to Repositories

A. Presentation Layer (Client)
- **UI Screens & Composables** (HomeScreen, MapScreen, SOS, Catch Log, Profile)
- **AppNavHost** for navigation
- **Jetpack Compose + Material 3** for rendering
B. ViewModel Layer
- **HomeViewModel**, **MapViewModel**, **GribViewModel**, **FishingLogViewModel**, etc.
- Expose UI state (LiveData/StateFlow)
C. Domain Layer (Use Cases)
- **calculateDriftVectors**, **calculateDriftImpact**, weather data aggregators
- Pure Kotlin functions and models
D. Data Layer
1. **Repositories**: AisRepository, GribRepository, MetAlertsRepository, FishLogRepository, etc.
2. **Local Data Source**
– **Room Database** (AppDatabase + DAOs for FishingLog, FishType, User, Favorites, Suggestions)
– **DataStore** for preferences (AppDataStore)
3. **Remote Data Source**
– **Retrofit Instances**: BarentsWatchRetrofitInstance, GeocodingRetrofitInstance, GribRetrofitInstance, MetAlertsRetrofitInstance
– **API Service Interfaces**: WeatherService, BarentsWatchAuthService, etc.
– **Datasources** wrapping raw calls: BarentsWatchDataSource, GribDataSource, etc.
4. **Local Parser** (GribParser via NetCDF-Java/CDM)
E. External Systems & Services
- **BarentsWatch API** (AIS + forbud zones)
- **MET Norway/MetAlerts API**
- **MapTiler Tiles / MapLibre GL**
- **Stadia Maps (Geocoding)**
- **Media3** (audio alerts)
- **Device Platform** (Android Location Services, Camera, Storage)

##### Relationships & Data Flow
- **UI → ViewModel**: User actions and events
- **ViewModel → Domain Use Case**: Invoke business logic
- **ViewModel → Repository**: Fetch or update data
- **Repository → Local/Remote Data Source**:
- If cache exists → Room/Datastore
- Else → Retrofit → parse → emit results
- **Remote Data Source → Repository**: Return parsed models
- **Repository → ViewModel**: Wrap in Result<T>, expose state
- **ViewModel → UI**: Observe and render changes
- **Device Sensors/Permissions**: UI requests location or camera; results flow back to ViewModel

##### Essential Architectural Elements to Capture
- MVVM layer separation
- Repository pattern between Domain and Data
- Dual data sources (local cache vs remote APIs)
- Parsing sub-system (NetCDF/CDM) as its own component
- External API endpoints and authentication flows
- Android platform dependencies (Permissions, Sensors, Camera)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        AppNavHost["AppNavHost\n(Navigation)"]:::presentation
        HomeScreen["HomeScreen"]:::presentation
        MapScreen["MapScreen"]:::presentation
        FishingLogScreen["FishingLogScreen"]:::presentation
        SosScreen["SosScreen"]:::presentation
        ProfileScreen["ProfileScreen"]:::presentation
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        direction TB
        HomeVM["HomeViewModel"]:::viewmodel
        MapVM["MapViewModel"]:::viewmodel
        GribVM["GribViewModel"]:::viewmodel
        FishLogVM["FishingLogViewModel"]:::viewmodel
        ProfileVM["ProfileViewModel"]:::viewmodel
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        CalcDrift["calculateDriftVectors()"]:::domain
        DriftUtils["Driftutils"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        GribRepo["GribRepository"]:::data
        AppDB["AppDatabase\n(Room)"]:::data
        GribParser["GribParser"]:::data
        GribDS["GribDataSource\n(Retrofit)"]:::data
    end

    %% External & Infrastructure
    subgraph "External & Infrastructure"
        direction TB
        BarentsWatchAPI["BarentsWatch API"]:::external
        MetAlertsAPI["MET Norway API"]:::external
        AndroidOS["Android OS\n(Location, Camera)"]:::external
    end

    %% Connections
    HomeScreen -->|"events"| HomeVM
    MapScreen -->|"events"| MapVM
    FishingLogScreen -->|"events"| FishLogVM
    ProfileScreen -->|"events"| ProfileVM

    HomeVM -->|"invoke use case"| CalcDrift
    MapVM -->|"invoke use case"| CalcDrift
    GribVM -->|"invoke use case"| CalcDrift

    CalcDrift -->|"utils"| DriftUtils

    GribVM -->|"fetch data"| GribRepo
    FishLogVM -->|"fetch data"| GribRepo
    ProfileVM -->|"fetch data"| GribRepo

    GribRepo -->|"local cache"| AppDB
    GribRepo -->|"parse GRIB"| GribParser
    GribRepo -->|"remote call"| GribDS

    GribDS -->|"HTTP calls"| BarentsWatchAPI
    GribDS -->|"HTTP calls"| MetAlertsAPI

    AppDB -->|"reads/writes"| AndroidOS
    GribParser -->|"netcdf parsing"| AndroidOS

    %% Click Events
    click AppNavHost "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/presentation/navigation/AppNavHost.kt"
    click HomeScreen "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/presentation/home/screens/HomeScreen.kt"
    click MapScreen "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/presentation/map/screens/MapScreen.kt"
    click FishingLogScreen "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/presentation/fishlog/screens/FishingLogScreen.kt"
    click SosScreen "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/presentation/sos/screens/SosScreen.kt"
    click ProfileScreen "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/presentation/profile/screens/ProfileScreen.kt"
    click MapVM "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/presentation/map/viewmodel/MapViewModel.kt"
    click GribVM "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/presentation/grib/viewmodel/GribViewModel.kt"
    click FishLogVM "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/presentation/fishlog/viewmodel/FishingLogViewModel.kt"
    click ProfileVM "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/presentation/profile/viewmodel/ProfileViewModel.kt"
    click CalcDrift "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/domain/usecase/drift/calculateDriftVectors.kt"
    click DriftUtils "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/domain/usecase/drift/Driftutils.kt"
    click GribRepo "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/data/repository/GribRepository.kt"
    click AppDB "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/data/local/database/AppDataBase.kt"
    click GribParser "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/data/local/parser/GribParser.kt"
    click GribDS "https://github.com/jonesstoen/fiskeklar/blob/main/app/src/main/java/no/uio/ifi/in2000/team46/data/remote/datasource/GribDataSource.kt"

    %% Styles
    classDef presentation fill:#2196f3,stroke:#1e88e5,color:white
    classDef viewmodel fill:#4caf50,stroke:#388e3c,color:white
    classDef domain fill:#ffeb3b,stroke:#fbc02d,color:black
    classDef data fill:#ff9800,stroke:#f57c00,color:white
    classDef external fill:#9e9e9e,stroke:#616161,color:white
```
