How gustavoleal1194/projeto_gestao_casa_di_ana works
1. Overall shape
Casa di Ana is a two-part ERP: a .NET 8 backend API and a React 18 SPA frontend. The backend owns all business rules and persistence; the frontend is a feature-based client that calls the API over REST.
2. Backend architecture
The backend follows Clean Architecture + CQRS. The solution is split into Domain, Application, Infrastructure, and API, with one-way dependencies inward. API only orchestrates HTTP traffic; Application defines use cases; Infrastructure provides EF Core and external services; Domain contains the core model and contracts.
3. Domain layer boundary
CasaDiAna.Domain is the business core. It holds entities such as Ingrediente, Produto, EntradaMercadoria, Inventario, ProducaoDiaria, VendaDiaria, NotificacaoEstoque, and Usuario, plus enums like roles, movement types, and statuses. Repositories and services are only exposed as interfaces here, so the rest of the system depends on abstractions.
4. Application layer use-case model
CasaDiAna.Application is organized by business module: auth, estoque, entradas, inventários, produção, relatórios, notificações, usuários, etc. Each operation is represented as a MediatR Command or Query, with handlers and FluentValidation validators alongside DTOs. This is where orchestration happens: validation, domain method calls, repository access, and response shaping.
5. HTTP entry and request pipeline
CasaDiAna.API contains the REST controllers, a global exception middleware, and startup bootstrapping in Program.cs. Controllers are thin; they translate HTTP requests into MediatR calls and return a standardized ApiResponse<T>. The middleware converts validation, domain, auth, and unexpected exceptions into consistent HTTP responses.
6. Infrastructure and persistence
CasaDiAna.Infrastructure implements the domain interfaces using EF Core 8 + PostgreSQL. AppDbContext maps the database with explicit fluent configurations and supports three logical schemas: auth, estoque, and producao. Migrations are checked in and applied on startup, so schema evolution is part of the runtime setup.
7. Cross-cutting backend services
The infrastructure also provides JWT issuance, current-user extraction, and stock notification generation. Authentication relies on JwtService; authorization claims are consumed by CurrentUserService; NotificacaoEstoqueService evaluates ingredient stock levels and creates notifications. These services are used across multiple modules, not tied to one controller.
8. Primary business flows
The main data flows are inventory-related: entradas increase stock, produção diária decreases stock via product recipe/ficha técnica, vendas diárias and perdas record outflows, and inventários/correções reconcile physical counts against system balances. Every stock change is tracked through Movimentacao, which preserves origin references for auditability.
9. Production and product modeling
The production domain centers on Produto, CategoriaProduto, and ItemFichaTecnica. Products define how ingredients are consumed when production is registered, and the system calculates cost and stock impact from that recipe. This module also includes daily production registration, sales by product, and loss tracking.
10. Notifications, labels, and reports
Three supporting subsystems sit on top of the operational data: stock notifications, label generation, and reports. Notifications surface low/critical/empty stock; labels persist nutritional models and print history; reports aggregate stock, movements, entradas, production vs sales, and ingredient consumption, with PDF export on the client side.
11. Frontend architecture
The frontend is structured by features, not by technical layers. Each module under frontend/src/features/ owns its pages, services, hooks, and local components. Shared UI pieces live in components/layout and components/form, while routes/AppRoutes.tsx wires navigation and lib/api.ts centralizes API access.
12. Frontend state and API flow
Zustand is used only for authentication state: JWT token, current user, role checks, and logout. Forms use React Hook Form and Zod; data fetching is encapsulated in feature services that call the shared Axios client. The Axios layer injects the bearer token and forces logout on 401 responses, making auth the only global client-side concern.
13. Deployment and runtime boundaries
The repo is designed for containerized deployment with Docker Compose. The frontend is built with Vite and served by Nginx in production; the backend runs as ASP.NET Core and exposes Swagger in non-production. Render is the target hosting platform, and the backend health endpoint exists for platform monitoring.
14. Testing scope
Tests currently focus on Application-layer handlers with xUnit, Moq, and FluentAssertions. That means the core use-case logic is covered without booting the full API or database, reinforcing the architecture boundary between orchestration and infrastructure.
15. What matters for a diagram
The key diagram should show: browser/SPA on one side, REST API in the middle, and PostgreSQL underneath Infrastructure; then separate the backend into API → Application → Domain, with Infrastructure implementing Domain interfaces. The most important domain flows to label are estoque movements, production/sales consumption, inventory reconciliation, and auth/token-based access control.
Main entry points: Controllers Controllers · AppDbContext.cs DbContext · Produto.cs Core model · IProdutoRepository.cs Contracts
Components 21
Frontend
React SPA and client-side state/API flow
- SPA shell · Bootstraps the client application and layout flow
CasaDiAna/frontend/src/main.tsx - Routes · Declares application navigation and feature entry points
CasaDiAna/frontend/src/routes/AppRoutes.tsx - API client · Central REST access with token injection and 401 handling
CasaDiAna/frontend/src/lib/api.ts - Auth store · Holds token, user, role checks, and logout state
CasaDiAna/frontend/src/store/authStore.ts - Features · Feature-based pages, hooks, services, and local UI
CasaDiAna/frontend/src/features
API
HTTP entrypoint, controllers, and middleware
- Program · Wires DI, middleware, controllers, and runtime startup
CasaDiAna/src/CasaDiAna.API/Program.cs - Controllers · Thin HTTP adapters that dispatch MediatR requests
CasaDiAna/src/CasaDiAna.API/Controllers - Middleware · Normalizes validation, auth, domain, and unexpected errors
CasaDiAna/src/CasaDiAna.API/Middleware/ExceptionHandlingMiddleware.cs
Application
CQRS use cases and orchestration
- Auth use case · Login command flow and token response shaping
CasaDiAna/src/CasaDiAna.Application/Auth/Commands/Login/LoginCommandHandler.cs - Stock flows · Inventory and entrada orchestration around stock changes
CasaDiAna/src/CasaDiAna.Application/Entradas/Commands/RegistrarEntrada/RegistrarEntradaCommandHandler.cs - Production flows · Production, sales, losses, and recipe-driven consumption
CasaDiAna/src/CasaDiAna.Application/ProducaoDiaria/Commands/RegistrarProducao/RegistrarProducaoCommandHandler.cs - Inventories & reports · Inventory reconciliation and operational reporting queries
CasaDiAna/src/CasaDiAna.Application/Inventarios/Commands/IniciarInventario/IniciarInventarioCommandHandler.cs - Notifications · Application-facing stock notification service contract and workflows
CasaDiAna/src/CasaDiAna.Application/Notificacoes/Services/INotificacaoEstoqueService.cs
Domain
Business model and contracts
- Core model · Business entities, value concepts, and domain exceptions
CasaDiAna/src/CasaDiAna.Domain/Entities/Produto.cs - Contracts · Repository and service abstractions consumed by application and infrastructure
CasaDiAna/src/CasaDiAna.Domain/Interfaces/IProdutoRepository.cs
Infrastructure
EF Core persistence and cross-cutting services
- DbContext · Database mapping, schema configuration, and migrations entrypoint
CasaDiAna/src/CasaDiAna.Infrastructure/Persistence/AppDbContext.cs - Infra services · JWT, current-user access, and stock notification generation
CasaDiAna/src/CasaDiAna.Infrastructure/Services/NotificacaoEstoqueService.cs - Repositories · Concrete repository implementations for domain abstractions
CasaDiAna/src/CasaDiAna.Infrastructure/Repositories - PostgreSQL · Primary relational store behind the ERP
Delivery
Containerized runtime and hosting
- Docker Compose · Containerized local/runtime deployment wiring
CasaDiAna/docker-compose.yml
Tests
Application-layer unit tests
- Use-case tests · Application handler tests with mocked dependencies
CasaDiAna/tests/CasaDiAna.Application.Tests/CasaDiAna.Application.Tests.csproj
Connections 27
- SPA shell → Routes: uses · Bootstraps navigation and feature screens
- SPA shell → Auth store: reads auth · Initializes client auth state and guards
- Routes → Features: opens · Routes resolve into feature-owned pages
- Features → API client: calls · Feature services use the shared REST client
- API client → Auth store: injects token · Bearer token is attached and 401 triggers logout
- Program → Controllers: hosts · Registers and serves REST controllers
- Program → Middleware: pipes through · Global exception handling sits in the request pipeline
- Controllers → Auth use case: dispatches · Controllers map HTTP auth requests to MediatR
- Controllers → Stock flows: dispatches · Stock endpoints forward to application commands/queries
- Controllers → Production flows: dispatches · Production endpoints forward use cases
- Controllers → Inventories & reports: dispatches · Inventory and report endpoints forward use cases
- Auth use case → Contracts: depends on · Use cases consume repository and service abstractions
- Stock flows → Core model: mutates · Entrada and stock logic operate on domain entities
- Production flows → Core model: mutates · Production and sales use the product and movement model
- Inventories & reports → Core model: reads · Inventory reconciliation and reports aggregate domain data
- Notifications → Contracts: depends on · Notification workflows depend on repository abstractions
- Repositories → Contracts: implements · EF repositories satisfy domain repository interfaces
- Infra services → Contracts: implements · Infrastructure services fulfill domain/application contracts
- DbContext → Core model: maps · EF Core maps entities and persistence shape
- DbContext → PostgreSQL: persists to · Application data is stored in PostgreSQL
- Repositories → DbContext: uses · Repositories are built on the DbContext
- Infra services → DbContext: reads/writes · Notification and auth services use persistence when needed
- Docker Compose → Program: runs · Compose orchestrates the ASP.NET backend container
- Docker Compose → SPA shell: serves · Compose/runtime setup includes the SPA delivery container
- Use-case tests → Auth use case: verifies · Tests focus on handler orchestration and validation behavior
- Use-case tests → Stock flows: verifies · Tests cover stock-related application flows
- Use-case tests → Inventories & reports: verifies · Tests cover inventory use-case boundaries