Unsaved
Ready
Loading Monaco Editor...
Preview
Styling
Flowchart
All Documentation templates

REST API Architecture — Mermaid Flowchart

Flowchart documenting a REST API architecture with middleware layers, controllers, services, and data access.

What this diagram shows

This Mermaid flowchart is one HTTP request through a layered API. CORS runs, then a rate limiter, then auth. A missing token returns 401 and stops. A valid token hits a router that chooses the user, product, or order controller. Each controller calls its service. Services share a validation layer. Validation asks the cache: a hit returns cached data, a miss goes to the repository, the ORM, and PostgreSQL. A miss also writes Redis. The response subgraph lists 200, 201, 400, 404, and 500 as the status boxes the layers can return.

Use it in an API README when new endpoints keep skipping a layer. The chart makes the shared path obvious: every controller goes through validation and the cache before the database. It does not show a specific URL. The three controllers are examples of the pattern. The status boxes are not wired to the layers with edges, so they read as a legend of outcomes rather than a trace of one call.

Redis is updated only on the miss path, after the repository returns. A hit never touches PostgreSQL in this drawing.

Mermaid syntax in this template

flowchart TD plus one subgraph named Response. The cache diamond is the only branch after validation. Auth is the earlier branch.

  • Auth -->|No Token| R401[401 Unauthorized]

    The failure edge names the status. The valid edge continues to the router.

  • Cache{Cache Hit?}

    Yes returns cached data. No enters the repository. Both product and user services reach this same diamond via validation.

  • subgraph Response

    Groups the status codes. They have no incoming edges in the template, so they document the vocabulary.

  • ORM --> DB[(PostgreSQL)]

    The cylinder is the database. Redis is a second cylinder on the writeback path.

Variations and ways to customize it

Wire a validation failure to 400

The 400 box sits in the legend. Connect validation to it so a bad body does not look like it reaches the cache.

Validate -->|Invalid| R400[400 Bad Request]
Validate -->|Valid| Cache{Cache Hit?}

Add a version prefix

Put a node before the router for /v1 versus /v2 if this chart is the companion to the versioning class diagram. The middleware order stays in front of it.

Auth -->|Valid Token| Version{Path}
Version -->|/v1| Router
Version -->|/v2| Router

Show the cache key

The hit path is unlabeled. A note or a longer node label such as Return Cached Data by resource id tells the reader what the key is.

Diagram type

Flowchart

Tags

REST APIarchitecturemiddlewarebackenddocumentation
Open in Editor

Frequently asked questions

In what order does a request pass middleware?

CORS, then the rate limiter, then auth. Only a valid token reaches the router. A missing token returns 401 and does not call a controller.

When does this API read PostgreSQL?

On a cache miss. The path is repository, ORM, PostgreSQL, then a write to Redis. A cache hit returns from the cache node and does not touch the database.

Are the status codes connected to the flow?

Only 401 is connected, from the auth diamond. 200, 201, 400, 404, and 500 sit in a subgraph as a legend. Draw edges to them if you want each error to have a source.

How do I add another resource?

Add a controller and a service, and point the service at the existing validation node. Do not give it a private path to the database or the chart stops being the standard layering.

Related templates and guides

All Documentation templates