# devfullcycle/mba-ia-desafio-design-docs-com-ia architecture

> Architecture diagram of the GitHub repository devfullcycle/mba-ia-desafio-design-docs-com-ia, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devfullcycle/mba-ia-desafio-design-docs-com-ia
- Repository: https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia

## Overview

1. **What this repository is**
This is a backend OMS (Order Management System) written in **Node.js + TypeScript**, centered on an HTTP API. The codebase is organized as a modular monolith: each business area lives in its own module under `src/modules/`, while cross-cutting concerns sit in `src/middlewares/`, `src/shared/`, and `src/config/`.

2. **Runtime and infrastructure**
The application uses **Prisma** as its database layer with a relational database configured via `prisma/schema.prisma`, migrations, and seed data. The presence of `docker-compose.yml` suggests a local containerized database/runtime setup. Environment configuration is separated in `src/config/env.ts` and DB bootstrap in `src/config/database.ts`.

3. **Request lifecycle**
The HTTP flow is: `src/server.ts` boots the process, `src/app.ts` assembles middleware and routes, and `src/routes/index.ts` composes the module routers. A request then passes through middlewares such as authentication, validation, and request logging before reaching a controller.

4. **Module boundaries**
Business functionality is split by domain:
- `auth` for login/token-related flows
- `users` for account management
- `customers` for customer records
- `products` for catalog data
- `orders` for order lifecycle operations

Each module follows a similar pattern: `*.routes.ts` defines endpoints, `*.controller.ts` handles HTTP concerns, `*.service.ts` contains business logic, and where needed `*.repository.ts` encapsulates database access. Schemas are separated into `*.schemas.ts`, indicating request/response validation or contract definitions.

5. **Order subsystem is the core domain**
The `orders` module is the most likely centerpiece of the OMS. It has a dedicated `order.status.ts`, which implies a controlled order state machine rather than free-form status updates. Given the repo description in the README, order changes likely include transactional stock handling and status audit behavior. That makes the orders module the main place where domain invariants are enforced.

6. **Persistence boundary**
Database access is abstracted through Prisma and repository classes in the domain modules. This creates a clear boundary: controllers and services do not talk directly to the database schema; instead, modules mediate persistence through repositories and the Prisma client. The `prisma/migrations/` folder shows the schema is evolved through migrations rather than ad hoc SQL.

7. **Cross-cutting middleware layer**
The middleware layer centralizes platform concerns:
- `auth.middleware.ts` for authentication/authorization
- `validate.middleware.ts` for request validation
- `error.middleware.ts` for centralized error translation
- `request-logger.middleware.ts` for request observability

This is important architecturally because it keeps domain modules focused on business rules and pushes HTTP, validation, and error formatting concerns out to shared infrastructure.

8. **Shared utilities and error model**
`src/shared/errors/` defines application and HTTP error types, which likely standardize error codes and status mapping across all modules. `src/shared/http/response.ts` suggests a common response envelope or helper, and `src/shared/logger/` indicates logging is centralized rather than ad hoc per module. This is the main shared runtime support layer.

9. **Auth and access control**
Authentication is isolated in its own module, rather than being embedded in users or orders. Combined with the auth middleware, this implies a clear boundary between identity concerns and business operations. The repository likely uses auth to protect module routes and enforce role-based access where needed.

10. **Tests and quality gate**
Tests are organized under `tests/` using **Vitest** (`vitest.config.ts`). There are focused integration/unit tests such as `auth.test.ts` and `orders.test.ts`, plus shared test setup and factories. That indicates the repo validates behavior at the module boundary rather than only testing helpers in isolation.

11. **Tooling and code hygiene**
The repo uses TypeScript compilation configs (`tsconfig.json`, `tsconfig.build.json`) plus ESLint and Prettier. This suggests a conventional Node backend with static typing, linting, formatting, and build separation between development and production output.

12. **Documentation sub-tree is separate from runtime**
The `docs/` directory and the repository root `README.md` are not part of the executable application; they are documentation artifacts for the design-doc challenge. They coexist with the app but do not affect runtime architecture.

13. **How to diagram this repo**
A good architecture diagram would show:
- Client/HTTP entrypoint
- Middleware pipeline
- Modular domain routers/controllers/services/repositories
- Prisma/MySQL persistence
- Shared error/logging utilities
- Test and migration/tooling sidecars

The key boundary is between **HTTP/platform concerns** and **domain business logic**, with **orders** as the most stateful and transaction-heavy subsystem.

Main entry points: [`src/config/database.ts`](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/config/database.ts) (Prisma DB), [`src/app.ts`](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/app.ts) (App), [`src/routes/index.ts`](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/routes/index.ts) (Routes), [`src/middlewares/validate.middleware.ts`](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/middlewares/validate.middleware.ts) (Validate mw)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_server(("Server<br/>bootstrap<br/>[server.ts]"))
  node_app["App<br/>http composition<br/>[app.ts]"]
  node_routes_index["Routes<br/>router composition<br/>[index.ts]"]
