# dwuangne/moneymind_be architecture

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

- Interactive diagram: https://gitdiagram.com/dwuangne/moneymind_be
- Repository: https://github.com/dwuangne/moneymind_be

## Overview

##### Main Components
- API Layer – MoneyMind_API:
- Contains controllers (e.g., ActivityController, AuthenticationsController, ChatController, etc.) that expose REST endpoints.
- Holds middlewares (e.g., ExceptionHandlerMiddleware, UserIdAuthorizationMiddleware) for cross-cutting concerns.
- Includes real-time communication components (e.g., ChatHub) and additional client components (e.g., NamedPipeClient) for specialized interactions.
- Provides configuration files (appsettings.json, launchSettings.json) and deployment profiles via PublishProfiles and ServiceDependencies.

- Business Logic Layer – MoneyMind_BLL:
- Comprises Data Transfer Objects (DTOs) organized by domain (Accounts, Activities, Chats, Emails, GoalItems, etc.) to communicate between layers.
- Hosts service implementations in the Services/Implementations folder that encapsulate business logic. Examples include ActivityService, ChatService, TransactionService, and more.
- Contains ML Model definitions (MLModels folder) and mapping profiles (using AutoMapper) which hint at advanced decision making or analytical logic.
- Stores email templates and utility classes (e.g., for JSON handling or intent recognition).

- Data Access Layer – MoneyMind_DAL:
- Implements repository patterns (both interfaces and their implementations) to encapsulate database interactions.
- Contains Entity Framework DB context classes (MoneyMindAuthDbContext.cs, MoneyMindDbContext.cs) and entity definitions defining the domain for persistence.
- Manages database migrations and configurations which ensure the database schema stays in sync.

##### Representing Relationships and Interactions
- The API controllers receive HTTP requests, then call upon respective services in the BLL to process business logic.
- Business services, in turn, interact with the DAL repositories to fetch or update data in the underlying database.
- The communication with realtime components like ChatHub and NamedPipeClient should be shown as parallel components interfacing with the API layer.
- External integration points such as GoogleSheets (via GoogleSheetSyncController and corresponding BLL services) and Firebase (firebase-adminsdk.json) should also be represented.

##### Architectural Patterns and Design Principles
- Layered Architecture: Show the clear separation among API (presentation), BLL (business rules and logic), and DAL (data persistence).
- Use of Repository and Service Patterns: Emphasize that controllers never directly access the database, but instead call services which use repositories.
- Middleware Usage: Illustrate that cross-cutting concerns (error handling, authorization) are managed by middleware components.
- Modularization: Highlight that each feature (e.g., transactions, users, notifications, chat) resides in its own dedicated submodule.
- Integration of Machine Learning Models: Include a note for ML components, showing that the BLL has dedicated ML models used for prediction and intent detection.

