# nenuphare/bloomy-app-back architecture

> Architecture diagram of the GitHub repository nenuphare/bloomy-app-back, 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/nenuphare/bloomy-app-back
- Repository: https://github.com/nenuphare/bloomy-app-back

## Overview

##### Project Type & Purpose
- The project is a Node.js backend server providing a RESTful API for a full-stack application (see the repo URLs that point to separate back‐ and front-end repositories).
- The backend supports various domains such as “home”, “room”, “task”, “type”, “user”, and “subscriber” management.
- It relies on JWT-based authentication (with files like jwtMiddleware.js and subscriberJwtMiddleware.js) and incorporates a policy file for access control (e.g., checkUserHome.js).

##### File Structure Insights & Architectural Breakdown
- Main Entry Point – index.js: This file is likely setting up the Express server, initializing middlewares, and mounting routes.
- Controllers & Routes:
– The “controllers” directory contains individual controllers (home, room, task, type, user) that encapsulate business logic.
– The “routes” directory maps URL endpoints to these controllers (e.g., homeRoute.js, roomRoute.js, etc.).
- Models:
– The “models” directory defines data structures or possibly interfaces to the database (e.g., homeModel.js, roomModel.js, and others). This part of the architecture supports the data persistence layer.
- Middleware & Policy:
– JWT middlewares in “middlewares” and in the “landing” folder manage authentication.
– The “policy” directory (checkUserHome.js) enforces authorization rules.
- Special Components:
– The “landing” directory appears to manage subscriber-specific functionalities, including routes, controllers, and a model tailored to subscribers.
– The “utils” directory with shareCodeGenerator.js holds helper functions to support the core logic.

