# mizuch1/flousbank architecture

> Architecture diagram of the GitHub repository mizuch1/flousbank, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mizuch1/flousbank
- Repository: https://github.com/mizuch1/flousbank

## Overview

##### Project type and purpose
- This is a full-stack mobile banking application (“MBK App”) built with React Native (via Expo) for the client, and Supabase (Auth, PostgreSQL, Edge Functions) for the backend.
- It provides user authentication, account dashboard, transaction history, card management, transfers, branch/ATM locator, and a simple chatbot.

##### File structure
- Top‐level directories:
- android/ & ios/ → native platform build configurations & resources
- app/ → Expo Router–driven UI pages and layout for auth and tabbed navigation
- src/contexts → React Context providers (e.g., AccountContext)
- supabase/functions → custom Edge Functions (e.g., transfer‐funds)
- Configuration files: babel.config.js, tsconfig.json, package.json, app.json, eas.json, Supabase client initialization (src/supabaseClient.ts)
- Logical separation: UI layer (app/), state layer (contexts), backend functions (supabase/functions), native build (android/, ios/)

##### README for additional insights
- Confirms tech stack: Expo SDK, Expo Router, TypeScript, React Context API, Supabase Auth/DB, Edge Functions, expo modules (secure‐store, maps, location, file‐system)
- Highlights features and external service dependencies (react-native-maps, supabase Edge Functions)

##### Main components
a. Mobile Client (React Native + Expo)
- UI Pages & Layout (app/_layout.tsx, app/(tabs)/, app/(auth)/)
- Navigation Layer (Expo Router)
- State Management (AccountContext, other contexts in src/contexts)
- Local Storage (Expo Secure Store)
- Device services: Location (expo-location), Maps (react-native-maps), File System & Sharing (expo-file-system, expo-sharing)
b. Supabase Backend
- Authentication Service (Supabase Auth)
- PostgreSQL Database (accounts, transactions, cards, branches, profiles)
- Edge Functions (supabase/functions/transfer-funds)
c. External Services
- Expo Go app / Native runtimes (Android, iOS)
- Third‐party SDKs (Maps, Location, Secure Store)
d. Development & Deployment
- Metro bundler (expo start)
- EAS / CI pipelines (eas.json)

##### Interactions & data flows
- App startup → Expo Router loads auth guard → AccountContext checks token in Secure Store → if valid, load Dashboard
- User actions (e.g., “Transfer Funds”) → React form → invoke Supabase Edge Function → Edge Function interacts with PostgreSQL → returns status → UI updates
- Data fetch (transactions, cards, branches) → Supabase client → direct REST/GraphQL calls to Supabase → populate React state
- Locator map → device requests location → front end fetches branch data from Supabase → react-native-maps renders pins
- Chatbot → keyword matching on device or simple request to functions/state → UI responds

##### Architectural patterns & design principles
- Client–Server separation: mobile front end vs. Supabase backend
- Modular UI using Expo Router’s filesystem routing
- Context API for global state & dependency injection
- Edge Functions as BFF (Backend-for-Frontend) for sensitive operations (transfers)
- Secure handling of tokens (Expo Secure Store)
- Lazy-loading & code splitting via file-based routing

