# derektsc/oficina-tech-challenge architecture

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

- Interactive diagram: https://gitdiagram.com/derektsc/oficina-tech-challenge
- Repository: https://github.com/derektsc/oficina-tech-challenge

## Overview

Oficina API is a Rails backend for repair-shop service orders. The main workflow is operator authentication and order creation, followed by diagnosis, budget approval or rejection, execution, completion and delivery; clients can check status, while an external system can submit budget decisions. The API also exposes an ordered operational queue, catalog and customer administration, and execution-time metrics. The README documents email notifications and PostgreSQL. Some use-case internals and controller wiring were not excerpted, so those links rely on documented behavior rather than claims about unseen implementation.

Main entry points: [`app/controllers/api/v1/admin/service_orders_controller.rb`](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/service_orders_controller.rb) (Admin endpoints), [`app/models/service_order.rb`](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/models/service_order.rb) (Service orders), [`db/schema.rb`](https://github.com/derektsc/oficina-tech-challenge/blob/main/db/schema.rb) (PostgreSQL), [`app/controllers/api/v1/auth_controller.rb`](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/auth_controller.rb) (Login endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP interface"]
  node_admin_api["Admin endpoints"]
  node_public_api["Public endpoints"]
  node_integration_api["Budget webhook"]
  node_catalog_admin["Catalog admin"]
  node_parts_admin["Parts admin"]
  node_customers_admin["Customer admin"]
  node_vehicles_admin["Vehicle admin"]
  node_order_serializer["Order serializer"]
end

subgraph group_workflow["Order workflow"]
  node_create_order["Create order<br/>[create.rb]"]
  node_order_transitions["Order transitions<br/>[start_diagnosis.rb]"]
  node_budget_decisions["Budget decisions"]
  node_operational_queue["Operational queue"]
  node_execution_metrics["Execution metrics"]
end

subgraph group_domain["Domain and persistence"]
  node_service_order_model["Service orders<br/>[service_order.rb]"]
  node_domain_status["Status rules<br/>[status.rb]"]
  node_stock_control["Stock control<br/>[stock_control.rb]"]
  node_database[("PostgreSQL<br/>[schema.rb]")]
end

subgraph group_notify["Identity and notifications"]
  node_auth_api["Login endpoint<br/>[auth_controller.rb]"]
  node_jwt["JWT codec<br/>[json_web_token.rb]"]
  node_user_model["Users<br/>[user.rb]"]
  node_mailer["Status email"]
end

node_operator(("Operator"))
node_customer(("Customer"))
node_external_system(("External system"))

node_operator -->|"requests token"| node_auth_api
node_auth_api -->|"authenticates"| node_user_model
node_auth_api -->|"encodes token"| node_jwt
node_operator -->|"manages orders"| node_admin_api
node_customer -->|"checks status"| node_public_api
node_external_system -->|"sends decision"| node_integration_api
node_admin_api -->|"creates order"| node_create_order
node_admin_api -->|"advances order"| node_order_transitions
node_admin_api -->|"lists queue"| node_operational_queue
node_admin_api -.->|"requests metrics"| node_execution_metrics
node_public_api -.->|"decides budget"| node_budget_decisions
node_integration_api -.->|"applies decision"| node_budget_decisions
node_admin_api -->|"serializes response"| node_order_serializer
node_service_order_model -->|"checks transitions"| node_domain_status
node_create_order -.->|"creates records"| node_service_order_model
node_order_transitions -.->|"updates order"| node_service_order_model
node_budget_decisions -.->|"checks stock"| node_stock_control
node_service_order_model -->|"persists data"| node_database
node_catalog_admin -.->|"manages catalog"| node_database
node_parts_admin -.->|"manages parts"| node_database
node_customers_admin -.->|"manages customers"| node_database
node_vehicles_admin -.->|"manages vehicles"| node_database
node_service_order_model -.->|"notifies status"| node_mailer

click node_admin_api "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/service_orders_controller.rb"
click node_public_api "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/public/service_orders_controller.rb"
click node_integration_api "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/integrations/budget_notifications_controller.rb"
click node_catalog_admin "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/catalog_services_controller.rb"
click node_parts_admin "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/parts_controller.rb"
click node_customers_admin "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/customers_controller.rb"
click node_vehicles_admin "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/vehicles_controller.rb"
click node_create_order "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/use_cases/service_orders/create.rb"
click node_order_transitions "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/use_cases/service_orders/start_diagnosis.rb"
click node_budget_decisions "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/use_cases/service_orders/apply_external_budget_decision.rb"
click node_operational_queue "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/use_cases/service_orders/list_operational.rb"
click node_execution_metrics "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/use_cases/service_orders/average_execution_time.rb"
click node_order_serializer "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/serializers/service_order_serializer.rb"
click node_service_order_model "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/models/service_order.rb"
click node_domain_status "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/domain/service_orders/status.rb"
click node_stock_control "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/domain/inventory/stock_control.rb"
click node_database "https://github.com/derektsc/oficina-tech-challenge/blob/main/db/schema.rb"
click node_auth_api "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/auth_controller.rb"
click node_jwt "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/json_web_token.rb"
click node_user_model "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/models/user.rb"
click node_mailer "https://github.com/derektsc/oficina-tech-challenge/blob/main/app/mailers/service_order_mailer.rb"

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_admin_api,node_public_api,node_integration_api,node_catalog_admin,node_parts_admin,node_customers_admin,node_vehicles_admin,node_order_serializer toneBlue
class node_create_order,node_order_transitions,node_budget_decisions,node_operational_queue,node_execution_metrics toneAmber
class node_service_order_model,node_domain_status,node_stock_control,node_database toneMint
class node_auth_api,node_jwt,node_user_model,node_mailer toneRose
class node_operator,node_customer,node_external_system toneIndigo
```

## Components

### HTTP interface

- [Admin endpoints](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/service_orders_controller.rb): `app/controllers/api/v1/admin/service_orders_controller.rb`
- [Public endpoints](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/public/service_orders_controller.rb): `app/controllers/api/v1/public/service_orders_controller.rb`
- [Budget webhook](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/integrations/budget_notifications_controller.rb): `app/controllers/api/v1/integrations/budget_notifications_controller.rb`
- [Catalog admin](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/catalog_services_controller.rb): `app/controllers/api/v1/admin/catalog_services_controller.rb`
- [Parts admin](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/parts_controller.rb): `app/controllers/api/v1/admin/parts_controller.rb`
- [Customer admin](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/customers_controller.rb): `app/controllers/api/v1/admin/customers_controller.rb`
- [Vehicle admin](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/admin/vehicles_controller.rb): `app/controllers/api/v1/admin/vehicles_controller.rb`
- [Order serializer](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/serializers/service_order_serializer.rb): `app/serializers/service_order_serializer.rb`

### Order workflow

- [Create order](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/use_cases/service_orders/create.rb): `app/lib/use_cases/service_orders/create.rb`
- [Order transitions](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/use_cases/service_orders/start_diagnosis.rb): `app/lib/use_cases/service_orders/start_diagnosis.rb`
- [Budget decisions](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/use_cases/service_orders/apply_external_budget_decision.rb): `app/lib/use_cases/service_orders/apply_external_budget_decision.rb`
- [Operational queue](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/use_cases/service_orders/list_operational.rb): `app/lib/use_cases/service_orders/list_operational.rb`
- [Execution metrics](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/use_cases/service_orders/average_execution_time.rb): `app/lib/use_cases/service_orders/average_execution_time.rb`

### Domain and persistence

- [Service orders](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/models/service_order.rb): `app/models/service_order.rb`
- [Status rules](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/domain/service_orders/status.rb): `app/lib/domain/service_orders/status.rb`
- [Stock control](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/domain/inventory/stock_control.rb): `app/lib/domain/inventory/stock_control.rb`
- [PostgreSQL](https://github.com/derektsc/oficina-tech-challenge/blob/main/db/schema.rb): `db/schema.rb`

### Identity and notifications

- [Login endpoint](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/controllers/api/v1/auth_controller.rb): `app/controllers/api/v1/auth_controller.rb`
- [JWT codec](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/lib/json_web_token.rb): `app/lib/json_web_token.rb`
- [Users](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/models/user.rb): `app/models/user.rb`
- [Status email](https://github.com/derektsc/oficina-tech-challenge/blob/main/app/mailers/service_order_mailer.rb): `app/mailers/service_order_mailer.rb`

### Other components

- **Operator**
- **Customer**
- **External system**

## Connections

- Operator → Login endpoint: requests token (evidence: `README.md`)
- Login endpoint → Users: authenticates (evidence: `app/controllers/api/v1/auth_controller.rb`)
- Login endpoint → JWT codec: encodes token (evidence: `app/controllers/api/v1/auth_controller.rb`)
- Operator → Admin endpoints: manages orders (evidence: `README.md`)
- Customer → Public endpoints: checks status (evidence: `README.md`)
- External system → Budget webhook: sends decision (evidence: `README.md`)
- Admin endpoints → Create order: creates order (evidence: `app/controllers/api/v1/admin/service_orders_controller.rb`)
- Admin endpoints → Order transitions: advances order (evidence: `app/controllers/api/v1/admin/service_orders_controller.rb`)
- Admin endpoints → Operational queue: lists queue (evidence: `app/controllers/api/v1/admin/service_orders_controller.rb`)
- Admin endpoints → Execution metrics: requests metrics
- Public endpoints → Budget decisions: decides budget (evidence: `README.md`)
- Budget webhook → Budget decisions: applies decision (evidence: `README.md`)
- Admin endpoints → Order serializer: serializes response (evidence: `app/controllers/api/v1/admin/service_orders_controller.rb`)
- Service orders → Status rules: checks transitions (evidence: `app/models/service_order.rb`)
- Create order → Service orders: creates records
- Order transitions → Service orders: updates order
- Budget decisions → Stock control: checks stock
- Service orders → PostgreSQL: persists data (evidence: `README.md`)
- Catalog admin → PostgreSQL: manages catalog
- Parts admin → PostgreSQL: manages parts
- Customer admin → PostgreSQL: manages customers
- Vehicle admin → PostgreSQL: manages vehicles
- Service orders → Status email: notifies status (evidence: `README.md`)
