# trosydman/justposts architecture

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

- Interactive diagram: https://gitdiagram.com/trosydman/justposts
- Repository: https://github.com/trosydman/justposts

## Overview

##### Main Components
- UI Layer:
- MainActivity.kt as the single-activity host.
- Two main Fragments: PostsFragment.kt (displays a paginated list of posts) and PostDetailsFragment.kt (displays details for a selected post).
- Associated ViewModels: PostsViewModel.kt and PostDetailsViewModel.kt.

- Domain Layer:
- Data models representing the domain (Post and User).
- Mappers (PostsResponseDTOMapper.kt and Data1DTOMapper.kt) to convert data from API responses into UI/domain models.

- Data Layer:
- Repository: PostRepository.kt, which encapsulates logic for data retrieval.
- Data Sources:
▫ Remote: GraphQLRemoteDataSource (and GraphQLZeroClient with its interface IGraphQLZeroClient for GraphQL communication).
- GraphQL schema and query files (Posts.graphql, schema.json) located under the graphql directory.

- Dependency Injection and Configuration:
- DI modules (ClientModule.kt, NetworkModule.kt, RemoteModule.kt, RepositoryModule.kt) that define how dependencies are provided.
- Build scripts and Gradle configuration files.

##### Relationships and Interactions
- The UI layer (Activity/Fragments) observes data via their respective ViewModels.
- ViewModels interact with the PostRepository to retrieve and update data.
- The Repository uses the GraphQLRemoteDataSource, which in turn uses the Apollo Client (configured and provided via DI) to fetch data from the GraphQLZero API.
- Mappers convert raw API responses into clean domain models that the UI can use.
- Dependency Injection (using Hilt) ties together these objects to ensure proper lifecycle and instance management.

##### Architectural Patterns and Principles
- MVVM (Model-View-ViewModel): Separates UI (Activities/Fragments) from business logic (ViewModels) and data handling.
- Clean Architecture/Repository Pattern: The repository abstracts data operations, and mappers decouple the DTOs (from Apollo) from domain models.
- Dependency Injection (Hilt): Simplifies the construction and management of dependency graphs.

##### Relevant Technologies and Frameworks
- Kotlin as the programming language.
- Android Jetpack components (ViewModel, LiveData, Navigation, Paging 3).
- Apollo Client for GraphQL.
- Hilt for dependency injection.
- Material Design for consistent user experience.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        MA["MainActivity"]:::ui
        MA_layout["MainActivity Layout"]:::ui
        PF["PostsFragment"]:::ui
        PF_layout["PostsFragment Layout"]:::ui
        PDF["PostDetailsFragment"]:::ui
        PDF_layout["PostDetailsFragment Layout"]:::ui
        PVM["PostsViewModel"]:::ui
        PDVM["PostDetailsViewModel"]:::ui
    end

    subgraph "Domain Layer"
        Post["Post Model"]:::domain
        User["User Model"]:::domain
        Mapper1["PostsResponseDTOMapper"]:::domain
        Mapper2["Data1DTOMapper"]:::domain
    end

    subgraph "Data Layer"
        Repo["PostRepository"]:::data
        RemoteDS["GraphQLRemoteDataSource"]:::data
        GraphQLClient["GraphQLZeroClient"]:::data
        IGraphQL["IGraphQLZeroClient"]:::data
        GraphQLFiles["GraphQL Files"]:::data
    end

    subgraph "Dependency Injection"
        ClientMod["ClientModule"]:::di
        NetworkMod["NetworkModule"]:::di
        RemoteMod["RemoteModule"]:::di
        RepoMod["RepositoryModule"]:::di
    end

    %% UI Layer Connections
    MA -->|"navigatesTo"| PF
    MA -->|"navigatesTo"| PDF
    MA -->|"uses"| MA_layout
    PF -->|"uses"| PF_layout
    PDF -->|"uses"| PDF_layout
    PF -->|"observes"| PVM
    PDF -->|"observes"| PDVM

    %% Inter-layer Connections
    PVM -->|"requestsData"| Repo
    PDVM -->|"requestsData"| Repo

    Repo -->|"mapsTo"| Mapper1
    Repo -->|"mapsTo"| Mapper2
    Repo -->|"fetchesFrom"| RemoteDS

    RemoteDS -->|"calls"| GraphQLClient
    RemoteDS -->|"calls"| IGraphQL
    RemoteDS -->|"utilizes"| GraphQLFiles

    %% Dependency Injection Connections
    ClientMod -->|"provides"| GraphQLClient
    NetworkMod -->|"provides"| RemoteDS
    RemoteMod -->|"provides"| Repo
    RepoMod -->|"provides"| PVM
    RepoMod -->|"provides"| PDVM

    %% Click Events for UI Layer
    click MA "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/ui/MainActivity.kt"
    click MA_layout "https://github.com/trosydman/justposts/blob/main/app/src/main/res/layout/activity_main.xml"
    click PF "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/ui/posts/PostsFragment.kt"
    click PF_layout "https://github.com/trosydman/justposts/blob/main/app/src/main/res/layout/fragment_posts.xml"
    click PDF "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/ui/post_details/PostDetailsFragment.kt"
    click PDF_layout "https://github.com/trosydman/justposts/blob/main/app/src/main/res/layout/fragment_post_details.xml"
    click PVM "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/ui/posts/PostsViewModel.kt"
    click PDVM "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/ui/post_details/PostDetailsViewModel.kt"

    %% Click Events for Domain Layer
    click Post "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/ui/model/Post.kt"
    click User "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/ui/model/User.kt"
    click Mapper1 "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/data_source/remote/api/graphqlzero/mapper/PostsResponseDTOMapper.kt"
    click Mapper2 "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/data_source/remote/api/graphqlzero/mapper/Data1DTOMapper.kt"

    %% Click Events for Data Layer
    click Repo "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/repository/PostRepository.kt"
    click RemoteDS "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/data_source/remote/GraphQLRemoteDataSource.kt"
    click GraphQLClient "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/data_source/remote/api/graphqlzero/GraphQLZeroClient.kt"
    click IGraphQL "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/data_source/remote/api/graphqlzero/IGraphQLZeroClient.kt"
    click GraphQLFiles "https://github.com/trosydman/justposts/blob/main/app/src/main/graphql/com/cmesquita/technicaltest/justposts/Posts.graphql"

    %% Click Events for Dependency Injection
    click ClientMod "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/di/ClientModule.kt"
    click NetworkMod "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/di/NetworkModule.kt"
    click RemoteMod "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/di/RemoteModule.kt"
    click RepoMod "https://github.com/trosydman/justposts/blob/main/app/src/main/java/com/cmesquita/technicaltest/justposts/di/RepositoryModule.kt"

    %% Styles
    classDef ui fill:#B3E5FC,stroke:#01579B,stroke-width:2px;
    classDef domain fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef data fill:#FFECB3,stroke:#FF6F00,stroke-width:2px;
    classDef di fill:#E1BEE7,stroke:#6A1B9A,stroke-width:2px;
```
