How cleytonrr/my-contacts works
Main Components
• Frontend: The React application, which is composed of multiple components (e.g., App, ContactForm, Header, various pages like Home, NewContact, EditContact) and makes API calls through its services (ContactsService, CategoriesService).
• Backend: The Node.js/Express server that handles RESTful API endpoints. This includes:
• Controllers (e.g., CategoryController, ContactController) handling incoming requests.
• Middlewares (e.g., CORS, ErrorHandler) that manage pre/post API processing.
• Repositories (e.g., CategoriesRepository, ContactsRepository) that abstract the database operations.
• Utility functions and database configuration (with schema.sql for setting up PostgreSQL).
• Database: PostgreSQL which is managed from the backend by executing SQL scripts (schema.sql), and utilized via the database layer in the backend.
• External Components: Tools/inputs such as environment files (.env, etc.) that configure runtime and deployment settings.
Relationships and Interactions
• The Frontend sends HTTP requests (through the HttpClient utilities) to the Backend’s API endpoints.
• The Backend processes these requests via its controllers and middlewares, delegates data handling to the repositories, and interacts with PostgreSQL.
• Error handling is managed centrally in the backend with an error handling middleware.
• The frontend’s internal state management and routing (via router.js) guide the user interactions and present the UI accordingly.
Architectural Patterns / Design Principles
• Clear separation of concerns: The division between frontend and backend helps in isolating UI logic from business logic.
• MVC-like pattern on the backend: Controllers, repositories, and middlewares formulate a layered pattern for processing requests.
• Component-based architecture in the frontend: React components and pages are distinctly separated and modular.
• RESTful API communication between the frontend and backend.