# andrz98/todobot architecture

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

- Interactive diagram: https://gitdiagram.com/andrz98/todobot
- Repository: https://github.com/andrz98/todobot

## Overview

##### Main Components
- Entry Point: app.js
- Configuration: The “config” directory (especially config/db.js for the database)
- Controllers: Two key groups
- Auth Controller in controllers/authController – responsible for user authentication and related user operations.
- Task Controllers in controllers/taskControllers – handling task operations such as add, clear, complete, delete, edit, and list tasks.
- Models: The “models” directory containing authorizedUser.js and task.js – which define the data structures.
- Helpers: Utility modules in the “helpers” directory for additional business logic, like verifying user authorization and finding tasks by name.
- Middlewares: Error handling from middlewares/errors/errorHandler.js – these intercept and manage errors across the application.
- Tests: The “test” directory (both integration and unit tests) verifying the functionality.
- Scripts: Manual and other scripts in “scripts/manual” that might be used during development or debugging (e.g., testDB.js).

##### Relationships and Interactions
- From app.js, indicate that the application:
- Reads configuration settings (from config/db.js) to establish database connections.
- Routes requests to respective controllers (auth and task controllers).
- That the controllers interact with the Models (authorizedUser and task) for CRUD operations.
- Optionally, include the “Tests” and “Scripts” components as separate areas that simulate interactions or verify functionality but note that they are not part of the runtime architecture.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Controllers, Models, Helpers, and Middlewares are separated into different directories, which means the application follows a fairly modular design.
- Error Handling: The use of dedicated middleware for error handling demonstrates a design principle to centralize and standardize error responses.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client/API Calls"):::client
    EntryPoint("app.js – Application Entry Point"):::entryPoint
    ConfigDB("config/db.js – Database Config"):::config

    Client -->|"sendsRequest"| EntryPoint
    EntryPoint -->|"loadsConfig"| ConfigDB

    subgraph "Controllers"
        AController("Auth Controller (handles authentication)"):::controller
        TComposite("Task Controller (Composite)"):::controller

        subgraph "Task Controllers"
            AddTask("Add Task"):::taskController
            ClearTask("Clear Task"):::taskController
            CompleteTask("Complete Task"):::taskController
            DeleteTask("Delete Task"):::taskController
            EditTask("Edit Task"):::taskController
            ListTask("List Task"):::taskController
        end
    end

    EntryPoint -->|"routesTo"| AController
    EntryPoint -->|"routesTo"| TComposite
    TComposite -->|"delegatesTo"| AddTask
    TComposite -->|"delegatesTo"| ClearTask
    TComposite -->|"delegatesTo"| CompleteTask
    TComposite -->|"delegatesTo"| DeleteTask
    TComposite -->|"delegatesTo"| EditTask
    TComposite -->|"delegatesTo"| ListTask

    subgraph "Models"
        AuthUserModel("Authorized User Model"):::model
        TaskModel("Task Model"):::model
    end

    subgraph "Helpers"
        UserAuthHelper("User Authorization Helper"):::helper
        TaskLookupHelper("Task Lookup Helper"):::helper
    end

    AController -->|"CRUDOn"| AuthUserModel
    AController -->|"validatesWith"| UserAuthHelper
    TComposite -->|"CRUDOn"| TaskModel
    TComposite -->|"validatesWith"| TaskLookupHelper

    ErrorMiddleware("Error Handling Middleware"):::middleware
    AController -->|"handledBy"| ErrorMiddleware
    TComposite -->|"handledBy"| ErrorMiddleware

    subgraph "Testing/Dev Tools"
        AppTest("General App Test"):::test
        AuthTest("Auth Controller Unit Test"):::test
        TaskTest("Task Controller Unit Test"):::test
        TestScript("Test Database Script"):::script
    end

    classDef client fill:#ff9,stroke:#333,stroke-width:2px;
    classDef entryPoint fill:#f9f,stroke:#333,stroke-width:2px;
    classDef config fill:#ccf,stroke:#333,stroke-width:2px;
    classDef controller fill:#cfc,stroke:#333,stroke-width:2px;
    classDef taskController fill:#9cf,stroke:#333,stroke-width:2px;
    classDef model fill:#fc9,stroke:#333,stroke-width:2px;
    classDef helper fill:#ffc,stroke:#333,stroke-width:2px;
    classDef middleware fill:#f99,stroke:#333,stroke-width:2px;
    classDef test fill:#ddd,stroke:#333,stroke-width:2px,stroke-dasharray:5 5;
    classDef script fill:#efe,stroke:#333,stroke-width:2px,stroke-dasharray:5 5;

    click EntryPoint "https://github.com/andrz98/todobot/blob/develop/app.js"
    click ConfigDB "https://github.com/andrz98/todobot/blob/develop/config/db.js"
    click AController "https://github.com/andrz98/todobot/blob/develop/controllers/authController/authController.js"
    click TComposite "https://github.com/andrz98/todobot/blob/develop/controllers/taskControllers/taskController.js"
    click AddTask "https://github.com/andrz98/todobot/blob/develop/controllers/taskControllers/addTask.js"
    click ClearTask "https://github.com/andrz98/todobot/blob/develop/controllers/taskControllers/clearTask.js"
    click CompleteTask "https://github.com/andrz98/todobot/blob/develop/controllers/taskControllers/completeTask.js"
    click DeleteTask "https://github.com/andrz98/todobot/blob/develop/controllers/taskControllers/deleteTask.js"
    click EditTask "https://github.com/andrz98/todobot/blob/develop/controllers/taskControllers/editTask.js"
    click ListTask "https://github.com/andrz98/todobot/blob/develop/controllers/taskControllers/listTask.js"
    click AuthUserModel "https://github.com/andrz98/todobot/blob/develop/models/authorizedUser.js"
    click TaskModel "https://github.com/andrz98/todobot/blob/develop/models/task.js"
    click UserAuthHelper "https://github.com/andrz98/todobot/blob/develop/helpers/userAuthorizedTaskController/isUserAuthorized.js"
    click TaskLookupHelper "https://github.com/andrz98/todobot/blob/develop/helpers/userTaskBynameController/findUserTaskByName.js"
    click ErrorMiddleware "https://github.com/andrz98/todobot/blob/develop/middlewares/errors/errorHandler.js"
    click AppTest "https://github.com/andrz98/todobot/blob/develop/test/app.js"
    click AuthTest "https://github.com/andrz98/todobot/blob/develop/test/unit/controllers/authController/authController.test.js"
    click TaskTest "https://github.com/andrz98/todobot/blob/develop/test/unit/controllers/taskController/taskController.test.js"
    click TestScript "https://github.com/andrz98/todobot/blob/develop/scripts/manual/testDB.js"
```
