# cuonvc/ex-money-backend architecture

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

- Interactive diagram: https://gitdiagram.com/cuonvc/ex-money-backend
- Repository: https://github.com/cuonvc/ex-money-backend

## Overview

##### Main Components
- Mobile Client (Flutter): Although external, it’s important to note the mobile app (referenced in the README) which interacts with this backend.
- API Gateway / Front Controller: The Spring Boot application (ExmoneyApplication) acts as the entry-point. It routes calls through REST controllers such as AuthController, ExpenseController, WalletController, etc.
- Service Layer: Group the services (ExpenseService, UserService, WalletService, etc.) along with their implementations. They encapsulate the business logic.
- Persistence/Repository Layer: Show repositories (e.g., ExpenseRepository, UserRepository) that interact with the PostgreSQL database alongside JPA entities. Optionally highlight Redis if caching is in use.
- Worker/Task Scheduler: Include components like ExpenseSchedulerExecuteWorker and ExpenseSchedulerResetWorker for background processing.
- External Services/Integrations: Represent integrations with third-party services (Firebase, Google OAuth 2.0) and any email service.

##### Relationships and Interactions
- That the Security components (JWT authentication and filters) are cross-cutting, so link them to the API gateway entry point and service layers.

##### Architectural Patterns
- Layered Architecture: Clearly separate the presentation (controllers), business logic (services), and data access (repositories) layers.
- Use of Dependency Injection (as seen in the configuration classes) and a service-oriented approach.
- Security aspects (JWT-based authentication via JwtAuthenticationFilter and JwtTokenProvider) are implemented as cross-cutting concerns.
- The system utilizes micro-level scheduling for background processing (TaskSchedulerService and associated worker classes).

##### Technologies/Frameworks
- Java Spring Boot (Main Framework)
- Spring Data JPA (for ORM capabilities)
- PostgreSQL (database) and Redis (caching, if applicable)
- Spring Security with JWT for authentication
- Docker (for containerization) and associated deployment tooling (docker-compose, Nginx, Ngrok)
- Firebase and OAuth 2.0 for third-party authentication and integration

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        M["Mobile Client (Flutter)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        A["Exmoney API Gateway"]:::api
        C["REST Controllers"]:::controller
        SC["Security Module"]:::security
        CONF["Configuration Components"]:::config

        subgraph "Business Logic"
            SL["Service Layer"]:::service
            SIMPL["Service Implementation"]:::service
            SL --> SIMPL
        end

        subgraph "Persistence Layer"
            R["Repositories"]:::persistence
            E["JPA Entities"]:::persistence
        end

        D["PostgreSQL Database"]:::db
        R --> D
        RC["Redis Cache"]:::db

        subgraph "External Integrations"
            F["Firebase Integration"]:::external
            OC["OAuth Controller"]:::external
            OS["OAuth Service"]:::external
            ES["Email Service"]:::external
            ESI["Email Service Impl"]:::external
        end

        W["Worker/Task Scheduler"]:::worker
    end

    %% Deployment Infrastructure
    subgraph "Deployment Infrastructure"
        DF["Dockerfile"]:::deployment
        DC["docker-compose"]:::deployment
        SS["Server Scripts"]:::deployment
    end

    %% Data Flow Connections
    M -->|"HTTP"| A
    A -->|"routes to"| C
    A ---|"configured by"| CONF
    A ---|"filtered by"| SC
    C -->|"delegates to"| SL
    SL -->|"calls"| SIMPL
    SIMPL -->|"persists data via"| R
    SIMPL -->|"uses caching"| RC
    R -->|"reads/writes"| D
    SIMPL -->|"triggers"| W
    SIMPL -->|"integrates with"| F
    SIMPL -->|"integrates with"| OC
    SIMPL -->|"integrates with"| OS
    SIMPL -->|"integrates with"| ES
    SIMPL -->|"integrates with"| ESI

    %% Click Events
    click A "https://github.com/cuonvc/ex-money-backend/blob/develop/src/main/java/com/exmoney/ExmoneyApplication.java"
    click C "https://github.com/cuonvc/ex-money-backend/tree/develop/src/main/java/com/exmoney/controller"
    click SL "https://github.com/cuonvc/ex-money-backend/tree/develop/src/main/java/com/exmoney/service"
    click SIMPL "https://github.com/cuonvc/ex-money-backend/tree/develop/src/main/java/com/exmoney/service/impl"
    click R "https://github.com/cuonvc/ex-money-backend/tree/develop/src/main/java/com/exmoney/repository"
    click E "https://github.com/cuonvc/ex-money-backend/tree/develop/src/main/java/com/exmoney/entity"
    click CONF "https://github.com/cuonvc/ex-money-backend/tree/develop/src/main/java/com/exmoney/config"
    click SC "https://github.com/cuonvc/ex-money-backend/tree/develop/src/main/java/com/exmoney/security"
    click W "https://github.com/cuonvc/ex-money-backend/tree/develop/src/main/java/com/exmoney/worker"
    click F "https://github.com/cuonvc/ex-money-backend/blob/develop/src/main/java/com/exmoney/config/FirebaseConfiguration.java"
    click OC "https://github.com/cuonvc/ex-money-backend/blob/develop/src/main/java/com/exmoney/controller/OAuthController.java"
    click OS "https://github.com/cuonvc/ex-money-backend/blob/develop/src/main/java/com/exmoney/service/OAuthService.java"
    click ES "https://github.com/cuonvc/ex-money-backend/blob/develop/src/main/java/com/exmoney/service/EmailService.java"
    click ESI "https://github.com/cuonvc/ex-money-backend/blob/develop/src/main/java/com/exmoney/service/impl/EmailServiceImpl.java"
    click DF "https://github.com/cuonvc/ex-money-backend/tree/develop/Dockerfile"
    click DC "https://github.com/cuonvc/ex-money-backend/blob/develop/docker-compose.yml"
    click SS "https://github.com/cuonvc/ex-money-backend/tree/develop/server"

    %% Styles
    classDef frontend fill:#a2d9ff,stroke:#1f78b4,stroke-width:2px;
    classDef api fill:#fdebd0,stroke:#e67e22,stroke-width:2px;
    classDef controller fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef service fill:#fcf3cf,stroke:#f1c40f,stroke-width:2px;
    classDef persistence fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;
    classDef db fill:#d6eaf8,stroke:#3498db,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external fill:#e8daef,stroke:#8e44ad,stroke-width:2px;
    classDef config fill:#d5dbdb,stroke:#7f8c8d,stroke-width:2px;
    classDef security fill:#f9e79f,stroke:#f39c12,stroke-width:2px;
    classDef worker fill:#d4efdf,stroke:#16a085,stroke-width:2px;
    classDef deployment fill:#f5cba7,stroke:#e67e22,stroke-width:2px;
```