end

subgraph group_domain["Domain modules"]
  node_auth_mod["Auth<br/>identity module<br/>[auth.routes.ts]"]
  node_users_mod["Users<br/>account module<br/>[user.routes.ts]"]
  node_customers_mod["Customers<br/>customer module<br/>[customer.routes.ts]"]
  node_products_mod["Products<br/>catalog module<br/>[product.routes.ts]"]
  node_orders_mod["Orders<br/>order module<br/>[order.routes.ts]"]
  node_order_status["Order status<br/>state model<br/>[order.status.ts]"]
end

subgraph group_platform["Platform"]
  node_auth_mw["Auth mw<br/>auth middleware<br/>[auth.middleware.ts]"]
  node_validate_mw["Validate mw<br/>validation middleware"]
  node_error_mw["Error mw<br/>error middleware"]
  node_logger_mw["Logger mw<br/>request logger"]
  node_shared_errors["Errors<br/>error model<br/>[index.ts]"]
  node_shared_response["Response<br/>http helper<br/>[response.ts]"]
  node_shared_logger["Logger<br/>logging support<br/>[index.ts]"]
end

subgraph group_data["Data"]
  node_prisma_db[("Prisma DB<br/>database layer<br/>[database.ts]")]
  node_schema["Schema<br/>[schema.prisma]"]
  node_migrations["Migrations<br/>schema evolution<br/>[migration.sql]"]
  node_seed["Seed<br/>bootstrap data<br/>[seed.ts]"]
end

subgraph group_quality["Quality"]
  node_tests["Tests<br/>vitest suite<br/>[auth.test.ts]"]
  node_tooling["Tooling<br/>dev config<br/>[vitest.config.ts]"]
end

node_server -->|"boots"| node_app
node_app -->|"mounts"| node_routes_index
node_app -->|"uses"| node_auth_mw
node_app -->|"uses"| node_validate_mw
node_app -->|"uses"| node_error_mw
node_app -->|"uses"| node_logger_mw
node_error_mw -->|"formats"| node_shared_errors
node_routes_index -->|"routes"| node_auth_mod
node_routes_index -->|"routes"| node_users_mod
node_routes_index -->|"routes"| node_customers_mod
node_routes_index -->|"routes"| node_products_mod
node_routes_index -->|"routes"| node_orders_mod
node_auth_mod -->|"validates"| node_validate_mw
node_users_mod -->|"validates"| node_validate_mw
node_customers_mod -->|"validates"| node_validate_mw
node_products_mod -->|"validates"| node_validate_mw
node_orders_mod -->|"validates"| node_validate_mw
node_auth_mod -->|"responds"| node_shared_response
node_orders_mod -->|"depends on"| node_order_status
node_auth_mod -->|"persists"| node_prisma_db
node_users_mod -->|"persists"| node_prisma_db
node_customers_mod -->|"persists"| node_prisma_db
node_products_mod -->|"persists"| node_prisma_db
node_orders_mod -->|"persists"| node_prisma_db
node_prisma_db -->|"defined by"| node_schema
node_schema -->|"evolves via"| node_migrations
node_prisma_db -->|"initialized by"| node_seed
node_tests -->|"covers"| node_auth_mod
node_tests -->|"covers"| node_orders_mod
node_tooling -->|"runs"| node_tests
node_tooling -.->|"builds"| node_server

