Skip to main content

Get Dashboard Stats

GET /api/dashboard
Retrieves comprehensive dashboard statistics including project counts, status breakdowns, and recent projects for the authenticated user.

Headers

Authorization
string
required
Bearer token for authentication

Response

success
boolean
Indicates if the request was successful
stats
object
Aggregated statistics for all user projects
recentProjects
array
Array of the 4 most recently updated projects
{
  "success": true,
  "stats": {
    "totalProjects": 12,
    "liveCount": 8,
    "stoppedCount": 4,
    "staticCount": 7,
    "nodeCount": 5,
    "totalRequests": 145032
  },
  "recentProjects": [
    {
      "_id": "507f1f77bcf86cd799439011",
      "name": "my-portfolio",
      "projectType": "Static",
      "status": "live",
      "plan": "pro",
      "totalRequest": 25430,
      "totalBuilds": 12,
      "domain": "example.com",
      "updatedAt": "2024-03-15T14:22:00.000Z",
      "createdAt": "2024-01-10T08:15:00.000Z"
    },
    {
      "_id": "507f1f77bcf86cd799439012",
      "name": "api-service",
      "projectType": "node",
      "status": "live",
      "plan": "business",
      "totalRequest": 89456,
      "totalBuilds": 45,
      "domain": "api-service.deployhub.online",
      "updatedAt": "2024-03-14T10:15:00.000Z",
      "createdAt": "2024-02-01T12:30:00.000Z"
    },
    {
      "_id": "507f1f77bcf86cd799439013",
      "name": "docs-site",
      "projectType": "static",
      "status": "stopped",
      "plan": "free",
      "totalRequest": 1203,
      "totalBuilds": 5,
      "domain": "docs-site.deployhub.online",
      "updatedAt": "2024-03-10T16:45:00.000Z",
      "createdAt": "2024-02-20T09:00:00.000Z"
    },
    {
      "_id": "507f1f77bcf86cd799439014",
      "name": "blog",
      "projectType": "Static",
      "status": "live",
      "plan": "pro",
      "totalRequest": 12890,
      "totalBuilds": 8,
      "domain": "blog.deployhub.online",
      "updatedAt": "2024-03-08T11:20:00.000Z",
      "createdAt": "2024-01-25T14:00:00.000Z"
    }
  ]
}

Implementation Details

Query Logic

  • Fetches all projects owned by the authenticated user
  • Excludes projects with status deleted
  • Projects are sorted by updatedAt in descending order (most recent first)
  • Uses lean queries for optimal performance

Statistics Aggregation

  • totalProjects: Count of all non-deleted projects
  • liveCount: Filtered count where status === "live"
  • stoppedCount: Filtered count where status === "stopped"
  • staticCount: Filtered count where projectType === "Static" || projectType === "static"
  • nodeCount: Filtered count where projectType === "node"
  • totalRequests: Sum of totalRequest field across all projects using reduce

Recent Projects

  • Returns the first 4 projects from the sorted list (most recently updated)
  • Domain logic: displays custom domain if hascustomDomain is true, otherwise uses {subdomain}.deployhub.online format

Selected Fields

The query selects the following fields from the Project model:
  • name
  • projectType
  • status
  • totalRequest
  • totalBuilds
  • plan
  • subdomain
  • hascustomDomain
  • customDomain
  • createdAt
  • updatedAt

Error Response

{
  "success": false,
  "message": "Failed to fetch dashboard stats"
}