a. Main Components:
– Client Interface: Though part of a separate repository ("bloomy-app-front"), represent front-end integration with the backend.
– API Gateway / Server Entry: index.js which receives HTTP requests.
– Routing Layer: Individual route files (from the “routes” directory) that direct requests to corresponding controllers.
– Controllers: Modules in “controllers” (and landing) that handle request logic.
– Data Models: Components under “models” that represent and interact with the data – possibly a database connection layer.
– Authentication/Authorization: Middlewares (in “middlewares” and "landing") and policy files that enforce security checks.
– Utility Functions: “utils” for tasks like code generation.
b. Relationships & Interactions:
– Incoming HTTP requests (e.g., from the front-end) hit the API Gateway (index.js).
– Requests are routed via the “routes” layer, which directs them to the proper controller.
– Controllers process the request, often interacting with the Models to fetch or store data.
– Before reaching controllers, authentication middlewares (JWT validation) and authorization policies intercept requests.
– Utility functions may be called within controllers to handle specific tasks.
c. Architectural Patterns & Principles:
– MVC (Model-View-Controller): Even though it's a backend, the separation between routing, controllers (logic), and models (data) is clear.
– Middleware-based Security: Integration of authentication (JWT) and authorization (policy) aspects supports secure request handling.
– Modularity: Each domain (home, room, task, etc.) is clearly separated into its own controllers, routes, and models.
d. Relevant Technologies:
– Node.js/Express (implied by the file naming and typical project structure).
– JSON Web Tokens (JWT) for authentication.
– Possibly an ORM or direct database access via models.
– Utility libraries for additional functionalities such as shared code generation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (bloomy-app-front)"]:::clientStyle
    APIGateway["API Gateway (index.js)"]:::apiStyle

    subgraph "Routing Layer"
        routeHome["Home Route"]:::routeStyle
        routeRoom["Room Route"]:::routeStyle
        routeTask["Task Route"]:::routeStyle
        routeType["Type Route"]:::routeStyle
        routeUser["User Route"]:::routeStyle
        routeSubscriber["Subscriber Route"]:::routeStyle
    end

    subgraph "Middleware & Policy"
        middlewareJWT["JWT Middleware"]:::middlewareStyle
        middlewareSubscriberJWT["Subscriber JWT Middleware"]:::middlewareStyle
        policyAccess["Access Control Policy"]:::policyStyle
    end

    subgraph "Controllers"
        ctrlHome["Home Controller"]:::controllerStyle
        ctrlRoom["Room Controller"]:::controllerStyle
        ctrlTask["Task Controller"]:::controllerStyle
        ctrlType["Type Controller"]:::controllerStyle
        ctrlUser["User Controller"]:::controllerStyle
        ctrlSubscriber["Subscriber Controller"]:::controllerStyle
    end

    subgraph "Data Models"
        modelHome["Home Model"]:::modelStyle
        modelRoom["Room Model"]:::modelStyle
        modelTask["Task Model"]:::modelStyle
        modelType["Type Model"]:::modelStyle
        modelUser["User Model"]:::modelStyle
        modelUserHome["User Home Model"]:::modelStyle
        modelSetting["Setting Model"]:::modelStyle
        modelSubscriber["Subscriber Model"]:::modelStyle
    end

    subgraph "Utility Functions"
        utilCodeGen["Shared Code Generator"]:::utilityStyle
    end

    %% Flow connections
    Client -->|"HTTPRequest"| APIGateway
    APIGateway -->|"RoutesMapping"| routeHome
    APIGateway -->|"RoutesMapping"| routeRoom
    APIGateway -->|"RoutesMapping"| routeTask
    APIGateway -->|"RoutesMapping"| routeType
    APIGateway -->|"RoutesMapping"| routeUser
    APIGateway -->|"RoutesMapping"| routeSubscriber

    %% Routes trigger authentication via middleware
    routeHome -->|"AuthCheck"| middlewareJWT
    routeRoom -->|"AuthCheck"| middlewareJWT
    routeTask -->|"AuthCheck"| middlewareJWT
    routeType -->|"AuthCheck"| middlewareJWT
    routeUser -->|"AuthCheck"| middlewareJWT
    routeSubscriber -->|"AuthCheck"| middlewareSubscriberJWT

    middlewareJWT --> policyAccess
    middlewareSubscriberJWT --> policyAccess

    policyAccess -->|"Validated"| ctrlHome
    policyAccess -->|"Validated"| ctrlRoom
    policyAccess -->|"Validated"| ctrlTask
    policyAccess -->|"Validated"| ctrlType
    policyAccess -->|"Validated"| ctrlUser
    policyAccess -->|"Validated"| ctrlSubscriber

    %% Controllers interact with Models and Utility Functions
    ctrlHome -->|"Uses"| modelHome
    ctrlHome -->|"Utilizes"| utilCodeGen

    ctrlRoom -->|"Uses"| modelRoom
    ctrlRoom -->|"Utilizes"| utilCodeGen

    ctrlTask -->|"Uses"| modelTask
    ctrlTask -->|"Utilizes"| utilCodeGen

    ctrlType -->|"Uses"| modelType
    ctrlType -->|"Utilizes"| utilCodeGen

    ctrlUser -->|"Uses"| modelUser
    ctrlUser -->|"Uses"| modelUserHome
    ctrlUser -->|"Uses"| modelSetting
    ctrlUser -->|"Utilizes"| utilCodeGen

    ctrlSubscriber -->|"Uses"| modelSubscriber
    ctrlSubscriber -->|"Utilizes"| utilCodeGen

    %% Click Events
    click APIGateway "https://github.com/nenuphare/bloomy-app-back/blob/main/index.js"
    click routeHome "https://github.com/nenuphare/bloomy-app-back/blob/main/routes/homeRoute.js"
    click routeRoom "https://github.com/nenuphare/bloomy-app-back/blob/main/routes/roomRoute.js"
    click routeTask "https://github.com/nenuphare/bloomy-app-back/blob/main/routes/taskRoute.js"
    click routeType "https://github.com/nenuphare/bloomy-app-back/blob/main/routes/typeRoute.js"
    click routeUser "https://github.com/nenuphare/bloomy-app-back/blob/main/routes/userRoute.js"
    click routeSubscriber "https://github.com/nenuphare/bloomy-app-back/blob/main/landing/subscriberRoute.js"
    click ctrlHome "https://github.com/nenuphare/bloomy-app-back/blob/main/controllers/homeController.js"
    click ctrlRoom "https://github.com/nenuphare/bloomy-app-back/blob/main/controllers/roomController.js"
    click ctrlTask "https://github.com/nenuphare/bloomy-app-back/blob/main/controllers/taskController.js"
    click ctrlType "https://github.com/nenuphare/bloomy-app-back/blob/main/controllers/typeController.js"
    click ctrlUser "https://github.com/nenuphare/bloomy-app-back/blob/main/controllers/userController.js"
    click ctrlSubscriber "https://github.com/nenuphare/bloomy-app-back/blob/main/landing/subscriberController.js"
    click modelHome "https://github.com/nenuphare/bloomy-app-back/blob/main/models/homeModel.js"
    click modelRoom "https://github.com/nenuphare/bloomy-app-back/blob/main/models/roomModel.js"
    click modelTask "https://github.com/nenuphare/bloomy-app-back/blob/main/models/taskModel.js"
    click modelType "https://github.com/nenuphare/bloomy-app-back/blob/main/models/typeModel.js"
    click modelUser "https://github.com/nenuphare/bloomy-app-back/blob/main/models/userModel.js"
    click modelUserHome "https://github.com/nenuphare/bloomy-app-back/blob/main/models/userHomeModel.js"
    click modelSetting "https://github.com/nenuphare/bloomy-app-back/blob/main/models/settingModel.js"
    click modelSubscriber "https://github.com/nenuphare/bloomy-app-back/blob/main/landing/subscriberModel.js"
    click middlewareJWT "https://github.com/nenuphare/bloomy-app-back/blob/main/middlewares/jwtMiddleware.js"
    click middlewareSubscriberJWT "https://github.com/nenuphare/bloomy-app-back/blob/main/landing/subscriberJwtMiddleware.js"
    click policyAccess "https://github.com/nenuphare/bloomy-app-back/blob/main/policy/checkUserHome.js"
    click utilCodeGen "https://github.com/nenuphare/bloomy-app-back/blob/main/utils/shareCodeGenerator.js"

    %% Styles
    classDef clientStyle fill:#b3e5fc,stroke:#000,stroke-width:1px;
    classDef apiStyle fill:#81d4fa,stroke:#000,stroke-width:1px;
    classDef routeStyle fill:#a5d6a7,stroke:#000,stroke-width:1px;
    classDef controllerStyle fill:#fff59d,stroke:#000,stroke-width:1px;
    classDef middlewareStyle fill:#ffcc80,stroke:#000,stroke-width:1px;
    classDef modelStyle fill:#f48fb1,stroke:#000,stroke-width:1px;
    classDef utilityStyle fill:#ce93d8,stroke:#000,stroke-width:1px;
    classDef policyStyle fill:#f06292,stroke:#000,stroke-width:1px;
```
