How devfullcycle/mba-ia-desafio-design-docs-com-ia works
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: database.ts Prisma DB · app.ts App · index.ts Routes · validate.middleware.ts Validate mw
Components 22
Runtime
Process boot, HTTP assembly, and request handling
Domain modules
Business capabilities exposed through routers, controllers, services, and repositories
- Auth · Login and token flows
src/modules/auth/auth.routes.ts - Users · User account management
src/modules/users/user.routes.ts - Customers · Customer records
src/modules/customers/customer.routes.ts - Products · Product catalog data
src/modules/products/product.routes.ts - Orders · Order lifecycle and invariants
src/modules/orders/order.routes.ts - Order status · Controlled order state machine
src/modules/orders/order.status.ts
Platform
Cross-cutting middleware and shared support code
- Auth mw · Authentication and authorization gate
src/middlewares/auth.middleware.ts - Validate mw · Request schema validation
src/middlewares/validate.middleware.ts - Error mw · Central error translation
src/middlewares/error.middleware.ts - Logger mw · Request observability
src/middlewares/request-logger.middleware.ts - Errors · Application and HTTP error types
src/shared/errors/index.ts - Response · Common response envelope/helpers
src/shared/http/response.ts - Logger · Centralized logging utilities
src/shared/logger/index.ts
Data
Persistence schema, migrations, and seeding
- Prisma DB · Prisma client and relational persistence
src/config/database.ts - Schema · Database schema definition
prisma/schema.prisma - Migrations · Versioned database changes
prisma/migrations/20260519182739_init/migration.sql - Seed · Initial database seed
prisma/seed.ts
Connections 31
- 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