# programandonocosmos/cashtools-api architecture

> Architecture diagram of the GitHub repository programandonocosmos/cashtools-api, 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/programandonocosmos/cashtools-api
- Repository: https://github.com/programandonocosmos/cashtools-api

## Overview

##### Main Components
- API/Web Server: Representing the Rocket-based application running as the core HTTP/GraphQL server.
- GraphQL Layer: Highlight the GraphQL resolvers (in src/graphql_resolvers.rs) that handle query/mutation endpoints using Juniper.
- Services Layer: Include the distinct service components (in src/services) such as account, transaction, and user services that encapsulate business logic.
- Authentication Component: Show the JWT-based authentication (see src/jwt.rs) that secures access to API endpoints.
- External Integrations: Include components for external communications such as Nubank integration (modules under src/nubank) and possibly email sending (src/sendemail.rs).
- Utilities & Models: Although more internal, it’s useful to note that entities (src/entities) and models (src/models) represent the domain objects, while utilities (src/utils) provide supporting functionality.

##### Relationships & Interactions
- The API/Web Server (Rocket) receives HTTP requests and routes them to the corresponding GraphQL resolvers or REST endpoints.
- GraphQL resolvers interface with the services layer to perform business logic.
- Services interact with the Database (via Diesel) to perform CRUD operations.
- External integrations like the Nubank module and email functionality are invoked from within the services to handle specific tasks (e.g., authentication with an external banking API, sending notifications).
- The migrations folder and Diesel configuration indicate continuous schema evolution; include a note about this migration management as part of database setup.

##### Architectural Patterns & Technologies
- The project uses an MVC-like separation between models/entities (representing data), services (business logic), and the API layer (controllers/resolvers).
- The use of Diesel for database communication indicates a focus on strong typing and migration-based schema management.
- JWT authentication is key for API security.
- Rocket and Juniper define the structure for API endpoints (possibly REST and GraphQL).
- External integration modules (like src/nubank) show a plug-in approach to extend functionality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core API Layer
    subgraph "Core API Layer"
        APIServer["API Server (Rocket)"]
        JWT["JWT Authentication (JWT)"]
        GraphQL["GraphQL Resolvers (Juniper)"]
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Services["Services (Business Logic)"]
        Account["Account Service"]
        Transaction["Transaction Service"]
        UserSvc["User Service"]
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        Diesel["Database Access (Diesel)"]
        Postgres["PostgreSQL Database"]
    end

    %% External Integrations
    subgraph "External Integrations"
        Nubank["Nubank Integration"]
        Email["Email Service"]
    end

    %% Domain Model
    subgraph "Domain Model"
        Entities["Entities"]
        Models["Models"]
        Utilities["Utilities"]
    end

    %% Connections
    %% API Layer interactions
    APIServer -->|"HTTP/GraphQL_Request"| GraphQL
    APIServer -->|"Auth_Check"| JWT

    %% GraphQL to Business Logic
    GraphQL -->|"Resolve_Query/Mutation"| Services

    %% Business Logic detailed services
    Services --> Account
    Services --> Transaction
    Services --> UserSvc

    %% Business Logic to Data Access
    Services -->|"CRUD_Operations"| Diesel
    Diesel -->|"DB_Query"| Postgres

    %% Business Logic external integrations
    Services -->|"External_API_Call"| Nubank
    Services -->|"Send_Email"| Email

    %% Domain Model relationships
    Entities -.->|"Domain_Objects"| Services
    Models -.->|"Data_Mapping"| Diesel
    Utilities -.->|"Support_Functions"| Services

    %% Styling Classes
    class APIServer,JWT,GraphQL apiLayer
    class Services,Account,Transaction,UserSvc businessLayer
    class Diesel,Postgres dataLayer
    class Nubank,Email externalLayer
    class Entities,Models,Utilities domainLayer

    %% Click Events
    click APIServer "https://github.com/programandonocosmos/cashtools-api/blob/main/src/main.rs"
    click JWT "https://github.com/programandonocosmos/cashtools-api/blob/main/src/jwt.rs"
    click GraphQL "https://github.com/programandonocosmos/cashtools-api/blob/main/src/graphql_resolvers.rs"
    click Services "https://github.com/programandonocosmos/cashtools-api/tree/main/src/services"
    click Account "https://github.com/programandonocosmos/cashtools-api/blob/main/src/services/account.rs"
    click Transaction "https://github.com/programandonocosmos/cashtools-api/blob/main/src/services/transaction.rs"
    click UserSvc "https://github.com/programandonocosmos/cashtools-api/blob/main/src/services/user.rs"
    click Diesel "https://github.com/programandonocosmos/cashtools-api/blob/main/src/database.rs"
    click Nubank "https://github.com/programandonocosmos/cashtools-api/tree/main/src/nubank"
    click Email "https://github.com/programandonocosmos/cashtools-api/blob/main/src/sendemail.rs"
    click Entities "https://github.com/programandonocosmos/cashtools-api/tree/main/src/entities"
    click Models "https://github.com/programandonocosmos/cashtools-api/tree/main/src/models"
    click Utilities "https://github.com/programandonocosmos/cashtools-api/blob/main/src/utils/mod.rs"

    %% Class Definitions for Styling
    classDef apiLayer fill:#F9D7D3,stroke:#B22222,stroke-width:2px;
    classDef businessLayer fill:#D2F8D2,stroke:#228B22,stroke-width:2px;
    classDef dataLayer fill:#D0E6F8,stroke:#1E90FF,stroke-width:2px;
    classDef externalLayer fill:#FFF3B0,stroke:#DAA520,stroke-width:2px;
    classDef domainLayer fill:#E6D0F8,stroke:#8A2BE2,stroke-width:2px;
```
