# shaorankun/blogfruits-api architecture

> Architecture diagram of the GitHub repository shaorankun/blogfruits-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shaorankun/blogfruits-api
- Repository: https://github.com/shaorankun/blogfruits-api

## Overview

BlogFruits is an Express REST API for authentication, user and blog management, comments, and AI-generated Fruit of the Day recommendations. A client calls routes mounted by the app; route handlers dispatch to controllers, which apply domain rules and access Mongoose models. The documented FOTD flow checks the MongoDB cache before requesting Gemini and saving a new result. README capabilities supplement sampled source where route or controller wiring was not available for inspection.

Main entry points: [`index.js`](https://github.com/shaorankun/blogfruits-api/blob/main/index.js) (Express app), [`routes/user.route.js`](https://github.com/shaorankun/blogfruits-api/blob/main/routes/user.route.js) (User routes), [`routes/post.route.js`](https://github.com/shaorankun/blogfruits-api/blob/main/routes/post.route.js) (Post routes), [`routes/comment.route.js`](https://github.com/shaorankun/blogfruits-api/blob/main/routes/comment.route.js) (Comment routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["API application"]
  node_app["Express app<br/>[index.js]"]
  node_auth_routes["Auth routes<br/>[auth.route.js]"]
  node_user_routes["User routes<br/>[user.route.js]"]
  node_post_routes["Post routes<br/>[post.route.js]"]
  node_comment_routes["Comment routes<br/>[comment.route.js]"]
  node_fotd_routes["FOTD routes<br/>[fotd.route.js]"]
end

subgraph group_identity["Identity and users"]
  node_auth_controller["Authentication<br/>[auth.controller.js]"]
  node_user_controller["User management<br/>[user.controller.js]"]
  node_token_middleware["Token verification<br/>[verifyUser.js]"]
  node_user_model["User model<br/>[user.model.js]"]
end

subgraph group_publishing["Blog and comments"]
  node_post_controller["Post management<br/>[post.controller.js]"]
  node_post_model["Post model<br/>[post.model.js]"]
  node_comment_controller["Comment management"]
  node_comment_model["Comment model<br/>[comment.model.js]"]
end

subgraph group_fruit["Fruit recommendations"]
  node_fotd_controller["Daily fruit<br/>[fotd.controller.js]"]
  node_fruit_model["Fruit model<br/>[fruit.model.js]"]
end

node_client(("API client"))
node_mongodb[("MongoDB")]
node_gemini{{"Gemini AI"}}

node_client -->|"sends requests"| node_app
node_app -->|"mounts routes"| node_auth_routes
node_app -->|"mounts routes"| node_user_routes
node_app -->|"mounts routes"| node_post_routes
node_app -->|"mounts routes"| node_comment_routes
node_app -->|"mounts routes"| node_fotd_routes
node_app -->|"connects"| node_mongodb
node_auth_routes -->|"dispatches"| node_auth_controller
node_user_routes -->|"dispatches"| node_user_controller
node_user_routes -->|"verifies token"| node_token_middleware
node_post_routes -->|"dispatches"| node_post_controller
node_post_routes -->|"verifies token"| node_token_middleware
node_comment_routes -->|"dispatches"| node_comment_controller
node_comment_routes -->|"verifies token"| node_token_middleware
node_fotd_routes -->|"dispatches"| node_fotd_controller
node_auth_controller -->|"reads and writes"| node_user_model
node_user_controller -->|"reads and writes"| node_user_model
node_post_controller -->|"reads and writes"| node_post_model
node_comment_controller -->|"reads and writes"| node_comment_model
node_fotd_controller -->|"checks and saves"| node_fruit_model
node_user_model -->|"persists users"| node_mongodb
node_post_model -->|"persists posts"| node_mongodb
node_comment_model -->|"persists comments"| node_mongodb
node_fruit_model -->|"persists fruit"| node_mongodb
node_fotd_controller -->|"generates recommendation"| node_gemini

click node_app "https://github.com/shaorankun/blogfruits-api/blob/main/index.js"
click node_auth_routes "https://github.com/shaorankun/blogfruits-api/blob/main/routes/auth.route.js"
click node_user_routes "https://github.com/shaorankun/blogfruits-api/blob/main/routes/user.route.js"
click node_post_routes "https://github.com/shaorankun/blogfruits-api/blob/main/routes/post.route.js"
click node_comment_routes "https://github.com/shaorankun/blogfruits-api/blob/main/routes/comment.route.js"
click node_fotd_routes "https://github.com/shaorankun/blogfruits-api/blob/main/routes/fotd.route.js"
click node_auth_controller "https://github.com/shaorankun/blogfruits-api/blob/main/controllers/auth.controller.js"
click node_user_controller "https://github.com/shaorankun/blogfruits-api/blob/main/controllers/user.controller.js"
click node_token_middleware "https://github.com/shaorankun/blogfruits-api/blob/main/utils/verifyUser.js"
click node_user_model "https://github.com/shaorankun/blogfruits-api/blob/main/models/user.model.js"
click node_post_controller "https://github.com/shaorankun/blogfruits-api/blob/main/controllers/post.controller.js"
click node_post_model "https://github.com/shaorankun/blogfruits-api/blob/main/models/post.model.js"
click node_comment_controller "https://github.com/shaorankun/blogfruits-api/blob/main/controllers/comment.controller.js"
click node_comment_model "https://github.com/shaorankun/blogfruits-api/blob/main/models/comment.model.js"
click node_fotd_controller "https://github.com/shaorankun/blogfruits-api/blob/main/controllers/fotd.controller.js"
click node_fruit_model "https://github.com/shaorankun/blogfruits-api/blob/main/models/fruit.model.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_auth_routes,node_user_routes,node_post_routes,node_comment_routes,node_fotd_routes,node_client toneBlue
class node_auth_controller,node_user_controller,node_token_middleware,node_user_model,node_mongodb toneAmber
class node_post_controller,node_post_model,node_comment_controller,node_comment_model toneMint
class node_fotd_controller,node_fruit_model toneRose
class node_gemini toneIndigo
```

## Components

### API application

- [Express app](https://github.com/shaorankun/blogfruits-api/blob/main/index.js): `index.js`
- [Auth routes](https://github.com/shaorankun/blogfruits-api/blob/main/routes/auth.route.js): `routes/auth.route.js`
- [User routes](https://github.com/shaorankun/blogfruits-api/blob/main/routes/user.route.js): `routes/user.route.js`
- [Post routes](https://github.com/shaorankun/blogfruits-api/blob/main/routes/post.route.js): `routes/post.route.js`
- [Comment routes](https://github.com/shaorankun/blogfruits-api/blob/main/routes/comment.route.js): `routes/comment.route.js`
- [FOTD routes](https://github.com/shaorankun/blogfruits-api/blob/main/routes/fotd.route.js): `routes/fotd.route.js`

### Identity and users

- [Authentication](https://github.com/shaorankun/blogfruits-api/blob/main/controllers/auth.controller.js): `controllers/auth.controller.js`
- [User management](https://github.com/shaorankun/blogfruits-api/blob/main/controllers/user.controller.js): `controllers/user.controller.js`
- [Token verification](https://github.com/shaorankun/blogfruits-api/blob/main/utils/verifyUser.js): `utils/verifyUser.js`
- [User model](https://github.com/shaorankun/blogfruits-api/blob/main/models/user.model.js): `models/user.model.js`

### Blog and comments

- [Post management](https://github.com/shaorankun/blogfruits-api/blob/main/controllers/post.controller.js): `controllers/post.controller.js`
- [Post model](https://github.com/shaorankun/blogfruits-api/blob/main/models/post.model.js): `models/post.model.js`
- [Comment management](https://github.com/shaorankun/blogfruits-api/blob/main/controllers/comment.controller.js): `controllers/comment.controller.js`
- [Comment model](https://github.com/shaorankun/blogfruits-api/blob/main/models/comment.model.js): `models/comment.model.js`

### Fruit recommendations

- [Daily fruit](https://github.com/shaorankun/blogfruits-api/blob/main/controllers/fotd.controller.js): `controllers/fotd.controller.js`
- [Fruit model](https://github.com/shaorankun/blogfruits-api/blob/main/models/fruit.model.js): `models/fruit.model.js`

### Other components

- **API client**
- **MongoDB**
- **Gemini AI**

## Connections

- API client → Express app: sends requests
- Express app → Auth routes: mounts routes
- Express app → User routes: mounts routes
- Express app → Post routes: mounts routes
- Express app → Comment routes: mounts routes
- Express app → FOTD routes: mounts routes
- Express app → MongoDB: connects
- Auth routes → Authentication: dispatches
- User routes → User management: dispatches
- User routes → Token verification: verifies token
- Post routes → Post management: dispatches
- Post routes → Token verification: verifies token
- Comment routes → Comment management: dispatches
- Comment routes → Token verification: verifies token
- FOTD routes → Daily fruit: dispatches
- Authentication → User model: reads and writes
- User management → User model: reads and writes
- Post management → Post model: reads and writes
- Comment management → Comment model: reads and writes
- Daily fruit → Fruit model: checks and saves
- User model → MongoDB: persists users
- Post model → MongoDB: persists posts
- Comment model → MongoDB: persists comments
- Fruit model → MongoDB: persists fruit
- Daily fruit → Gemini AI: generates recommendation