##### Final Touches
- Components are clearly labeled.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer (MoneyMind_API)"
        API_Controllers("Controllers")
        API_Middlewares("Middlewares")
        API_ChatHub("ChatHub")
        API_NamedPipe("NamedPipeClient")
        API_appsettings("appsettings.json")
        API_launchSettings("launchSettings.json")
        API_PublishProfiles("PublishProfiles")
        API_ServiceDependencies("ServiceDependencies")
        API_JwtHelper("JWT Helper")
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer (MoneyMind_BLL)"
        BLL_DTOs("DTOs")
        BLL_Services("Services")
        BLL_ServiceInterfaces("Service Interfaces")
        BLL_MLModels("ML Models")
        BLL_MappingProfiles("Mapping Profiles")
        BLL_EmailTemplates("Email Templates")
        BLL_Utils("Utility Classes")
    end

    %% Data Access Layer
    subgraph "Data Access Layer (MoneyMind_DAL)"
        DAL_DBContexts("DB Contexts")
        DAL_Entities("Entities")
        DAL_Migrations("Migrations")
        DAL_GenericRepoImpl("Generic Repository Impl")
        DAL_GenericRepoInterface("Generic Repository Interface")
        DAL_RepoImpl("Specific Repository Implementations")
        DAL_RepoInterfaces("Repository Interfaces")
    end

    %% External Integrations
    subgraph "External Integrations"
        Ext_GoogleSheets("GoogleSheets")
        Ext_Firebase("Firebase")
    end

    %% Relationships
    API_Middlewares -->|"pre-processes"| API_Controllers
    API_Controllers -->|"calls"| BLL_Services
    BLL_Services -->|"uses"| DAL_RepoImpl
    API_Controllers -->|"triggers"| Ext_GoogleSheets
    API_Controllers -->|"triggers"| Ext_Firebase

    %% Classes
    class API_Controllers,API_Middlewares,API_ChatHub,API_NamedPipe,API_appsettings,API_launchSettings,API_PublishProfiles,API_ServiceDependencies,API_JwtHelper api
    class BLL_DTOs,BLL_Services,BLL_ServiceInterfaces,BLL_MLModels,BLL_MappingProfiles,BLL_EmailTemplates,BLL_Utils bll
    class DAL_DBContexts,DAL_Entities,DAL_Migrations,DAL_GenericRepoImpl,DAL_GenericRepoInterface,DAL_RepoImpl,DAL_RepoInterfaces dal
    class Ext_GoogleSheets,Ext_Firebase external

    %% Click Events for API Layer
    click API_Controllers "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_API/Controllers"
    click API_Middlewares "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_API/Middlewares"
    click API_ChatHub "https://github.com/dwuangne/moneymind_be/blob/main/MoneyMind_API/Hubs/ChatHub.cs"
    click API_NamedPipe "https://github.com/dwuangne/moneymind_be/blob/main/MoneyMind_API/Client/NamedPipeClient.cs"
    click API_appsettings "https://github.com/dwuangne/moneymind_be/blob/main/MoneyMind_API/appsettings.json"
    click API_launchSettings "https://github.com/dwuangne/moneymind_be/blob/main/MoneyMind_API/launchSettings.json"
    click API_PublishProfiles "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_API/Properties/PublishProfiles"
    click API_ServiceDependencies "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_API/Properties/ServiceDependencies"
    click API_JwtHelper "https://github.com/dwuangne/moneymind_be/blob/main/MoneyMind_API/Helpers/JwtHelper.cs"

    %% Click Events for Business Logic Layer
    click BLL_DTOs "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_BLL/DTOs"
    click BLL_Services "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_BLL/Services/Implementations"
    click BLL_ServiceInterfaces "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_BLL/Services/Interfaces"
    click BLL_MLModels "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_BLL/MLModels"
    click BLL_MappingProfiles "https://github.com/dwuangne/moneymind_be/blob/main/MoneyMind_BLL/Mapping/AutoMapperProfiles.cs"
    click BLL_EmailTemplates "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_BLL/Templates/EmailTemplate"
    click BLL_Utils "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_BLL/Utils"

    %% Click Events for Data Access Layer
    click DAL_DBContexts "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_DAL/DBContexts"
    click DAL_Entities "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_DAL/Entities"
    click DAL_Migrations "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_DAL/Migrations"
    click DAL_GenericRepoImpl "https://github.com/dwuangne/moneymind_be/blob/main/MoneyMind_DAL/Repositories/GenericRepository.cs"
    click DAL_GenericRepoInterface "https://github.com/dwuangne/moneymind_be/blob/main/MoneyMind_DAL/Repositories/IGenericRepository.cs"
    click DAL_RepoImpl "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_DAL/Repositories/Implementations"
    click DAL_RepoInterfaces "https://github.com/dwuangne/moneymind_be/tree/main/MoneyMind_DAL/Repositories/Interfaces"

    %% Style Definitions
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef bll fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef dal fill:#FFD580,stroke:#000,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