##### Detail
- Every key directory/module from your file tree (android/ios configs, app/ pages, src/contexts, supabase/functions)
- Both synchronous (direct DB read) and asynchronous flows (Edge Functions, location fetch)
- Environment/config dependencies (EXPO_PUBLIC_SUPABASE_URL, Anon Key)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Top Layer: User Device & Native Runtimes
    subgraph "User Device & Native Runtimes"
        direction TB
        ExpoGo("Expo Go"):::external
        AndroidNative("Android Runtime"):::external
        iOSNative("iOS Runtime"):::external
    end

    %% Middle Layer: Mobile App
    subgraph "Mobile App (React Native + Expo)"
        direction TB

        subgraph "UI Pages & Layout"
            direction TB
            LayoutApp["app/_layout.tsx"]:::client
            IndexPage["app/index.tsx"]:::client
            AuthLogin["app/(auth)/login.tsx"]:::client
            TabsLayout["app/(tabs)/_layout.tsx"]:::client
            BillsPage["app/(tabs)/bills.tsx"]:::client
            CardsPage["app/(tabs)/cards.tsx"]:::client
            ChatbotPage["app/(tabs)/chatbot.tsx"]:::client
            HistoryPage["app/(tabs)/history.tsx"]:::client
            LocatorPage["app/(tabs)/locator.tsx"]:::client
            MorePage["app/(tabs)/more.tsx"]:::client
            TransferPage["app/(tabs)/transfer.tsx"]:::client
            NotificationsPage["app/notifications.tsx"]:::client
            TransactionDetails["app/transaction-details.tsx"]:::client
            TransferConfirmation["app/transfer-confirmation.tsx"]:::client
        end

        subgraph "Navigation Layer"
            direction TB
            ExpoRouter["Expo Router"]:::client
        end

        subgraph "State Management"
            direction TB
            AccountContext["src/contexts/AccountContext.tsx"]:::client
        end

        subgraph "Local Device Services"
            direction TB
            SecureStore["Expo Secure Store"]:::external
            LocationSvc["Device Location (expo-location)"]:::external
            MapsSvc["Maps (react-native-maps)"]:::external
            FileSystem["File System (expo-file-system)"]:::external
            Sharing["Sharing (expo-sharing)"]:::external
        end

        subgraph "API Layer"
            direction TB
            SupabaseClient["src/supabaseClient.ts"]:::client
        end
    end

    %% Bottom Layer: Supabase Backend
    subgraph "Supabase Backend"
        direction TB
        AuthService["Supabase Auth"]:::backend
        Database["PostgreSQL Database"]:::database
        subgraph "Edge Functions"
            direction TB
            TransferFunction["transfer-funds"]:::edge
        end
    end

    %% Connections
    ExpoGo -->|"runs Mobile App"| LayoutApp
    AndroidNative -->|"runs Mobile App"| LayoutApp
    iOSNative -->|"runs Mobile App"| LayoutApp

    LayoutApp -->|"/routes load"| ExpoRouter
    ExpoRouter -->|guard| AccountContext
    AccountContext -->|reads token| SecureStore
    AccountContext -->|provides state| LayoutApp

    LayoutApp -->|renders pages| IndexPage
    LayoutApp -->|renders auth| AuthLogin
    LayoutApp -->|renders tabs| TabsLayout
    TabsLayout --> BillsPage
    TabsLayout --> CardsPage
    TabsLayout --> ChatbotPage
    TabsLayout --> HistoryPage
    TabsLayout --> LocatorPage
    TabsLayout --> MorePage
    TabsLayout --> TransferPage
    LayoutApp --> NotificationsPage
    LayoutApp --> TransactionDetails
    LayoutApp --> TransferConfirmation

    IndexPage -->|requests data| SupabaseClient
    BillsPage -->|fetch transactions| SupabaseClient
    HistoryPage -->|fetch history| SupabaseClient
    CardsPage -->|fetch cards| SupabaseClient
    LocatorPage -->|fetch branches| SupabaseClient
    TransferPage -->|invoke| SupabaseClient
    ChatbotPage -->|process| AccountContext

    SupabaseClient -->|auth calls| AuthService
    SupabaseClient -->|db reads| Database
    SupabaseClient -->|invoke function| TransferFunction
    TransferFunction -->|db writes| Database

    LocatorPage -->|get coords| LocationSvc
    LocatorPage -->|render pins| MapsSvc
    LayoutApp -->|store file| FileSystem
    LayoutApp -->|share| Sharing

    %% Click Events
    click LayoutApp "https://github.com/mizuch1/flousbank/blob/main/app/_layout.tsx"
    click IndexPage "https://github.com/mizuch1/flousbank/blob/main/app/index.tsx"
    click AuthLogin "https://github.com/mizuch1/flousbank/blob/main/app/(auth)/login.tsx"
    click TabsLayout "https://github.com/mizuch1/flousbank/blob/main/app/(tabs)/_layout.tsx"
    click BillsPage "https://github.com/mizuch1/flousbank/blob/main/app/(tabs)/bills.tsx"
    click CardsPage "https://github.com/mizuch1/flousbank/blob/main/app/(tabs)/cards.tsx"
    click ChatbotPage "https://github.com/mizuch1/flousbank/blob/main/app/(tabs)/chatbot.tsx"
    click HistoryPage "https://github.com/mizuch1/flousbank/blob/main/app/(tabs)/history.tsx"
    click LocatorPage "https://github.com/mizuch1/flousbank/blob/main/app/(tabs)/locator.tsx"
    click MorePage "https://github.com/mizuch1/flousbank/blob/main/app/(tabs)/more.tsx"
    click TransferPage "https://github.com/mizuch1/flousbank/blob/main/app/(tabs)/transfer.tsx"
    click NotificationsPage "https://github.com/mizuch1/flousbank/blob/main/app/notifications.tsx"
    click TransactionDetails "https://github.com/mizuch1/flousbank/blob/main/app/transaction-details.tsx"
    click TransferConfirmation "https://github.com/mizuch1/flousbank/blob/main/app/transfer-confirmation.tsx"
    click AccountContext "https://github.com/mizuch1/flousbank/blob/main/src/contexts/AccountContext.tsx"
    click SupabaseClient "https://github.com/mizuch1/flousbank/blob/main/src/supabaseClient.ts"
    click TransferFunction "https://github.com/mizuch1/flousbank/blob/main/supabase/functions/transfer-funds/index.ts"
    click AndroidNative "https://github.com/mizuch1/flousbank/tree/main/android/"
    click iOSNative "https://github.com/mizuch1/flousbank/blob/main/ios/mbkapp/Info.plist"

    %% Styles
    classDef client fill:#cfe2ff,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#d1e7dd,stroke:#0f5132,stroke-width:1px
    classDef database fill:#d1e7dd,stroke:#0f5132,stroke-width:2px,stroke-dasharray: 5 5
    classDef edge fill:#cff4fc,stroke:#055160,stroke-width:1px
    classDef external fill:#ffe5b4,stroke:#cc7000,stroke-width:1px
```
