# tanishk794/taskback architecture

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

- Interactive diagram: https://gitdiagram.com/tanishk794/taskback
- Repository: https://github.com/tanishk794/taskback

## Overview

##### Main Components
- Backend Server: The entry point is server.js, which starts the Node.js/Express server.
- API Endpoints: There are two main APIs – Authentication (AUTH API) and Task management (TASK API).
- Controllers: authController.js and taskController.js handle the logic for incoming requests.
- Routes: The authRoutes.js and taskRoutes.js files define URL endpoints and map them to controller functions.
- Middleware: The authMiddleware.js file validates requests for secure operations.
- Models: Task.js and User.js reside in the model directory to define the data structure.
- Database Connection: src/config/connectDb.js sets up the connection to a MongoDB cloud instance.
- Utility: src/utils/generateToken.js is responsible for generating authentication tokens.
- Environment/Configuration: .env is used to store configuration values.

##### Relationships and Interactions
- A client (or frontend) sends HTTP requests (e.g., registration, login, task operations) to the backend.
- Requests flow through the corresponding route (e.g., /api/auth or /api/tasks).
- For secure endpoints, authMiddleware intercepts the request for token validation.
- Routes then hand off the requests to the appropriate controller.
- Controllers perform business logic and interact with the models (User and Task) to perform database operations.
- The database operations are managed through the MongoDB connection that is established via src/config/connectDb.js.
- Utilities like generateToken are used within the authentication controller to create tokens.
- Responses flow back through the route to the client.

##### Architectural Patterns and Design Principles
- MVC (Model-View-Controller)-inspired separation: Though it’s an API backend, hosting models, controllers, middleware, and routes gives a clear separation of concerns.
- Modular design: Each logical component is isolated for better maintainability.
- Environment-based configuration: Using .env provides flexibility to swap configurations without code modifications.

##### Important Labels and Details
- Endpoints names in the Routes layer (e.g., /api/auth/register, /api/tasks/).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    Client["Client/Consumer"]:::client
    Server["Backend Server (server.js)"]:::server
    Config["Configuration (.env)"]:::config

    %% Server Layer: Routes Layer
    subgraph "Routes Layer"
        AuthRoutes["Auth Routes (/api/auth)"]:::routes
        TaskRoutes["Task Routes (/api/tasks)"]:::routes
    end

    %% Server Layer: Middleware Layer
    subgraph "Middleware Layer"
        AuthMiddleware["Auth Middleware (token validation)"]:::middleware
    end

    %% Server Layer: Controllers Layer
    subgraph "Controllers Layer"
        AuthController["Auth Controller – Handles login/registration"]:::controller
        TaskController["Task Controller – Manages tasks CRUD"]:::controller
    end

    %% Server Layer: Models Layer
    subgraph "Models Layer"
        UserModel["User Model"]:::model
        TaskModel["Task Model"]:::model
    end

    %% Utility and Database Components
    Utility["Utility (generateToken)"]:::utility
    DB["Database Connection (MongoDB)"]:::db

    %% Connections - Request Flow
    Client -->|"request"| Server
    Server -->|"load config"| Config
    Server -->|"register routes"| AuthRoutes
    Server -->|"register routes"| TaskRoutes

    AuthRoutes -->|"forward request"| AuthController
    TaskRoutes -->|"secure request"| AuthMiddleware
    AuthMiddleware -->|"validate and forward"| TaskController

    %% Controller interactions with Models and Utility
    AuthController -->|"db operation"| UserModel
    TaskController -->|"db operation"| TaskModel
    AuthController -->|"generate token"| Utility

    %% Models to Database operations
    UserModel -->|"query/modify"| DB
    TaskModel -->|"query/modify"| DB

    %% Response Flow (dashed lines)
    DB -->|"response"| AuthController
    DB -->|"response"| TaskController
    AuthController -.->|"send response"| AuthRoutes
    TaskController -.->|"send response"| TaskRoutes
    AuthRoutes -.->|"return response"| Server
    TaskRoutes -.->|"return response"| Server
    Server -.->|"response"| Client

    %% Styles
    classDef client fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef server fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef routes fill:#a5d6a7,stroke:#333,stroke-width:2px;
    classDef middleware fill:#ffcc80,stroke:#333,stroke-width:2px;
    classDef controller fill:#90caf9,stroke:#333,stroke-width:2px;
    classDef model fill:#f48fb1,stroke:#333,stroke-width:2px;
    classDef utility fill:#ffe082,stroke:#333,stroke-width:2px;
    classDef db fill:#b3e5fc,stroke:#333,stroke-width:2px;
    classDef config fill:#eeeeee,stroke:#333,stroke-width:2px;

    %% Click Events
    click Server "https://github.com/tanishk794/taskback/blob/main/server.js"
    click AuthRoutes "https://github.com/tanishk794/taskback/blob/main/src/routes/authRoutes.js"
    click TaskRoutes "https://github.com/tanishk794/taskback/blob/main/src/routes/taskRoutes.js"
    click AuthController "https://github.com/tanishk794/taskback/blob/main/src/controllers/authController.js"
    click TaskController "https://github.com/tanishk794/taskback/blob/main/src/controllers/taskController.js"
    click AuthMiddleware "https://github.com/tanishk794/taskback/blob/main/src/middleware/authMiddleware.js"
    click UserModel "https://github.com/tanishk794/taskback/blob/main/model/User.js"
    click TaskModel "https://github.com/tanishk794/taskback/blob/main/model/Task.js"
    click DB "https://github.com/tanishk794/taskback/blob/main/src/config/connectDb.js"
    click Utility "https://github.com/tanishk794/taskback/blob/main/src/utils/generateToken.js"
    click Config "https://github.com/tanishk794/taskback/blob/main/.env"
```
