# ludwig-g-w/chaincred architecture

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

- Interactive diagram: https://gitdiagram.com/ludwig-g-w/chaincred
- Repository: https://github.com/ludwig-g-w/chaincred

## Overview

##### Major Components
- Frontend/Mobile Client:
– The “app” directory (with nested (tabs), screen files, routing layouts) and the “lib” folder (containing UI components, screens, utilities, and services) represent the mobile client built in React Native/Expo.
– Native project integration is reflected by the “android” and “ios” directories that contain platform-specific configuration and build files.
- Backend/API Layer:
– The “api” directory and the “server.js” file indicate that there is an API service.
– tRPC endpoints (in app/api, and lib/trpc-server) are used for RPC-style communication.
– There are also routes for authentication (auth) and blockchain interactions.
- External Services & Data Persistence:
– Thirdweb: Handling user authentication (using SIWE/EIP-4361) and blockchain interactions.
– EAS: For attestation verification.
– Supabase: Serving as the backend database service.
– Prisma: Used for database access modelling (see lib/services/db with schema.prisma, migrations, etc.).
– Additional integration with Google (via API keys), and possibly GraphQL (noting “generated/graphql.ts” and “graphql.schema.json”).

##### Relationships and Interactions
- Mobile Client:
– Displays UI screens (discover, home, settings, login, profile, etc.) and interacts with native modules.
– It invokes API endpoints for authentication, fetching data, and submitting reviews.
– Integrates directly with Thirdweb’s React Native SDK for blockchain calls.
- API/Backend:
– Exposes endpoints to manage authentication, blockchain transactions, and tRPC-based calls.
– Acts as a mediator between the mobile app and external services.
- External Services:
– Thirdweb’s Authentication and Blockchain SDKs handle wallet interactions.
– EAS verifies attestations (scanning Ethereum addresses).
– Supabase and Prisma handle data storage and relational database operations.
- Data Flow:
– User actions in the mobile client (like QR scanning and review submission) trigger API calls.
– The API layer processes requests, interacts with databases, and calls out to third-party services (e.g., blockchain attestation via EAS).
– Data and responses flow back through the API to update the UI.

##### Architectural Patterns & Design Principles
- Modular Separation of Concerns:
– Segregate UI components (inside “app” and “lib/components”) from business logic (services in “lib/services” and “lib/trpc-server”) and data access (Prisma, Supabase integrations).
- Use of tRPC for type-safe API routing.
- Multi-platform development: including separate directories and configurations for iOS, Android, and potentially web (React Native supports web with Expo).
- Docker integration suggests containerized development for the API/backend services.
- Utilization of external SDKs (Thirdweb, EAS) suggests adherence to established blockchain and attestation patterns.

##### Specific Elements
– API calls from the mobile app to the backend.
– Blockchain interactions from both the mobile and backend layers with Thirdweb/EAS.
– Data persistence flows between the API and the database.
– Presentation/UI components vs. business logic vs. external service integrations.
– Internal (in-house modules) vs. External (Thirdweb, Supabase, etc.) components.

##### Additional Notes for Maximum Clarity
- Detail any middleware (like rate limiting in lib/trpc-server/middleware) to show where request processing or validation happens.
- Configuration and environment specifics (seen from the .env file, docker-compose, and related scripts) to reflect deployment or containerized architecture.
- Since the project also includes code generation (codegen.ts, codegen.yml) and has a strict file structure, mention that each module’s dependency is clearly structured, which can help in tracing data flows and control.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Mobile Client (React Native/Expo)"
        direction TB
        subgraph "UI/UX Layer"
            direction TB
            UI_Screens["UI Screens & Navigation (app/)"]:::mobile
            UI_Components["UI Components & Utilities (lib/components, lib/screens)"]:::mobile
        end
        subgraph "Native Modules"
            direction TB
            Android["Android Native (android/)"]:::mobile
            iOS["iOS Native (ios/)"]:::mobile
        end
    end

    subgraph "API/Backend Layer"
        direction TB
        API_Endpoints["API Endpoints (api/, server.js)"]:::backend
        tRPC["tRPC Endpoints (app/api/trpc, lib/trpc-server)"]:::backend
        GraphQL["GraphQL Integration (generated/graphql.ts, graphql.schema.json)"]:::backend
    end

    subgraph "Database & Data Persistence"
        direction TB
        Prisma["Prisma Integration (lib/services/db)"]:::database
        Supabase["Supabase Integration (lib/services/supabase.ts, generated/supabase.ts)"]:::database
    end

    subgraph "External Services"
        direction TB
        Thirdweb["Thirdweb SDK (lib/services/thirdwebAuth.ts, lib/services/thirdwebClient.ts)"]:::external
        EAS["EAS Attestation Service (lib/utils/eas.tsx)"]:::external
        Google["Google Services (API Keys)"]:::external
    end

    UI_Screens -->|"APIcalls"| API_Endpoints
    UI_Components -->|"EventTriggers"| API_Endpoints
    API_Endpoints -->|"InvokesTRPC"| tRPC
    API_Endpoints -->|"HandlesGraphQL"| GraphQL

    API_Endpoints -->|"DBoperations"| Prisma
    API_Endpoints -->|"DBoperations"| Supabase

    API_Endpoints -->|"BlockchainAttestation"| Thirdweb
    API_Endpoints -->|"AttestationVerification"| EAS
    UI_Screens -->|"BlockchainActions"| Thirdweb

    API_Endpoints -->|"IntegratesWith"| Google

    click UI_Screens "https://github.com/ludwig-g-w/chaincred/tree/main/app/"
    click UI_Components "https://github.com/ludwig-g-w/chaincred/tree/main/lib/components"
    click Android "https://github.com/ludwig-g-w/chaincred/tree/main/android/"
    click iOS "https://github.com/ludwig-g-w/chaincred/tree/main/ios/"
    click API_Endpoints "https://github.com/ludwig-g-w/chaincred/tree/main/api/"
    click API_Endpoints "https://github.com/ludwig-g-w/chaincred/blob/main/server.js"
    click tRPC "https://github.com/ludwig-g-w/chaincred/tree/main/app/api/trpc/"
    click tRPC "https://github.com/ludwig-g-w/chaincred/tree/main/lib/trpc-server/"
    click GraphQL "https://github.com/ludwig-g-w/chaincred/blob/main/generated/graphql.ts"
    click GraphQL "https://github.com/ludwig-g-w/chaincred/blob/main/graphql.schema.json"
    click Prisma "https://github.com/ludwig-g-w/chaincred/tree/main/lib/services/db/"
    click Supabase "https://github.com/ludwig-g-w/chaincred/blob/main/lib/services/supabase.ts"
    click Supabase "https://github.com/ludwig-g-w/chaincred/blob/main/generated/supabase.ts"
    click Thirdweb "https://github.com/ludwig-g-w/chaincred/blob/main/lib/services/thirdwebAuth.ts"
    click Thirdweb "https://github.com/ludwig-g-w/chaincred/blob/main/lib/services/thirdwebClient.ts"
    click EAS "https://github.com/ludwig-g-w/chaincred/blob/main/lib/utils/eas.tsx"

    classDef mobile fill:#AEDFF7,stroke:#036,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef database fill:#FFF59D,stroke:#F9A825,stroke-width:2px;
    classDef external fill:#FFCC80,stroke:#FB8C00,stroke-width:2px;

    class UI_Screens,UI_Components,Android,iOS mobile;
    class API_Endpoints,tRPC,GraphQL backend;
    class Prisma,Supabase database;
    class Thirdweb,EAS,Google external;
```
