# aschnarre1/bankapp architecture

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

- Interactive diagram: https://gitdiagram.com/aschnarre1/bankapp
- Repository: https://github.com/aschnarre1/bankapp

## Overview

##### Main Components
- App.js as the Central Hub: This file acts as the central entry point (or “controller for the entire project”) and wires together the other components (middleware, routes, controllers, and models). Represent this as the core of your system.
- Cloudinary Module: Since image uploading (checks and IDs) is handled here, list “Cloudinary” as an external service module. Indicate that it configures API keys, allowed formats, and storage details in the cloud.
- Controllers: Include separate nodes for accountRoute, request, and users controllers. They handle business logic, data encryption, error handling, and interact with models and middleware.
- Models: Represent the MongoDB schemas for Accounts, Users, and UserRequests. These nodes handle data structure and database interactions.
- Routes: This component organizes URL paths and ties them to the corresponding controllers. Note that routes also enforce asynchronous handling and invoke middleware validations.
- Middleware: Include a node representing functions that check conditions (e.g., authentication, authorization) before the routes and controllers are executed.
- Utils: A smaller component that encompasses error handling and asynchronous utility functions (ExpressError, catchAsync).
- Views: Represent the frontend portion that is built using EJS templates. Subdivide into:
- Account Views: For logged-in user pages related to account functionalities (e.g., admin views, requests, transfers, etc.).
- User Views: For guest/user-facing pages such as login, registration, contact us, etc.
- Layouts and Partials: These components standardize common UI elements like navbar, footer, flash messages, and are reused across EJS pages.
- Public Assets: A container for static assets like CSS files, client-side JavaScript (form validation), images, etc. This should be represented as resources that the views and the browser consume.
- Schemas & Validation: Include a node for JOI validation (schemas.js) and the custom validation/sanitization functionality to prevent insecure data.
- External Dependencies: Optionally, note that package.json and node_modules indicate reliance on npm packages, such as Express, Node-Cloudinary, Bootstrap, etc.

##### Relationships and Interactions
- Data Flow (User Registration as an Example):
– The client accesses the homepage/views through a browser.
– Navigation triggers routes (e.g., /register) which then invoke the corresponding middleware (e.g., validate user input) before sending the data to the controller.
– Controllers then process, format, and encrypt user data before sending it to the Models to store into the MongoDB database.
– The controller might also interact with Cloudinary to upload required images.
– Responses, confirmations, or error pages are rendered using the EJS views.
– Request flow from the client (Public/Browser) to Routes, then to Middleware, Controllers, and Models.
– Response flow in the reverse direction – from Models back through Controllers and Routes, then rendered via Views to the client.
– Error routes flowing to a common error view template.

##### Important Architectural Patterns or Design Principles
- Full-stack Separation: Mark clear separation of concerns between frontend (views, public assets), backend (controllers, routes, middleware), and database (models).
- MVC Pattern: Controllers, Models, and Views each serve their own clear purpose aligning with the Model-View-Controller paradigm.
- Security and Data Validation: Emphasize the use of middleware for authentication and the incorporation of JOI and custom validations to secure data inputs.
- External Service Integration: Demonstrate how Cloudinary is integrated to handle image uploads as an external service.
- Modular Organization: The file structure reflects low coupling and high cohesion by separating functionality into discrete directories.

