How josherxd/gestion-compras-inventario works
Project type and purpose
• This is a full-stack “Gestión Compras e Inventario” application.
• Frontend: React single-page application (SPA) for managing products and orders.
• Backend: Node.js + TypeScript + Express REST API, backed by MongoDB, following a clean-architecture layering (controllers → use cases → domain services → repositories).
File structure
• Top-level directories:
• backend/
– src/ (TypeScript source)
• application/use_case (business use-cases)
• domain/models, interfaces, services (core entities, domain logic)
• infrastructure (Express controllers, routes, repository implementations, config)
– dist/ (compiled JS)
– test/ (Jest tests for each layer)
– schema.sql (DB schema reference)
– package.json, tsconfig.json, .env
• frontend/
– public/ (static HTML, manifest)
– src/ (React code)
• views (UI pages)
• context (React Context API)
• services/api.js (HTTP client)
• styles
README for additional insights
• Stack: React + CSS on frontend; Node.js, TypeScript, Express, Mongoose on backend; Jest for tests.
• Clean-architecture layering explicitly described.
• Key API endpoints for products, orders, purchase orders.
Main components and their interactions
a. Frontend (React SPA)
• UI Views (RegistrarProducto, RegistrarOrdenDeCompra, Home)
• AppContext (global state)
• api.js (fetch wrapper calling /api endpoints)
• Runs on http://localhost:3000, served by npm start
b. Backend (Express REST API)
• HTTP layer: Express server (index.ts) → routing modules (/api/productos, /api/ordenes, /api/purchaseorders)
• Controller layer: order.controller, product.controller, purchaseorder routes
• Application layer: use cases (order.usecase.ts, product.usecase.ts) orchestrating domain logic
• Domain layer:
• Models (Order, Product, Price, Quantity, etc.)
• Interfaces (OrderRepository, ProductRepository, PdfService)
• Services (business rules, e.g. order.service.ts)
• Infrastructure layer:
• Mongoose repository implementations (order.repository.service.ts, product.repository.service.ts)
• Database configuration (MongoDB connection via mongoose)
• Error handling and configuration (common/config/statusCode.ts, envs.ts)
• Tests: exercise each layer with Jest
c. Database
• MongoDB (hosted locally or in the cloud)
• Collections: products, orders, purchaseorders
• schema.sql for reference
d. External services
• Placeholder PdfService (interface in domain, implemented or stubbed in infrastructure if used)
Architectural patterns and design principles
• Clean (hexagonal) architecture: clear separation of layers, dependency inversion via interfaces
• RESTful API design, resource-oriented routing
• React Context for state management
• Mongoose ODM for data persistence