# rmanguinho/clean-react architecture

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

- Interactive diagram: https://gitdiagram.com/rmanguinho/clean-react
- Repository: https://github.com/rmanguinho/clean-react

## Overview

##### Project type and purpose
- This is a front‐end React application (“4Dev React – Enquetes para Programadores”) built with TypeScript, using Clean Architecture and TDD.
- It implements a survey system that consumes a remote REST API (http://fordevs.herokuapp.com/api-docs), caches data in localStorage, and follows SOLID, DRY, KISS.

##### File structure
- Top‐level:
- public/ + template HTMLs (webpack entry points)
- src/ – contains all application code, subdivided into layers: presentation, main, data, domain, infra, validation
- tests/ – unit, integration and E2E (Cypress) tests
- Layers and patterns:
- presentation/ – React components, pages, hooks (UI layer)
- main/ – composition root: factories, adapters, decorators, routes (wiring + DI)
- data/ – usecases implementations, models, protocols (repository pattern)
- domain/ – business models, use‐case interfaces, domain errors
- infra/ – concrete HTTP (Axios) and cache (localStorage) adapters
- validation/ – field‐validation protocols and validators
- Build & CI: ESLint, Husky, Jest, Cypress, TravisCI, Webpack configs.

##### README insights
- Emphasis on Clean Architecture, SOLID, TDD.
- Lists design patterns used: Factory, Adapter, Composite, Decorator, Proxy, Builder.
- Technology stack: React + Hooks + Recoil, TypeScript, Axios, Cypress, Jest.

a. Main components
- Presentation Layer (React UI – pages & components)
- Main/Composition Root (factories, decorators, router)
- Domain Layer (use‐case interfaces + business models + errors)
- Data Layer (use‐case implementations, data models, protocol interfaces)
- Infra Layer (HTTP client adapter, localStorage adapter)
- External Services (Remote API, Browser LocalStorage)
b. Relationships & interactions
1. UI invokes a use‐case via a factory from main/
2. Factory wires: UseCaseInteractor (data/) implements DomainInterface
3. UseCaseInteractor depends on HTTPClientProtocol and CacheProtocol (data/protocols)
4. HTTPClientProtocol decorator (authorize‐http‐client‐decorator) wraps AxiosHttpClient (infra/http)
5. CacheProtocol implemented by LocalStorageAdapter (infra/cache)
6. HTTPClient → Remote API; LocalStorage → Browser localStorage
7. Responses propagate back through UseCase → UI for rendering
c. Architectural patterns & principles
- Clean Architecture layers, Dependency Inversion: domain interfaces implemented by data layer, wired in main.
- Factories as Composition Root, Decorator for HTTP client authorization, Proxy for private-route.
- Builder & Composite for validation rules.
d. Key technologies
- React + Hooks + Recoil (state management)
- TypeScript (typing + modules)
- Axios for HTTP, localStorage for caching
- Webpack for bundling, Jest & React Testing Library for unit tests, Cypress for E2E

##### Essential elements
- Clear labels (e.g., “SurveyListPage”, “RemoteLoadSurveyListUseCase”, “AuthorizeHttpClientDecorator”).
- Annotations for design patterns at work (e.g., “Factory”, “Decorator”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        SurveyListPage["SurveyListPage"]:::presentation
    end

    %% Main / Composition Root
    subgraph "Main / Composition Root"
        direction TB
        PageFactories["Pages Factories\n(Factory)"]:::main
        UseCaseFactories["UseCase Factories"]:::main
        AuthorizeHttpClientDecorator["AuthorizeHttpClientDecorator\n(Decorator)"]:::main
        Router["router.tsx\n(Routes)"]:::main
        PrivateRouteProxy["private-route.tsx\n(Proxy)"]:::main
        ValidationBuilder["validation-builder.ts\n(Builder)"]:::main
        ValidationComposite["validation-composite.ts\n(Composite)"]:::main
        APIUrlFactory["api-url-factory.ts\n(API URL Factory)"]:::main
        AxiosHttpClientFactory["axios-http-client-factory.ts"]:::main
        LocalStorageAdapterFactory["local-storage-adapter-factory.ts"]:::main
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        DomainInterface["UseCase Interface"]:::domain
        BusinessModel["Survey Model"]:::domain
        DomainErrors["Domain Errors"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        UseCaseInteractor["RemoteLoadSurveyListUseCase"]:::data
        HttpClientProtocol["http-client.ts\n(HTTPClientProtocol)"]:::data
        CacheGet["get-storage.ts\n(CacheProtocol GET)"]:::data
        CacheSet["set-storage.ts\n(CacheProtocol SET)"]:::data
    end

    %% Infra Layer
    subgraph "Infra Layer"
        direction TB
        AxiosHttpClient["axios-http-client.ts\n(AxiosHttpClient)"]:::infra
        LocalStorageAdapter["local-storage-adapter.ts\n(LocalStorageAdapter)"]:::infra
    end

    %% External Services
    subgraph "External Services"
        direction TB
        RemoteAPI["Remote REST API"]:::external
        BrowserLocalStorage["Browser LocalStorage"]:::external
    end

    %% Connections - Request Flow
    SurveyListPage -->|"uses"| PageFactories
    PageFactories -->|"builds UseCase"| UseCaseFactories
    UseCaseFactories -->|"returns"| UseCaseInteractor
    UseCaseInteractor -->|"implements"| DomainInterface
    UseCaseInteractor -->|"depends on HTTPClientProtocol"| HttpClientProtocol
    UseCaseInteractor -->|"depends on CacheProtocol"| CacheGet
    UseCaseInteractor -->|"and"| CacheSet
    HttpClientProtocol -->|"decorated by"| AuthorizeHttpClientDecorator
    AuthorizeHttpClientDecorator -->|"wraps"| AxiosHttpClientFactory
    AxiosHttpClientFactory -->|"creates"| AxiosHttpClient
    AxiosHttpClient -->|"calls"| RemoteAPI
    CacheGet -->|"implemented by"| LocalStorageAdapter
    CacheSet -->|"implemented by"| LocalStorageAdapter
    LocalStorageAdapter -->|"reads/writes"| BrowserLocalStorage
    PageFactories -->|"uses Routing"| Router
    Router -->|"protects with"| PrivateRouteProxy
    PageFactories -->|"builds validation"| ValidationBuilder
    ValidationBuilder -->|"uses"| ValidationComposite
    APIUrlFactory -->|"provides URL to"| AxiosHttpClientFactory
    LocalStorageAdapterFactory -->|"provides"| LocalStorageAdapter

    %% Return Flow
    RemoteAPI -->|"response"| AxiosHttpClient
    BrowserLocalStorage -->|"data"| LocalStorageAdapter
    LocalStorageAdapter -->|"data"| UseCaseInteractor
    UseCaseInteractor -->|"data"| SurveyListPage

    %% Click Events
    click SurveyListPage "https://github.com/rmanguinho/clean-react/tree/master/src/presentation"
    click PageFactories "https://github.com/rmanguinho/clean-react/tree/master/src/main/factories/pages"
    click UseCaseFactories "https://github.com/rmanguinho/clean-react/tree/master/src/main/factories/usecases"
    click AuthorizeHttpClientDecorator "https://github.com/rmanguinho/clean-react/blob/master/src/main/decorators/authorize-http-client-decorator.ts"
    click Router "https://github.com/rmanguinho/clean-react/blob/master/src/main/routes/router.tsx"
    click PrivateRouteProxy "https://github.com/rmanguinho/clean-react/blob/master/src/main/proxies/private-route.tsx"
    click ValidationBuilder "https://github.com/rmanguinho/clean-react/blob/master/src/main/builders/validation-builder.ts"
    click ValidationComposite "https://github.com/rmanguinho/clean-react/blob/master/src/main/composites/validation-composite.ts"
    click APIUrlFactory "https://github.com/rmanguinho/clean-react/blob/master/src/main/factories/http/api-url-factory.ts"
    click AxiosHttpClientFactory "https://github.com/rmanguinho/clean-react/blob/master/src/main/factories/http/axios-http-client-factory.ts"
    click LocalStorageAdapterFactory "https://github.com/rmanguinho/clean-react/blob/master/src/main/factories/cache/local-storage-adapter-factory.ts"
    click DomainInterface "https://github.com/rmanguinho/clean-react/tree/master/src/domain"
    click BusinessModel "https://github.com/rmanguinho/clean-react/tree/master/src/domain"
    click DomainErrors "https://github.com/rmanguinho/clean-react/tree/master/src/domain"
    click UseCaseInteractor "https://github.com/rmanguinho/clean-react/tree/master/src/data"
    click HttpClientProtocol "https://github.com/rmanguinho/clean-react/blob/master/src/data/protocols/http/http-client.ts"
    click CacheGet "https://github.com/rmanguinho/clean-react/blob/master/src/data/protocols/cache/get-storage.ts"
    click CacheSet "https://github.com/rmanguinho/clean-react/blob/master/src/data/protocols/cache/set-storage.ts"
    click AxiosHttpClient "https://github.com/rmanguinho/clean-react/blob/master/src/infra/http/axios-http-client.ts"
    click LocalStorageAdapter "https://github.com/rmanguinho/clean-react/blob/master/src/infra/cache/local-storage-adapter.ts"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#0366d6,color:#0366d6,stroke-width:1px;
    classDef main fill:#e2e3e5,stroke:#6a737d,color:#6a737d,stroke-width:1px;
    classDef domain fill:#d4edda,stroke:#22863a,color:#22863a,stroke-width:1px;
    classDef data fill:#fff3cd,stroke:#735c0f,color:#735c0f,stroke-width:1px;
    classDef infra fill:#f5c6cb,stroke:#cb2431,color:#cb2431,stroke-width:1px;
    classDef external fill:#d6d8db,stroke:#1b1f23,color:#1b1f23,stroke-width:1px;
```
