Integrated Management System
Technical Documentation for Developers – v1.0
Introduction
This document serves as the single source of truth for all technical decisions, architecture, and step-by-step development plans for the Integrated Management System. It is intended for current and future developers working on the project.
Languages: UI in Portuguese (pt-BR), code/comments in English.
Development model: Monorepo, full-stack separated (Next.js + NestJS), containerized.
🎯 Primary Goal
Build a scalable, maintainable, and modular system that can grow with the company, starting from a solid foundation.
Approved Technology Stack
🖥️ Frontend
- Next.js 14+ (App Router)
- TypeScript 5+
- Tailwind CSS (custom theme)
- TanStack Query v5
- Zustand (UI state)
- i18next (pt-BR)
- React Hook Form + Zod
⚙️ Backend
- NestJS 10+
- TypeScript 5+
- Prisma ORM (latest)
- MySQL 8
- JWT (access + refresh)
- class-validator / class-transformer
- Swagger/OpenAPI
Architecture Overview
Monorepo Structure (Turborepo + pnpm)
/
├── apps/
│ ├── web/ # Next.js frontend
│ └── api/ # NestJS backend
├── packages/
│ ├── config/ # shared configs (eslint, tsconfig)
│ └── types/ # shared TypeScript types
├── docker-compose.yml
├── turbo.json
├── pnpm-workspace.yaml
└── package.json
Communication: REST API with JSON, JWT authentication.
Database: MySQL via Prisma ORM, with migrations.
Environment Variables
| Variable | App | Description |
|---|---|---|
DATABASE_URL | api | Prisma connection string |
JWT_SECRET | api | Secret for access tokens |
JWT_REFRESH_SECRET | api | Secret for refresh tokens |
NEXT_PUBLIC_API_URL | web | Base URL of backend API |
Frontend Development Plan
Phase 1: Setup (Steps 1-10)
- Create workspace with
pnpm initandturbo.json. - Initialize
apps/webusingcreate-next-appwith TypeScript and App Router. - Configure Tailwind CSS with custom colors (primary orange palette).
- Install dependencies:
@tanstack/react-query,zustand,i18next,react-hook-form,zod. - Set up ESLint and Prettier with shared config from
packages/config. - Create base folder structure:
components/,app/,lib/,hooks/,types/. - Implement root layout with Inter font and metadata in pt-BR.
- Configure i18next (initial locale pt-BR).
- Create reusable Button component and a sample form with Tailwind + Zod validation.
- Verify dev server runs and production build succeeds.
Phase 2: Authentication & Layout (Steps 1-8)
- Design login page (email/password).
- Create registration page (company basic data).
- Implement API calls for auth using React Query.
- Configure Zustand store for session state (token, user).
- Protect private routes (Next.js middleware).
- Create dashboard layout (sidebar, header, content area).
- Implement logout and automatic token refresh.
- Add error handling and toast notifications.
Phase 3: First Business Module (Steps 1-10)
- Decide module (suggest "Users" or "Clients").
- Create listing page with table (server or client component).
- Implement pagination and search with React Query.
- Create create/edit form (modal or separate page).
- Integrate validation with Zod and React Hook Form.
- Connect to backend endpoints (GET, POST, PUT, DELETE).
- Add loading states and skeletons.
- Implement delete confirmation.
- Add visual feedback (success/error).
- Review responsiveness and basic accessibility.
Backend Development Plan
Phase 1: Setup (Steps 1-10)
- Create
apps/apiwith NestJS CLI. - Configure environment variables with
@nestjs/config. - Install Prisma and set up MySQL client.
- Define initial Prisma schema (
User,Companymodels). - Run first migration against local Docker MySQL.
- Set up Swagger for automatic API documentation.
- Install and configure
class-validatorandclass-transformer. - Create HealthController for status checks.
- Configure CORS for frontend origin.
- Verify API starts and responds correctly.
Phase 2: Authentication & Users (Steps 1-10)
- Create
Authmodule with controller and service. - Implement company + admin user registration.
- Generate JWT access/refresh tokens with
@nestjs/jwt. - Create Passport JWT strategy.
- Protect routes with custom guards.
- Implement login endpoint (validate credentials, return tokens).
- Create refresh token endpoint.
- Implement logout (invalidate refresh token).
- Add DTO validation with global pipes.
- Document endpoints in Swagger with examples.
Phase 3: CRUD & Roles (Steps 1-10)
- Create
Usersmodule (controller, service, repository via Prisma). - Define DTOs for create, update, response.
- Implement endpoints: list (paginated), get by ID, create, update, delete.
- Add search filters.
- Create
Rolesmodule with basic CRUD. - Associate roles to users (many-to-many).
- Implement role guard for authorization.
- Add centralized exception handling (filters).
- Write unit tests for core services.
- Manual test with Swagger and adjust.
Coding Standards & Conventions
- TypeScript strict mode enabled in all projects.
- Use functional components and hooks; avoid class components.
- Naming:
camelCasefor variables/functions,PascalCasefor components/classes,UPPER_SNAKE_CASEfor constants. - All backend DTOs must use validation decorators from
class-validator. - Frontend forms must use React Hook Form + Zod schemas.
- API responses should follow a consistent envelope:
{ data, meta?, error? }. - Error messages in UI must be in Portuguese; code comments in English.
Essential Commands
Monorepo
# Install dependencies
pnpm install
# Run all apps in dev mode
pnpm dev
# Build all apps
pnpm build
# Lint all
pnpm lint
Backend (NestJS + Prisma)
# Generate Prisma client
pnpm --filter api prisma generate
# Run migrations
pnpm --filter api prisma migrate dev
# Start API in dev
pnpm --filter api start:dev
Frontend (Next.js)
# Start dev server
pnpm --filter web dev
# Build for production
pnpm --filter web build