click node_server "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/server.ts"
click node_app "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/app.ts"
click node_routes_index "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/routes/index.ts"
click node_auth_mw "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/middlewares/auth.middleware.ts"
click node_validate_mw "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/middlewares/validate.middleware.ts"
click node_error_mw "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/middlewares/error.middleware.ts"
click node_logger_mw "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/middlewares/request-logger.middleware.ts"
click node_shared_errors "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/shared/errors/index.ts"
click node_shared_response "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/shared/http/response.ts"
click node_shared_logger "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/shared/logger/index.ts"
click node_auth_mod "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/auth/auth.routes.ts"
click node_users_mod "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/users/user.routes.ts"
click node_customers_mod "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/customers/customer.routes.ts"
click node_products_mod "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/products/product.routes.ts"
click node_orders_mod "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/orders/order.routes.ts"
click node_order_status "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/orders/order.status.ts"
click node_prisma_db "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/config/database.ts"
click node_schema "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/prisma/schema.prisma"
click node_migrations "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/prisma/migrations/20260519182739_init/migration.sql"
click node_seed "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/prisma/seed.ts"
click node_tests "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/tests/auth.test.ts"
click node_tooling "https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/vitest.config.ts"

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_server,node_app,node_routes_index toneBlue
class node_auth_mod,node_users_mod,node_customers_mod,node_products_mod,node_orders_mod,node_order_status toneAmber
class node_auth_mw,node_validate_mw,node_error_mw,node_logger_mw,node_shared_errors,node_shared_response,node_shared_logger toneMint
class node_prisma_db,node_schema,node_migrations,node_seed toneRose
class node_tests,node_tooling toneIndigo
```

## Components

### Runtime

Process boot, HTTP assembly, and request handling

- [Server](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/server.ts): bootstrap · Process entrypoint · `src/server.ts`
- [App](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/app.ts): http composition · Assembles middleware and routing · `src/app.ts`
- [Routes](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/routes/index.ts): router composition · Mounts module routers · `src/routes/index.ts`

### Domain modules

Business capabilities exposed through routers, controllers, services, and repositories

- [Auth](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/auth/auth.routes.ts): identity module · Login and token flows · `src/modules/auth/auth.routes.ts`
- [Users](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/users/user.routes.ts): account module · User account management · `src/modules/users/user.routes.ts`
- [Customers](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/customers/customer.routes.ts): customer module · Customer records · `src/modules/customers/customer.routes.ts`
- [Products](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/products/product.routes.ts): catalog module · Product catalog data · `src/modules/products/product.routes.ts`
- [Orders](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/orders/order.routes.ts): order module · Order lifecycle and invariants · `src/modules/orders/order.routes.ts`
- [Order status](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/modules/orders/order.status.ts): state model · Controlled order state machine · `src/modules/orders/order.status.ts`

### Platform

Cross-cutting middleware and shared support code

- [Auth mw](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/middlewares/auth.middleware.ts): auth middleware · Authentication and authorization gate · `src/middlewares/auth.middleware.ts`
- [Validate mw](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/middlewares/validate.middleware.ts): validation middleware · Request schema validation · `src/middlewares/validate.middleware.ts`
- [Error mw](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/middlewares/error.middleware.ts): error middleware · Central error translation · `src/middlewares/error.middleware.ts`
- [Logger mw](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/middlewares/request-logger.middleware.ts): request logger · Request observability · `src/middlewares/request-logger.middleware.ts`
- [Errors](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/shared/errors/index.ts): error model · Application and HTTP error types · `src/shared/errors/index.ts`
- [Response](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/shared/http/response.ts): http helper · Common response envelope/helpers · `src/shared/http/response.ts`
- [Logger](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/shared/logger/index.ts): logging support · Centralized logging utilities · `src/shared/logger/index.ts`

### Data

Persistence schema, migrations, and seeding

- [Prisma DB](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/src/config/database.ts): database layer · Prisma client and relational persistence · `src/config/database.ts`
- [Schema](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/prisma/schema.prisma): prisma schema · Database schema definition · `prisma/schema.prisma`
- [Migrations](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/prisma/migrations/20260519182739_init/migration.sql): schema evolution · Versioned database changes · `prisma/migrations/20260519182739_init/migration.sql`
- [Seed](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/prisma/seed.ts): bootstrap data · Initial database seed · `prisma/seed.ts`

### Quality

Tests and development tooling

- [Tests](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/tests/auth.test.ts): vitest suite · Module-level verification · `tests/auth.test.ts`
- [Tooling](https://github.com/devfullcycle/mba-ia-desafio-design-docs-com-ia/blob/main/vitest.config.ts): dev config · TypeScript, lint, format, and test config · `vitest.config.ts`

## Connections

- Server → App: boots · Starts the HTTP application
- App → Routes: mounts · Composes the router tree
- App → Auth mw: uses · Applies auth gating
- App → Validate mw: uses · Applies request validation
- App → Error mw: uses · Applies centralized error handling
- App → Logger mw: uses · Applies request logging
- Error mw → Errors: formats · Maps application errors to HTTP responses
- Routes → Auth: routes · Registers auth endpoints
- Routes → Users: routes · Registers user endpoints
- Routes → Customers: routes · Registers customer endpoints
- Routes → Products: routes · Registers product endpoints
- Routes → Orders: routes · Registers order endpoints
- Auth → Validate mw: validates · Validates auth requests
- Users → Validate mw: validates · Validates user requests
- Customers → Validate mw: validates · Validates customer requests
- Products → Validate mw: validates · Validates product requests
- Orders → Validate mw: validates · Validates order requests
- Auth → Response: responds · Uses shared response helpers
- Orders → Order status: depends on · Encodes order state transitions
- Auth → Prisma DB: persists · Reads/writes through Prisma
- Users → Prisma DB: persists · Reads/writes through Prisma
- Customers → Prisma DB: persists · Reads/writes through Prisma
- Products → Prisma DB: persists · Reads/writes through Prisma
- Orders → Prisma DB: persists · Transactional order data access
- Prisma DB → Schema: defined by · Schema drives the generated client
- Schema → Migrations: evolves via · Schema changes are versioned by migrations
- Prisma DB → Seed: initialized by · Seed data populates local environments
- Tests → Auth: covers · Verifies auth behavior
- Tests → Orders: covers · Verifies order behavior
- Tooling → Tests: runs · Vitest executes the suite
- Tooling → Server: builds · TypeScript compile and runtime tooling support
