# joinreinvest/reinvest-fe-common architecture

> Architecture diagram of the GitHub repository joinreinvest/reinvest-fe-common, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/joinreinvest/reinvest-fe-common
- Repository: https://github.com/joinreinvest/reinvest-fe-common

## Overview

##### Project Type & Purpose
- This is a common library meant to be shared by the Reinvest APP. Its goal is to centralize constants, form schema definitions, service integrations (e.g., handling addresses, form flows, and various queries), and utility functions. The library appears to support account creation, updates, investment workflows, and various queries related to a financial or investment application.

##### Key Components from the File Structure
- Constants: The “src/constants” folder contains many configuration values (account types, conversions, industries, etc.) that the entire library references.
- Form Schemas: “src/form-schemas” holds definitions for form structures (e.g., investment forms, file forms) that outline the data formats and user-input validations.
- Services: The “src/services” directory is segmented into multiple subdomains:
- Address Services: Provides functionality related to address handling.
- Form Flow Module: Contains clients (React components such as context providers), hooks (e.g., useCurrentStep, useFields), generators, processors, and utilities to manage user form steps and validations.
- Queries: A rich set of GraphQL queries and mutations related to account operations, investment initiation, bank account management, document management, and more. Notice the “queries” subfolder contains both specific query methods (e.g., “createBankAccount.ts”, “updateProfile.ts”) and GraphQL fragments.
- Types: The “src/types” folder holds type definitions for documents, investments, and GraphQL – ensuring type safety across the codebase.
- Utilities & Configuration: General purpose modules (e.g., for handling dates, currency, phone numbers) and external configuration files (e.g., tsup.config.js, tsconfig.json) are also included.

##### Architectural Patterns & Design Principles
- Modularity & Separation of Concerns: The project cleanly splits functionality into constants, schema definitions, services that encapsulate distinct business logic areas, types, and utilities.
- Layered Design: The architecture can be pictured as layers:
- Core Data & Config (Constants, Form Schemas, Types)
- Business Logic & Service Layer (Address, Form Flow, Queries)
- Integration Utilities (helpers for date, currency, phone number conversions)
- Reusability: Separating universal elements (such as form flow management and query operations) allows the library to be effectively reused by other parts of the larger Reinvest APP.

- Constants Module: Display as a standalone block providing input to almost every module.
- Form Schemas: Represent as a block that feeds into the form flow services.
- Services:
- Address Service: Handles address operations.
- Form Flow Service: Encompasses sub-components:
- Client Components (e.g., client.tsx, context provider)
- Generators (consumer, provider, context)
- Hooks (for progress, current step, etc.)
- Processors (for flow steps and store operations)
- Utilities (for messages and validation)
- Queries Service: Includes:
- Individual query files (e.g., create, update, withdraw operations)
- GraphQL fragments for shared data parts
- Types Module: Serves as a support structure for ensuring type consistency.
- Utilities Module: Contains helper functions for common transformations and configurations.
- External Build/Config Tools: Represent codegen.ts, tsup.config.js, tsconfig.json, etc., outlining build and integration points.

b. Relationships & Interactions:
- In the Form Flow Service, indicate the flow between client components, hooks, generators, and processors to emphasize the progressive stages of form handling.
- The Queries module should display a dependency relationship with the GraphQL fragments and how these queries can interface with external APIs or database backends.
- Utilities should be shown as helper layers that assist various services.

c. Highlighting Patterns & Technologies:
- Modularity by grouping components into logical layers.
- Use clear labels for each module and showcase external integrations such as GraphQL (through queries and fragments) and TypeScript tooling (via configuration files).
- That React (suggested by the .tsx files in the form-flow folder) is in use for managing dynamic UI aspects of form processes.

- Optionally, indicate a “Build/Integration” section to represent the code generation and configuration processes which enable the library to be compiled and bundled (using tsup and codegen).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Data & Config Layer
    subgraph "Core Data & Config"
        A["Constants"]:::core
        B["Form Schemas"]:::core
        C["Types"]:::core
    end

    %% Business Logic & Services Layer
    subgraph "Business Logic & Services"
        D["Address Service"]:::service
        subgraph "Form Flow Service"
            D1["Client Components"]:::ui
            D2["Generators"]:::service
            D3["Hooks"]:::service
            D4["Processors"]:::service
            D5["Utilities"]:::service
        end
        subgraph "Queries Service"
            E1["Query Files"]:::service
            E2["GraphQL Fragments"]:::service
        end
    end

    %% Integration & External Tools Layer
    subgraph "Integration & External Tools"
        F["Utilities Module"]:::integration
        subgraph "Build/Config Tools"
            F1["codegen.ts"]:::integration
            F2["tsup.config.js"]:::integration
            F3["tsconfig.json"]:::integration
        end
    end

    %% Relationships from Core Layer to Business Logic
    A -->|"provides_config"| D
    A -->|"defines_constants"| D1
    B -->|"defines_forms"| D1
    B -->|"defines_forms"| E1
    C -->|"ensures_types"| D
    C -->|"ensures_types"| D1
    C -->|"ensures_types"| E1

    %% Internal Form Flow Service Relationships
    D1 -->|"initiates_flow"| D2
    D2 -->|"triggers_hooks"| D3
    D3 -->|"processes_data"| D4
    D4 -->|"updates_store"| D5

    %% Queries Service internal relationship
    E1 -->|"incorporates"| E2

    %% Utilities Module support to Business Logic
    F -->|"assists"| D
    F -->|"assists"| D1
    F -->|"assists"| E1

    %% Build/Config Tools integration to Core
    F1 -->|"builds"| A
    F2 -->|"bundles"| A
    F3 -->|"compiles"| A

    %% Styling Definitions
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef service fill:#fcf,stroke:#333,stroke-width:2px;
    classDef ui fill:#cfc,stroke:#333,stroke-width:2px;
    classDef integration fill:#ffc,stroke:#333,stroke-width:2px;

    %% Click Events
    click A "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/constants"
    click B "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/form-schemas"
    click C "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/types"
    click D "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/services/address"
    click D1 "https://github.com/joinreinvest/reinvest-fe-common/blob/main/src/services/form-flow/client.tsx"
    click D2 "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/services/form-flow/generators"
    click D3 "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/services/form-flow/hooks"
    click D4 "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/services/form-flow/processors"
    click D5 "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/services/form-flow/utilities"
    click E1 "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/services/queries"
    click E2 "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/services/queries/fragments"
    click F "https://github.com/joinreinvest/reinvest-fe-common/tree/main/src/utilities"
    click F1 "https://github.com/joinreinvest/reinvest-fe-common/blob/main/codegen.ts"
    click F2 "https://github.com/joinreinvest/reinvest-fe-common/blob/main/tsup.config.js"
    click F3 "https://github.com/joinreinvest/reinvest-fe-common/blob/main/tsconfig.json"
```
