# cc711612/wallet architecture

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

- Interactive diagram: https://gitdiagram.com/cc711612/wallet
- Repository: https://github.com/cc711612/wallet

## Overview

Based on our analysis of the file tree and the README, this project is a Laravel-based full-stack web application designed as a “分帳” (cost-splitting) tool. It provides a set of API endpoints and web pages for managing, visualizing, and splitting expenses. The project uses the standard Laravel MVC structure with clearly separated components, including controllers for APIs and web display, business logic in services and jobs, and data models with their corresponding database migrations and seeders. It also includes integrations with external services such as Line notifications and a Gemini service.

##### Main Components
a. Frontend Client:
- Web assets stored in the “public” and “resources” directories (such as JavaScript, CSS, and Blade templates). These represent the user interface that displays the expense splitting screens.
b. API Layer / Web Controllers:
- Controllers present under "app/Http/Controllers" (separated into API controllers for Auth, Devices, Wallets, Users, etc.) provide the RESTful interface.
c. Business Logic & Service Layer:
- Business rules are implemented via Service classes in “app/Services”, “app/Models/*/Databases/Services”, and traits in “app/Traits”. Also note the Commands and Jobs (for tasks like wallet creation, exchange rate updates, notifications).
d. Domain/Model Layer:
- Eloquent models in “app/Models”, along with corresponding database migration scripts in the “database/migrations” folder. These represent entities such as Wallets, Users, Wallet Details, Categories, and Socials.
e. External Integrations:
- Modules like Gemini (found in “app/Facades/Gemini.php” and “app/Services/GeminiService.php”) and Line notifications (“app/Channels/LineNotifyChannel.php” and associated Jobs/Notifications) tie the application to external systems.
f. Infrastructure & Deployment:
- The “deployment” folders for both development and production along with Docker-compose files, Supervisor, and Nginx configuration files indicate containerization and deployment strategies.
g. Additional Technical Components:
- Middleware (Authentication, CSRF, API validations) in “app/Http/Middleware” for request filtering.
- Command Line interfaces and Scheduling (found under “app/Console/Commands”).
- Testing components in “tests” for both unit and feature tests ensure quality.

##### Relationships and Flows
- The frontend sends HTTP requests (AJAX or form submissions) to the API endpoints exposed by the controllers.
- Controllers interact with business logic (services, requesters, validators) to handle user requests.
- Business logic interacts with the database through repositories and model methods (using Eloquent).
- Jobs and commands are used for asynchronous processing, background tasks, and scheduled operations (for notifications, wallet detail calculations, etc.).
- Certain services (e.g., LineNotify and Gemini) communicate with external APIs to send notifications or process external integrations.
- Middleware guards the routes and performs pre/post processing of incoming and outgoing requests.

##### Important Architectural Patterns & Design Principles
- MVC Pattern: The separation of controllers (handling HTTP requests), models (database entities), and views (frontend presentation).
- Layered Architecture: Distinct separation between the UI (Frontend), Application Layer (Controllers & Middleware), Domain Logic (Services, Jobs, Models), and Infrastructure (Database, External APIs).
- Use of Service and Repository patterns: Business logic is encapsulated in dedicated service classes while repository patterns standardize database interactions.
- Asynchronous Processing: Use of Jobs/Commands for tasks that do not need immediate completion.
- Modularity and Extensibility: Multiple “Concerns” and “Traits” indicate abstraction and code reuse to keep components decoupled.

##### Final Checklist
- Be very detailed – capture both the logical (MVC, service, repository) and physical (deployment, Docker, and server configurations) architecture.
- Distinguish between synchronous user interactions and background processing (jobs/commands).
- Do not oversimplify: separate the components as much as possible for clarity, ensuring that the various layers (presentation, application, infrastructure) are all represented.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        F0["Public Assets"]:::frontend
        F1["Resource Views & Assets"]:::frontend
        F0 --> F1
    end

    %% Middleware Layer
    B["Middleware (app/Http/Middleware)"]:::middleware

    %% API Layer / Controllers
    C["Controllers (app/Http/Controllers)"]:::controller

    %% Business Logic & Service Layer
    subgraph "Business Logic Layer"
        D1["Services (app/Services)"]:::service
        D2["Jobs (app/Jobs)"]:::service
        D3["Traits/Concerns (app/Traits & app/Concerns)"]:::service
        D1 --> D2
        D2 --> D3
    end

    %% Domain / Model Layer
    E["Models & Database (app/Models, migrations, seeders)"]:::database

    %% External Integrations
    subgraph "External Integrations"
        F3["Gemini Facade"]:::external
        F4["Gemini Service"]:::external
        G1["Line Notify Channel"]:::external
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        H1["Development Deployment"]:::infrastructure
        H2["Production Deployment"]:::infrastructure
    end

    %% Command Line Interfaces & Scheduling
    I["CLI & Scheduling (app/Console/Commands)"]:::cli

    %% Testing Components
    J["Testing (tests)"]:::testing

    %% Flow Connections
    F1 -->|"HTTP_request"| B
    B -->|"Routes_to"| C
    C -->|"Invokes"| D1
    D3 -->|"DB_operations"| E
    D1 -->|"calls"| F3
    D1 -->|"calls"| F4
    D2 -->|"triggers"| G1
    D1 -->|"schedules"| I
    J -->|"tests"| D1

    %% Deployment Hosts Connections
    H1 ---|"hosts"| C
    H1 ---|"hosts"| D1
    H1 ---|"hosts"| I
    H1 ---|"stores"| E
    H2 ---|"hosts"| C
    H2 ---|"hosts"| D1
    H2 ---|"hosts"| I
    H2 ---|"stores"| E

    %% Click Events
    click F0 "https://github.com/cc711612/wallet/tree/master/public"
    click F1 "https://github.com/cc711612/wallet/tree/master/resources"
    click B "https://github.com/cc711612/wallet/tree/master/app/Http/Middleware"
    click C "https://github.com/cc711612/wallet/tree/master/app/Http/Controllers"
    click D1 "https://github.com/cc711612/wallet/tree/master/app/Services"
    click D2 "https://github.com/cc711612/wallet/tree/master/app/Jobs"
    click D3 "https://github.com/cc711612/wallet/tree/master/app/Traits"
    click E "https://github.com/cc711612/wallet/tree/master/app/Models"
    click F3 "https://github.com/cc711612/wallet/blob/master/app/Facades/Gemini.php"
    click F4 "https://github.com/cc711612/wallet/blob/master/app/Services/GeminiService.php"
    click G1 "https://github.com/cc711612/wallet/blob/master/app/Channels/LineNotifyChannel.php"
    click H1 "https://github.com/cc711612/wallet/tree/master/deployment/develop"
    click H2 "https://github.com/cc711612/wallet/tree/master/deployment/production"
    click I "https://github.com/cc711612/wallet/tree/master/app/Console/Commands"
    click J "https://github.com/cc711612/wallet/tree/master/tests"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,color:#1B2631;
    classDef middleware fill:#FEF5E7,stroke:#D68910,color:#784212;
    classDef controller fill:#FDEBD0,stroke:#D35400,color:#873600;
    classDef service fill:#D5F5E3,stroke:#27AE60,color:#145A32;
    classDef database fill:#F9E79F,stroke:#B7950B,color:#7D6608;
    classDef external fill:#FADBD8,stroke:#C0392B,color:#641E16;
    classDef infrastructure fill:#D6EAF8,stroke:#2874A6,color:#154360;
    classDef cli fill:#E8DAEF,stroke:#8E44AD,color:#4A235A;
    classDef testing fill:#D1F2EB,stroke:#17A589,color:#0E6251;
```
