# masterkprod/task-manager-backend architecture

> Architecture diagram of the GitHub repository masterkprod/task-manager-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/masterkprod/task-manager-backend
- Repository: https://github.com/masterkprod/task-manager-backend

## Overview

##### Project type and purpose
- This is a full-stack CRUD Task Manager.
- Frontend: Next.js 14 + React 18 + TailwindCSS, React Query, React Hook Form.
- Backend: Express.js + TypeScript, MongoDB (Mongoose), JWT auth, Swagger docs, rate limiting, Helmet.

##### File structure
- Top-level:
- package.json, tsconfig.json, render.yaml, postman-collection.json
- src/ containing config/, controllers/, middlewares/, models/, routes/, services/, server.ts
- Patterns: MVC-style on the backend (routes → controllers → services → models)
- Config files for database, swagger, environment variables
- No separate frontend in tree (assume it lives in a sibling directory in full repo)

##### Key insights from README
- Frontend and backend are deployed separately (Vercel for Next.js, Render for Express)
- Backend exposes REST API under /api, plus Swagger UI at /api-docs and a health check endpoint
- JWT access/refresh token flow, CORS configuration, user roles (user/admin)

a. Main components (Container view)
1. User’s Browser / Mobile Web App
2. Next.js Frontend (App Router)
3. React-Query Data Layer
4. Express.js Backend API
5. MongoDB Database
6. External Services: Render (backend host), Vercel (frontend host)
7. Optional: Postman Collection (for testing), Swagger UI
b. Relationships & data flows
- Browser ↔ Next.js via HTTPS (UI, API calls)
- Next.js → React-Query → Fetch through NEXT_PUBLIC_API_URL → Express API
- Express middlewares (CORS, rate limiting, Helmet) → auth middleware  → controllers
- Controllers → calls to services → interact with Mongoose models → MongoDB
- Express → Swagger endpoint for docs → Developer
- JWT tokens stored in httpOnly cookies, sent on each request
c. Architectural patterns & principles
- Separation of concerns:
– Frontend (presentation + client state) vs Backend (business logic + data)
- MVC on the server: routes → controllers → services → models
- Layered security: CORS, rate limiter, helmet, express-validator, JWT auth
- Environment-driven configuration (src/config)
- Containerized deployment on Render and Vercel
d. Key technologies & libraries
- Next.js 14, React 18, TailwindCSS, @tanstack/react-query, React Hook Form
- Express.js, TypeScript, Mongoose, jsonwebtoken, express-validator, helmet, swagger-ui-express
- MongoDB (Atlas or local)

