How arcay322/sumaq_uywa works
1. Repository shape
- This is a monorepo with two primary runtime boundaries: a React/Vite frontend at the repo root and a Node.js/Express backend in backend/.
- The backend owns persistence, business rules, auth, file generation, and scheduled/background work. The frontend owns user interaction, navigation, and API consumption.
2. Frontend application boundary
- The frontend is a TypeScript React app built with Vite, Material UI, React Router, and an API layer over Axios.
- src/pages represents the main screens for domain areas like cuyes, galpones, gastos, ventas, salud, reproducción, dashboard, and login/register.
- src/components contains reusable domain widgets, tables, dialogs, and specialized modules for alerts, calendar, reports, and dashboards.
3. Frontend composition and state
- src/layouts defines app shell structure such as sidebar/main layout.
- src/contexts, src/hooks, and src/services provide cross-cutting client concerns: notifications, error handling, delete confirmation, and WebSocket integration.
- The frontend also has its own theme system in src/theme and UI utilities in src/utils, indicating a strong separation between domain pages and shared presentation behavior.
4. Backend API boundary
- The backend is an Express + TypeScript API under backend/src.
- The classic controller-route-service layering is explicit: routes define HTTP endpoints, controllers adapt requests/responses, and services contain business logic.
- This structure is repeated per domain, which makes each functional area diagrammable as an independent vertical slice.
5. Core domain subsystems
- The main backend domains are:
- Inventario/Cuyes/Galpones/Jaulas
- Alimentación
- Salud
- Ventas
- Gastos
- Reproducción
- Dashboard
- Alerts/Notifications
- Reports/Exports
- Calendar
- Auth
- Each domain has its own controller, route, schema, and service set, so the architecture is modular rather than centralized around one large service.
6. Data access and persistence
- Persistence is handled by Prisma ORM against PostgreSQL.
- Database structure evolves through backend/prisma/migrations, with a shared schema.prisma and a separate schema.test.prisma for test isolation.
- backend/src/utils/prisma.ts and backend/src/utils/database.ts indicate shared database access helpers, likely used to enforce a stable client lifecycle and avoid connection churn.
7. Authentication and request protection
- Authentication is JWT-based, with password hashing via bcrypt as documented in the README.
- Protected routes are guarded by middleware in backend/src/middlewares/auth.ts, with validation middleware layered in for domain-specific constraints.
- The frontend includes PrivateRoute, so access control exists on both the UI and API sides.
8. Reporting and file generation subsystem
- Reports are a major standalone subsystem in backend/src/services/reports.
- It includes generation of CSV, Excel, and PDF outputs, plus file storage, download, cleanup, job lifecycle, and job monitoring.
- There is a separate reports job controller/route pair, so report creation is treated as an asynchronous workflow rather than a simple request/response action.
- Generated artifacts are stored under backend/uploads/reports, which is a persistent file boundary distinct from the database.
9. Background jobs, alerts, and real-time communication
- The backend has scheduled and operational background work in backend/src/jobs, especially alert scheduling.
- Real-time behavior is supported by a WebSocket layer in backend/src/services/websocket and related middleware, used by the frontend notification widgets and dashboard components.
- Alerts and notifications are split into their own domain, reflecting user-facing eventing separate from core CRUD modules.
10. Dashboard and analytics flow
- Dashboard functionality aggregates data from several modules through dedicated services such as metrics, charts, realtime, and error handling.
- This is a read-heavy integration layer: it pulls from cuyes, reproducción, ventas, gastos, salud, and alerts to present operational status and KPIs.
- The dashboard is therefore an orchestration boundary rather than a data owner.
11. Reproduction and lifecycle management
- Reproduction is one of the richer business domains, with entities like preñez, camadas, jala/jaula capacity, and reproductive integration services.
- On the frontend, this domain has specialized managers, analytics, recommendations, compatibility widgets, and calendar integration.
- The backend includes dedicated validation and dual naming variants (preñez / prenez), showing an evolved domain with compatibility and cleanup work around it.
12. Calendar and scheduling
- The calendar subsystem exists on both sides: backend calendar services manage events and recovery, while the frontend provides reproductive calendar UI and event creation/details.
- This suggests the calendar is used as an operational planner for reproduction and alerts, not as a general-purpose personal calendar.
13. Testing and quality boundaries
- The backend has an extensive Jest suite, including unit, integration, and end-to-end tests for reports, jobs, cache, database utilities, API endpoints, and reproductive optimizations.
- The frontend also includes tests for shared UI components and reporting progress components.
- Several root-level .kiro/specs documents and stabilization notes indicate the repo has undergone structured cleanup and iterative hardening, especially around TypeScript, reporting, and reproduction.
14. Deployment and environment
- The project is designed for separate frontend/backend environments, with .env examples for root and backend.
- Deployment is oriented around Render, with scripts and configuration for automated build, migration, and service startup.
- The backend depends on PostgreSQL, while the frontend is a static build served separately or behind a platform pipeline.
15. How data moves through the system
- Typical flow: user action in a React page/component → frontend service/API call → Express route/controller → domain service → Prisma/PostgreSQL → response back to UI.
- For reporting and alerts, the flow extends to background jobs, file generation/storage, WebSocket broadcasts, and then frontend notification/report history views.
- This makes the architecture a combination of synchronous CRUD APIs and asynchronous operational subsystems, with the database as the central source of truth.
Main entry points: pages Pages · components Widgets · routes Routes · services Services
Components 22
Frontend
React/Vite client boundary
- App shell · Top-level client entry and routing composition
src/main.tsx - Pages · Domain screens for inventory, reproduction, reports, dashboard, auth
src/pages - Widgets · Reusable tables, dialogs, dashboards, alerts, reports, and calendar widgets
src/components - Layouts · Main and sidebar layout structure
src/layouts - Client state · Notifications, error handling, WebSocket, and delete confirmation hooks
src/contexts - API client · HTTP and notification service layer
src/services/api.ts - Theme · Shared presentation styles and Material UI theming
src/theme - Access control · Private route protection in the UI
src/components/PrivateRoute.tsx
Backend
Express API and domain services
- Server entry · Backend bootstrap and server wiring
backend/src/index.ts - Routes · Endpoint definitions across domain areas
backend/src/routes - Controllers · Request/response adapters for each domain
backend/src/controllers - Services · Business logic for inventory, reproduction, sales, health, dashboard, alerts, and reports
backend/src/services - Middleware · Auth, validation, cache, error handling, and websocket middleware
backend/src/middlewares - Jobs · Scheduled alert processing and operational jobs
backend/src/jobs/alertsScheduler.job.ts - Reports stack · CSV, Excel, PDF generation, storage, lifecycle, monitoring, and downloads
backend/src/services/reports - Dashboard · Metrics, charts, realtime aggregation, and dashboard orchestration
backend/src/services/dashboard - Reproduction · Preñez, camadas, compatibility, jaula capacity, and integration services
backend/src/services/reproduccion - Alerts · Alerts, notifications, and realtime broadcast services
backend/src/services/alerts - Auth · Authentication endpoint and guarded request flow
backend/src/middlewares/auth.ts - Calendar · Operational events and recovery handling for reproduction planning
backend/src/services/calendar
Data
Persistence and generated artifacts
- Prisma · Database client and schema layer over PostgreSQL
backend/prisma/schema.prisma - Report files · Persistent generated report outputs
backend/uploads/reports
Connections 26
- App shell → Pages: navigates · Routes render domain screens
- App shell → Layouts: wraps · Layouts provide the application shell
- Pages → Widgets: composes · Pages use shared widgets and tables
- Pages → API client: calls · Screens fetch and mutate through the API layer
- Widgets → Client state: uses · Widgets consume notification and websocket hooks
- Client state → API client: observes · Hooks coordinate API-facing client behavior
- Access control → Pages: protects · Private routes gate authenticated screens
- Theme → Widgets: styles · Shared theming shapes UI presentation
- Server entry → Routes: mounts · Server registers HTTP routes
- Routes → Controllers: dispatches · Routes forward requests to controllers
- Controllers → Services: delegates · Controllers hand off business logic
- Services → Prisma: persists · Services read and write via Prisma
- Middleware → Routes: guards · Auth and validation sit in front of endpoints
- Jobs → Alerts: triggers · Scheduled work drives alert processing
- Reports stack → Report files: stores · Generated exports land in file storage
- Reports stack → Prisma: reads · Report data is assembled from the database
- Dashboard → Services: aggregates · Dashboard pulls from operational domains
- Reproduction → Prisma: coordinates · Reproduction logic depends on persisted lifecycle data
- Alerts → Services: broadcasts · Notification flows are exposed through services
- Calendar → Reproduction: supports · Calendar events are tied to reproduction planning
- Widgets → Alerts: listens to · Notification widgets consume realtime updates
- Widgets → Dashboard: visualizes · Dashboard widgets present aggregated metrics
- Pages → Reports stack: requests · Report screens trigger export and history workflows
- Pages → Reproduction: operates on · Reproduction screens mirror the reproductive domain
- Pages → Calendar: plans with · Calendar UI coordinates operational events
- Auth → Routes: secures · JWT protection applies to protected API slices