##### Relevant Technologies, Frameworks, and Libraries
- Node.js, Express.js, and MongoDB are the backbone of the application.
- EJS for templating, CSS and Bootstrap for responsive design.
- Cloudinary (using node-cloudinary package) for media storage.
- JOI for data validation/sanitization.
- Custom middleware and utility functions for error handling and async operations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients and Entry Point
    Client["Client (Browser)"]:::frontend
    AppCentralHub["App.js - Central Hub"]:::backend

    %% External Service
    Cloudinary["Cloudinary Module"]:::external

    %% Backend Subgraphs
    subgraph "Backend Services"
        %% Routes Subgraph
        subgraph "Routes"
            AccountRoutes["AccountRoutes"]:::backend
            RequestRoutes["RequestRoutes"]:::backend
            UsersRoutes["UsersRoutes"]:::backend
        end

        Middleware["Middleware"]:::backend

        %% Controllers Subgraph
        subgraph "Controllers"
            AccountController["AccountController"]:::backend
            RequestController["RequestController"]:::backend
            UsersController["UsersController"]:::backend
        end

        %% Models Subgraph
        subgraph "Models"
            AccountsModel["AccountsModel"]:::backend
            UsersModel["UsersModel"]:::backend
            UserRequestsModel["UserRequestsModel"]:::backend
        end

        %% Utilities Subgraph
        subgraph "Utilities & Validation"
            ExpressError["ExpressError"]:::util
            catchAsync["catchAsync"]:::util
            Schemas["Schemas & Validation"]:::util
        end
    end

    %% Frontend Subgraphs
    subgraph "Frontend Presentation"
        subgraph "Views"
            AccountViews["Account Views"]:::frontend
            UserViews["User Views"]:::frontend
            LayoutsAndPartials["Layouts & Partials"]:::frontend
            GeneralViews["General Views"]:::frontend
        end
        PublicAssets["Public Assets"]:::frontend
    end

    %% Flow Connections
    Client -->|"Accesses"| AppCentralHub
    AppCentralHub -->|"Initializes"| AccountRoutes
    AppCentralHub -->|"Initializes"| RequestRoutes
    AppCentralHub -->|"Initializes"| UsersRoutes

    %% Routes to Middleware
    AccountRoutes -->|"validate"| Middleware
    RequestRoutes -->|"validate"| Middleware
    UsersRoutes -->|"validate"| Middleware

    %% Middleware to Controllers
    Middleware -->|"process"| AccountController
    Middleware -->|"process"| RequestController
    Middleware -->|"process"| UsersController
    Middleware -->|"validateData"| Schemas

    %% Controllers to Models (Data Storage)
    AccountController -->|"encrypt&store"| AccountsModel
    UsersController -->|"encrypt&store"| UsersModel
    RequestController -->|"encrypt&store"| UserRequestsModel

    %% Models return data to Controllers
    AccountsModel -->|"responseData"| AccountController
    UsersModel -->|"responseData"| UsersController
    UserRequestsModel -->|"responseData"| RequestController

    %% Controllers back to Routes (Sending Response)
    AccountController -->|"sendResponse"| AccountRoutes
    RequestController -->|"sendResponse"| RequestRoutes
    UsersController -->|"sendResponse"| UsersRoutes

    %% Routes render Views
    AccountRoutes -->|"renderHTML"| AccountViews
    UsersRoutes -->|"renderHTML"| UserViews
    RequestRoutes -->|"renderHTML"| GeneralViews

    %% Views use Public Assets
    PublicAssets -->|"serveStatic"| AccountViews
    PublicAssets -->|"serveStatic"| UserViews
    PublicAssets -->|"serveStatic"| GeneralViews
    PublicAssets -->|"serveStatic"| LayoutsAndPartials

    %% Views render to Client
    AccountViews -->|"displayed"| Client
    UserViews -->|"displayed"| Client
    GeneralViews -->|"displayed"| Client
    LayoutsAndPartials -->|"partOfView"| Client

    %% Controllers interacting with External Service
    AccountController -- "uploadImage" --> Cloudinary

    %% Controllers utilizing Utilities
    AccountController -->|"errorHandling"| ExpressError
    RequestController -->|"errorHandling"| ExpressError
    UsersController -->|"errorHandling"| ExpressError
    AccountController -->|"asyncHandling"| catchAsync
    RequestController -->|"asyncHandling"| catchAsync
    UsersController -->|"asyncHandling"| catchAsync

    %% Click Events
    click AppCentralHub "https://github.com/aschnarre1/bankapp/blob/master/app.js"
    click Cloudinary "https://github.com/aschnarre1/bankapp/blob/master/cloudinary/index.js"
    click AccountController "https://github.com/aschnarre1/bankapp/blob/master/controllers/accountRoute.js"
    click RequestController "https://github.com/aschnarre1/bankapp/blob/master/controllers/request.js"
    click UsersController "https://github.com/aschnarre1/bankapp/blob/master/controllers/users.js"
    click AccountsModel "https://github.com/aschnarre1/bankapp/blob/master/models/accounts.js"
    click UsersModel "https://github.com/aschnarre1/bankapp/blob/master/models/user.js"
    click UserRequestsModel "https://github.com/aschnarre1/bankapp/blob/master/models/userRequest.js"
    click AccountRoutes "https://github.com/aschnarre1/bankapp/blob/master/routes/accountRoute.js"
    click RequestRoutes "https://github.com/aschnarre1/bankapp/blob/master/routes/request.js"
    click UsersRoutes "https://github.com/aschnarre1/bankapp/blob/master/routes/users.js"
    click Middleware "https://github.com/aschnarre1/bankapp/blob/master/middleware.js"
    click ExpressError "https://github.com/aschnarre1/bankapp/blob/master/utils/ExpressError.js"
    click catchAsync "https://github.com/aschnarre1/bankapp/blob/master/utils/catchAsync.js"
    click AccountViews "https://github.com/aschnarre1/bankapp/tree/master/views/accountViews/"
    click UserViews "https://github.com/aschnarre1/bankapp/tree/master/views/users/"
    click LayoutsAndPartials "https://github.com/aschnarre1/bankapp/blob/master/views/layouts/boilierplate.ejs"
    click PublicAssets "https://github.com/aschnarre1/bankapp/tree/master/public/"
    click Schemas "https://github.com/aschnarre1/bankapp/blob/master/schemas.js"
    click GeneralViews "https://github.com/aschnarre1/bankapp/blob/master/views/home.ejs"

    %% Styles
    classDef backend fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef frontend fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef external fill:#ffff99,stroke:#000,stroke-width:1px;
    classDef util fill:#d3d3d3,stroke:#000,stroke-width:1px;
```