##### Detail
- Essential backend layers (config, routes, middlewares, controllers, services, models)
- Environment variable configuration block feeding both frontend and backend
- Don’t shy away from illustrating the full MVC ladder and token flow – more clarity trumps minimalism.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External and Deployment
    subgraph "External Services" 
        direction TB
        Git[("Git Repository")]:::external
        Vercel[("Vercel (Frontend Host)")]:::external
        RenderSvc[("Render (Backend Host)")]:::external
        Postman[("Postman Collection")]:::external
        SwaggerUI[("Swagger UI")]:::external
    end
    Git --> Vercel
    Git --> RenderSvc

    %% Environment Config
    Env[("env.example")]:::external
    Env --> NextApp
    Env --> Server

    %% User Interaction
    User[("User's Browser")]:::external
    User --> NextApp

    %% Frontend Layer
    subgraph "Frontend: Next.js 14" 
        direction TB
        NextApp[("Next.js App Router")]:::frontend
        ReactQuery[("React-Query")]:::frontend
        RHookForm[("React Hook Form")]:::frontend
        Tailwind[("TailwindCSS")]:::frontend
    end
    NextApp --> ReactQuery
    ReactQuery -->|"fetch via NEXT_PUBLIC_API_URL"| Server

    %% Backend Layer
    subgraph "Backend: Express.js + TypeScript" 
        direction TB
        Server[("src/server.ts")]:::backend

        subgraph "Config" 
            direction TB
            AppConfig[("config.ts")]:::config
            DBConfig[("database.ts")]:::config
            SwaggerConfig[("swagger.ts")]:::config
        end

        subgraph "Middlewares" 
            direction TB
            CORS[("CORS")]:::backend
            Helmet[("Helmet")]:::backend
            RateLimit[("Rate Limiter")]:::backend
            Validation[("validation.ts")]:::backend
            AuthMw[("auth.ts")]:::backend
        end

        subgraph "Routes" 
            direction TB
            AuthRoutes[("/api/auth")]:::backend
            TaskRoutes[("/api/tasks")]:::backend
            UserRoutes[("/api/users")]:::backend
        end

        subgraph "Controllers" 
            direction TB
            AuthCtrl[("authController.ts")]:::backend
            TaskCtrl[("taskController.ts")]:::backend
            UserCtrl[("userController.ts")]:::backend
        end

        subgraph "Services" 
            direction TB
            AuthService[("authService.ts")]:::backend
        end

        subgraph "Models" 
            direction TB
            UserModel[("User.ts")]:::backend
            TaskModel[("Task.ts")]:::backend
        end
    end

    %% Backend Flow
    NextApp -->|"API Calls"| AuthRoutes
    NextApp -->|"API Calls"| TaskRoutes
    NextApp -->|"API Calls"| UserRoutes

    Server --> AppConfig
    Server --> DBConfig
    Server --> SwaggerConfig

    Server --> CORS --> Helmet --> RateLimit --> Validation --> AuthMw

    AuthMw --> AuthRoutes
    AuthRoutes --> AuthCtrl --> AuthService --> UserModel
    TaskRoutes --> TaskCtrl --> TaskModel
    UserRoutes --> UserCtrl --> UserModel

    RenderSvc --> Server

    %% Database
    subgraph "Database" 
        direction TB
        MongoDB[("MongoDB")]:::database
    end
    Server -->|"Mongoose"| MongoDB

    %% API Docs & Testing
    SwaggerConfig --> SwaggerUI
    Postman --> AuthRoutes
    Postman --> TaskRoutes
    Postman --> UserRoutes

    %% Click Events
    click AppConfig "https://github.com/masterkprod/task-manager-backend/blob/main/src/config/config.ts"
    click DBConfig "https://github.com/masterkprod/task-manager-backend/blob/main/src/config/database.ts"
    click SwaggerConfig "https://github.com/masterkprod/task-manager-backend/blob/main/src/config/swagger.ts"
    click Validation "https://github.com/masterkprod/task-manager-backend/blob/main/src/middlewares/validation.ts"
    click AuthMw "https://github.com/masterkprod/task-manager-backend/blob/main/src/middlewares/auth.ts"
    click TaskModel "https://github.com/masterkprod/task-manager-backend/blob/main/src/models/Task.ts"
    click UserModel "https://github.com/masterkprod/task-manager-backend/blob/main/src/models/User.ts"
    click AuthService "https://github.com/masterkprod/task-manager-backend/blob/main/src/services/authService.ts"
    click AuthCtrl "https://github.com/masterkprod/task-manager-backend/blob/main/src/controllers/authController.ts"
    click TaskCtrl "https://github.com/masterkprod/task-manager-backend/blob/main/src/controllers/taskController.ts"
    click UserCtrl "https://github.com/masterkprod/task-manager-backend/blob/main/src/controllers/userController.ts"
    click AuthRoutes "https://github.com/masterkprod/task-manager-backend/blob/main/src/routes/auth.ts"
    click TaskRoutes "https://github.com/masterkprod/task-manager-backend/blob/main/src/routes/tasks.ts"
    click UserRoutes "https://github.com/masterkprod/task-manager-backend/blob/main/src/routes/users.ts"
    click Server "https://github.com/masterkprod/task-manager-backend/blob/main/src/server.ts"
    click RenderSvc "https://github.com/masterkprod/task-manager-backend/blob/main/render.yaml"
    click Env "https://github.com/masterkprod/task-manager-backend/blob/main/env.example"
    click Postman "https://github.com/masterkprod/task-manager-backend/blob/main/postman-collection.json"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef database fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef config fill:#E6E6E6,stroke:#000,stroke-width:1px;
```
