# harry-huynh/to-do-backend architecture

> Architecture diagram of the GitHub repository harry-huynh/to-do-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harry-huynh/to-do-backend
- Repository: https://github.com/harry-huynh/to-do-backend

## Overview

##### Project type and purpose
- This is a backend‐only REST API for a to‐do application, built on Node.js/Express with MongoDB as its persistence layer.
- It exposes user and task management endpoints, uses JWT for authentication, and follows a simple layered structure (routes → services → database).

##### File structure
- server.js: entry point, loads middleware, mounts routes, reads env variables, connects to MongoDB.
- routes/: defines Express routers — User.js for `/api/user/register` & `/api/user/login`, Task.js for `/api/user/tasks` CRUD.
- services/: business‐logic layer. e.g. user‐service.js handles hashing, token creation, user lookups.
- schemas/: Mongoose models for User and Task, enforcing data structure at the DB level.
- package.json / package-lock.json: dependencies (express, mongoose, passport, jsonwebtoken, bcryptjs, cors, dotenv).
- vercel.json: deployment config (if using Vercel).
- .env variables for MONGO_URL, JWT_SECRET, PORT.

##### README for additional insights
- Confirms stack: Express + Mongoose + Passport‐JWT.
- Outlines the auth flow: login → issue JWT → subsequent requests carry Bearer token.
- Lists all endpoints & required headers.

##### Elements
- Clear labels: “Client”, “API Server”, “Auth Middleware”, “User Service”, “Task Service”, “MongoDB”.
– Client → API Server (HTTP/HTTPS requests)
– API Server → MongoDB (over MONGODB_URI)
– Data flow back in reverse.
– Rectangles for services/components

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    Client["Client (Web/Mobile)"]:::client

    %% API Server Layer
    subgraph "API Server"
        Env["Environment Variables (.env)"]:::config
        Middleware["CORS / BodyParser / Passport-JWT Middleware"]:::middleware

        subgraph "Routers"
            UR["User Router"]:::router
            TR["Task Router"]:::router
        end

        subgraph "Services"
            US["User Service"]:::service
            TS["Task Service"]:::service
        end

        subgraph "Models"
            UM["User Model"]:::model
            TM["Task Model"]:::model
        end
    end

    %% Database
    DB["MongoDB"]:::database

    %% Connections
    Client -->|"HTTP/HTTPS"| Middleware
    Env --> Middleware
    Middleware --> UR
    Middleware --> TR
    UR -->|"calls"| US
    TR -->|"calls"| TS
    US -->|"uses Mongoose"| UM
    TS -->|"uses Mongoose"| TM
    UM -->|"reads/writes"| DB
    TM -->|"reads/writes"| DB

    %% Click Events
    click ExpressServer "https://github.com/harry-huynh/to-do-backend/blob/main/server.js"
    click UR "https://github.com/harry-huynh/to-do-backend/blob/main/routes/User.js"
    click TR "https://github.com/harry-huynh/to-do-backend/blob/main/routes/Task.js"
    click US "https://github.com/harry-huynh/to-do-backend/blob/main/services/user-service.js"
    click TS "https://github.com/harry-huynh/to-do-backend/blob/main/services/user-service.js"
    click UM "https://github.com/harry-huynh/to-do-backend/blob/main/schemas/User.js"
    click TM "https://github.com/harry-huynh/to-do-backend/blob/main/schemas/Task.js"
    click VercelConfig "https://github.com/harry-huynh/to-do-backend/blob/main/vercel.json"
    click PackageJSON "https://github.com/harry-huynh/to-do-backend/blob/main/package.json"
    click Readme "https://github.com/harry-huynh/to-do-backend/blob/main/README.md"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:1px
    classDef config fill:#bbf,stroke:#333,stroke-width:1px
    classDef middleware fill:#ffb,stroke:#333,stroke-width:1px
    classDef router fill:#bfb,stroke:#333,stroke-width:1px
    classDef service fill:#fbf,stroke:#333,stroke-width:1px
    classDef model fill:#bff,stroke:#333,stroke-width:1px
    classDef database fill:#fb8,stroke:#333,stroke-width:2px
```
