# energyshifter8/rest-api-guide architecture

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

- Interactive diagram: https://gitdiagram.com/energyshifter8/rest-api-guide
- Repository: https://github.com/energyshifter8/rest-api-guide

## Overview

This is a small Rails API for JSON CRUD on posts and nested comments. Clients send HTTP requests through Rails routes to the corresponding controller; controllers validate permitted fields, invoke Active Record models, and return JSON results. The models enforce the documented post/comment relationship and validations, with persistence in MySQL. The README also identifies a Swagger UI and OpenAPI specification. The sampled sources show CRUD calls; the documentation describes the database and Swagger capabilities, but their runtime wiring was not sampled.

Main entry points: [`app/controllers/comments_controller.rb`](https://github.com/energyshifter8/rest-api-guide/blob/master/app/controllers/comments_controller.rb) (Comments controller), [`config/routes.rb`](https://github.com/energyshifter8/rest-api-guide/blob/master/config/routes.rb) (REST routes), [`app/controllers/posts_controller.rb`](https://github.com/energyshifter8/rest-api-guide/blob/master/app/controllers/posts_controller.rb) (Posts controller), [`app/models/post.rb`](https://github.com/energyshifter8/rest-api-guide/blob/master/app/models/post.rb) (Post model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API handling"]
  node_routes["REST routes<br/>[routes.rb]"]
  node_posts_controller["Posts controller"]
  node_comments_controller["Comments controller"]
  node_application_controller["API error handling"]
end

subgraph group_domain["Post and comment domain"]
  node_post["Post model<br/>[post.rb]"]
  node_comment["Comment model<br/>[comment.rb]"]
end

subgraph group_docs["API documentation"]
  node_swagger["Swagger UI<br/>[index.html]"]
  node_openapi["OpenAPI specification<br/>[openapi.yaml]"]
end

node_client(("API client"))
node_mysql[("MySQL database")]

node_client -->|"sends HTTP"| node_routes
node_routes -->|"routes requests"| node_posts_controller
node_routes -->|"routes requests"| node_comments_controller
node_posts_controller -->|"queries and updates"| node_post
node_comments_controller -->|"finds parent"| node_post
node_comments_controller -->|"queries and updates"| node_comment
node_post -->|"persists records"| node_mysql
node_comment -->|"persists records"| node_mysql
node_posts_controller -->|"returns JSON"| node_client
node_comments_controller -->|"returns JSON"| node_client
node_client -->|"explores endpoints"| node_swagger

click node_routes "https://github.com/energyshifter8/rest-api-guide/blob/master/config/routes.rb"
click node_posts_controller "https://github.com/energyshifter8/rest-api-guide/blob/master/app/controllers/posts_controller.rb"
click node_comments_controller "https://github.com/energyshifter8/rest-api-guide/blob/master/app/controllers/comments_controller.rb"
click node_application_controller "https://github.com/energyshifter8/rest-api-guide/blob/master/app/controllers/application_controller.rb"
click node_post "https://github.com/energyshifter8/rest-api-guide/blob/master/app/models/post.rb"
click node_comment "https://github.com/energyshifter8/rest-api-guide/blob/master/app/models/comment.rb"
click node_swagger "https://github.com/energyshifter8/rest-api-guide/blob/master/public/api-docs/index.html"
click node_openapi "https://github.com/energyshifter8/rest-api-guide/blob/master/public/api-docs/openapi.yaml"

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_routes,node_posts_controller,node_comments_controller,node_application_controller,node_client toneBlue
class node_post,node_comment,node_mysql toneAmber
class node_swagger,node_openapi toneMint
```

## Components

### API handling

- [REST routes](https://github.com/energyshifter8/rest-api-guide/blob/master/config/routes.rb): `config/routes.rb`
- [Posts controller](https://github.com/energyshifter8/rest-api-guide/blob/master/app/controllers/posts_controller.rb): `app/controllers/posts_controller.rb`
- [Comments controller](https://github.com/energyshifter8/rest-api-guide/blob/master/app/controllers/comments_controller.rb): `app/controllers/comments_controller.rb`
- [API error handling](https://github.com/energyshifter8/rest-api-guide/blob/master/app/controllers/application_controller.rb): `app/controllers/application_controller.rb`

### Post and comment domain

- [Post model](https://github.com/energyshifter8/rest-api-guide/blob/master/app/models/post.rb): `app/models/post.rb`
- [Comment model](https://github.com/energyshifter8/rest-api-guide/blob/master/app/models/comment.rb): `app/models/comment.rb`

### API documentation

- [Swagger UI](https://github.com/energyshifter8/rest-api-guide/blob/master/public/api-docs/index.html): `public/api-docs/index.html`
- [OpenAPI specification](https://github.com/energyshifter8/rest-api-guide/blob/master/public/api-docs/openapi.yaml): `public/api-docs/openapi.yaml`

### Other components

- **API client**
- **MySQL database**

## Connections

- API client → REST routes: sends HTTP (evidence: `README.md`)
- REST routes → Posts controller: routes requests (evidence: `README.md`)
- REST routes → Comments controller: routes requests (evidence: `README.md`)
- Posts controller → Post model: queries and updates (evidence: `app/controllers/posts_controller.rb`)
- Comments controller → Post model: finds parent (evidence: `app/controllers/comments_controller.rb`)
- Comments controller → Comment model: queries and updates (evidence: `app/controllers/comments_controller.rb`)
- Post model → MySQL database: persists records (evidence: `README.md`)
- Comment model → MySQL database: persists records (evidence: `README.md`)
- Posts controller → API client: returns JSON (evidence: `app/controllers/posts_controller.rb`)
- Comments controller → API client: returns JSON (evidence: `app/controllers/comments_controller.rb`)
- API client → Swagger UI: explores endpoints (evidence: `README.md`)
