# besimgurbuz/mfloww architecture

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

- Interactive diagram: https://gitdiagram.com/besimgurbuz/mfloww
- Repository: https://github.com/besimgurbuz/mfloww

## Overview

##### Main Components
- Frontend Client: Represented by the Next.js “app” directory. Distinguish primary pages (e.g., landing page, sign-in, beta, dashboard, settings) along with shared layout and contextual providers for themes, authentication, and user context.
- Server/API Endpoints: Group the API routes found under src/app/api. These endpoints handle various resources and processes:
- Beta access and validation (src/app/api/beta)
- Cron tasks (src/app/api/cron)
- Exchange rates (src/app/api/rates)
- User authentication and token verification (src/app/api/sign-in, verify-token)
- Data synchronization (src/app/api/sync) and its status
- User management (src/app/api/user)
- Business Logic & Integrations: Located in src/lib, these modules contain:
- Firebase integration (src/lib/firebase.ts)
- Local DB handling (src/lib/local-db)
- External service clients for exchange rates (src/lib/server/exchange-rates/*)
- Other utility functions (src/lib/utils.ts, src/lib/transaction)
- Shared UI Components & Design System: Found under the src/components directory. These provide reusable widgets (buttons, dialogs, tables, etc.), dashboard-specific components (charts, cards, transaction menus), and layout elements.

##### Relationships & Interactions
- The Frontend Client interacts with the API endpoints through HTTP requests (Next.js server-side functions are used to manage these interactions, often powered by server components).
- UI components (such as sign-in forms or dashboard widgets) are composed to create pages that in turn invoke API endpoints or use local libraries to fetch and display data.
- Shared libraries within src/lib are called by both client and server code to perform tasks like retrieving exchange rates (by invoking external services), processing local data, and applying authentication and cryptographic functionality.
- There is a clear separation between UI/presentation, API routes (serverless functions on Vercel), and backend logic (in src/lib), representing a clean full-stack architecture.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The clear division into UI, API, and domain logic ensures each layer maintains its responsibility.
- Modular Design: Components, hooks, and utility libraries are implemented as separate modules that can be reused across pages.
- Serverless/API Routes: The use of Next.js API routes for business logic encapsulates server-side functions, making the architecture scalable (suitable for deployment on Vercel’s serverless architecture).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Client Subgraph
    subgraph "Frontend Client"
        FE("Next.js Frontend"):::frontend
        FE1("Landing Page"):::frontend
        FE2("Sign-In Page"):::frontend
        FE3("Beta Access Page"):::frontend
        FE4("Dashboard Page"):::frontend
        FE5("Settings Page"):::frontend
    end

    %% Server/API Endpoints Subgraph
    subgraph "Server/API Endpoints"
        API_Beta("API - Beta Access"):::api
        API_Validate("API - Beta Validate"):::api
        API_Cron("API - Cron Tasks"):::api
        API_Rates("API - Exchange Rates"):::api
        API_SignIn("API - Sign-In"):::api
        API_Verify("API - Verify Token"):::api
        API_Sync("API - Data Sync"):::api
        API_SyncStatus("API - Sync Status"):::api
        API_User("API - User Management"):::api
    end

    %% Business Logic & Integrations Subgraph
    subgraph "Business Logic & Integrations"
        BL_Firebase("Firebase Integration"):::logic
        BL_LocalDB("Local DB Handling"):::logic
        BL_ExRate("Exchange Rate Clients"):::logic
        BL_Utils("Utility Functions & Transaction"):::logic
    end

    %% Shared UI Components & Design System Subgraph
    subgraph "Shared UI Components & Design System"
        UI_Common("Common UI Components"):::ui
        UI_Dashboard("Dashboard Components"):::ui
        UI_SignIn("Sign-In Form"):::ui
    end

    %% Configuration & Infrastructure Subgraph
    subgraph "Configuration & Infrastructure"
        CFG_Next("Next.js Config"):::config
        CFG_TS("TypeScript Config"):::config
        CFG_Tailwind("Tailwind CSS Config"):::config
        CFG_Vercel("Vercel Deployment Config"):::config
    end

    %% External Services Node
    EX_Rate("Exchange Rate API"):::external

    %% Relationships
    %% Frontend calling API Endpoints
    FE -->|"HTTP"| API_SignIn
    FE -->|"HTTP"| API_Beta
    FE -->|"HTTP"| API_Rates
    FE -->|"HTTP"| API_Sync

    %% API Endpoints interacting with Business Logic
    API_SignIn -->|"process"| BL_Firebase
    API_Verify -->|"verify"| BL_Firebase
    API_Beta -->|"validate"| BL_Utils
    API_Validate -->|"validateBeta"| BL_Utils
    API_Cron -->|"schedule"| BL_Utils
    API_Rates -->|"fetchRates"| BL_ExRate
    API_Sync -->|"syncData"| BL_LocalDB
    API_SyncStatus -->|"statusCheck"| BL_LocalDB
    API_User -->|"userManage"| BL_LocalDB

    %% Frontend using Shared UI Components
    FE1 -->|"renders"| UI_Common
    FE2 -->|"renders"| UI_SignIn
    FE4 -->|"renders"| UI_Dashboard

    %% Both Frontend and API also leverage Business Logic
    FE -->|"calls"| BL_Utils

    %% Business Logic interacting with External Exchange Rate API
    BL_ExRate -->|"request"| EX_Rate

    %% Configuration supporting Frontend, API and Business Logic (dashed links)
    CFG_Next -.-> FE
    CFG_TS -.-> FE
    CFG_Tailwind -.-> FE
    CFG_Vercel -.-> API_SignIn
    CFG_Vercel -.-> API_Beta
    CFG_Vercel -.-> API_Rates
    CFG_Vercel -.-> API_Sync

    %% Click Events for Frontend Client
    click FE "https://github.com/besimgurbuz/mfloww/tree/main/src/app"
    click FE1 "https://github.com/besimgurbuz/mfloww/blob/main/src/app/page.tsx"
    click FE2 "https://github.com/besimgurbuz/mfloww/blob/main/src/app/sign-in/page.tsx"
    click FE3 "https://github.com/besimgurbuz/mfloww/blob/main/src/app/beta/page.tsx"
    click FE4 "https://github.com/besimgurbuz/mfloww/blob/main/src/app/dashboard/page.tsx"
    click FE5 "https://github.com/besimgurbuz/mfloww/blob/main/src/app/settings/page.tsx"

    %% Click Events for Server/API Endpoints
    click API_Beta "https://github.com/besimgurbuz/mfloww/blob/main/src/app/api/beta/route.ts"
    click API_Validate "https://github.com/besimgurbuz/mfloww/blob/main/src/app/api/beta/validate/route.ts"
    click API_Cron "https://github.com/besimgurbuz/mfloww/blob/main/src/app/api/cron/route.ts"
    click API_Rates "https://github.com/besimgurbuz/mfloww/blob/main/src/app/api/rates/route.ts"
    click API_SignIn "https://github.com/besimgurbuz/mfloww/blob/main/src/app/api/sign-in/route.ts"
    click API_Verify "https://github.com/besimgurbuz/mfloww/blob/main/src/app/api/verify-token/route.ts"
    click API_Sync "https://github.com/besimgurbuz/mfloww/blob/main/src/app/api/sync/route.ts"
    click API_SyncStatus "https://github.com/besimgurbuz/mfloww/blob/main/src/app/api/sync/status/route.ts"
    click API_User "https://github.com/besimgurbuz/mfloww/blob/main/src/app/api/user/route.ts"

    %% Click Events for Business Logic & Integrations
    click BL_Firebase "https://github.com/besimgurbuz/mfloww/blob/main/src/lib/firebase.ts"
    click BL_LocalDB "https://github.com/besimgurbuz/mfloww/tree/main/src/lib/local-db"
    click BL_ExRate "https://github.com/besimgurbuz/mfloww/tree/main/src/lib/server/exchange-rates"
    click BL_Utils "https://github.com/besimgurbuz/mfloww/blob/main/src/lib/utils.ts"

    %% Click Events for Shared UI Components
    click UI_Common "https://github.com/besimgurbuz/mfloww/tree/main/src/components/ui"
    click UI_Dashboard "https://github.com/besimgurbuz/mfloww/tree/main/src/components/dashboard"
    click UI_SignIn "https://github.com/besimgurbuz/mfloww/blob/main/src/components/sign-in/sign-in-form.tsx"

    %% Click Events for Configuration & Infrastructure
    click CFG_Next "https://github.com/besimgurbuz/mfloww/blob/main/next.config.js"
    click CFG_TS "https://github.com/besimgurbuz/mfloww/blob/main/tsconfig.json"
    click CFG_Tailwind "https://github.com/besimgurbuz/mfloww/blob/main/tailwind.config.ts"
    click CFG_Vercel "https://github.com/besimgurbuz/mfloww/blob/main/vercel.json"

    %% Styles
    classDef frontend fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef api fill:#aed6f1,stroke:#333,stroke-width:2px;
    classDef logic fill:#a9dfbf,stroke:#333,stroke-width:2px;
    classDef ui fill:#f5b7b1,stroke:#333,stroke-width:2px;
    classDef config fill:#d7bde2,stroke:#333,stroke-width:2px;
    classDef external fill:#fcf3cf,stroke:#333,stroke-width:2px;
```
