How rnhc1000/calculatorui works
Main components
• Frontend Application: Represent the ReactJS codebase that includes the UI and components.
• Key folders: src (with App.tsx, assets, components, routes, hooks, services, models, and utils).
• Components such as Header, Footer, Login, Operations, and various UI elements (like FormInput, AG-GRID based datatable, etc.) form the core view layer.
• React Router: Routing between pages such as Home, Login, Operation, and Records.
• React Context & State Management: Components such as ContextWalletBalance (in utils/context-wallet.ts and similar for token). This handles real-time balance updates and authentication state.
• Services Layer: Responsible for handling communication with the external RESTful API. Services include:
• auth-services.ts, operation-services.ts, csrf-services.ts, records-services.ts, user-service.ts, wallet-services.ts.
• Local Storage Repositories: Modules to manage tokens and wallet data (in src/localstorage).
• External RESTful API: Located externally (https://api.ferreiras.dev.br), which actually performs the math operations, ensures security with authentication, and manages recorded operations in the backend database.
Relationships and interactions
• The user interacts with the UI (constructed of multiple React components).
• Upon login, the authentication service (auth-services.ts) communicates with the REST API to validate credentials, retrieves JWT tokens, and then updates the React Context.
• The UI components take advantage of React Hooks (useState, useEffect, etc.) to update UI state (for balance, operation results) in real time.
• When the user initiates a math operation, the front-end makes a REST call through its service layer to the back-end API. The response (result of the operation and updated balance) flows back to update the UI, stored locally, and possibly persisted in localStorage.
• The AG-GRID based table component displays a history of operations by fetching data from the backend via the corresponding service.
Important architectural patterns and design principles
• Separation of Concerns: UI components, business logic (services), and state management (React Context/localstorage) are mutually separated.
• Component-Based UI: Every UI part (header, login, table view, footer) is built as its own component, encouraging reuse and maintainability.
• Service Abstraction: All API communication is encapsulated in dedicated service modules.
• Routing and Navigation: React Router is used to neatly manage different pages and their state.
• Configuration & Environment: Environment variables (seen in the system.ts file) are used to set the base URL for the backend, making the instance configurable per deployment.
Specific technologies and frameworks
• ReactJS with TypeScript
• React Router for navigation
• React Hooks and React Context for state management (e.g., wallet and token)
• AG-GRID for displaying operation records
• Vite as the build tool
• Additional libraries: axios for HTTP requests, jwt-decode for token management, and others found in the .vite/deps folder.
• User -> UI Components
• UI Components <-> Service Modules
• Service Modules -> External REST API
• API responses -> UI update (via Context and Hooks)
Bring it all together
• Next, illustrate the API Service Layer as a middle tier that abstracts direct REST calls.
• Notes about environment configuration (e.g., BASE_URL in system.ts) and mention that deployment may require tweaking these settings (as mentioned in the README).