How joinreinvest/reinvest-fe-common works
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).