How githubstuf/gestion-comptable-api works
Main Components
• Server/Entry Point – Represented by the file (src/server.ts) that starts the Express (or similar) server.
• Middleware – Components handling cross-cutting concerns such as authentication (AuthMiddleware.ts) and error handling (ErrorHandlerMiddleware.ts).
• Routes – HTTP route definitions found in the src/routes directory (e.g., client.routes.ts, devis.routes.ts, marche.routes.ts). They map endpoints to controllers.
• Controllers (Use Case Coordinators) – Located within each usecase (for instance, CreateClientController.ts, CreateDevisController.ts, etc.). These act as the entry point for each business operation.
• Use Cases – Core business logic located in the src/usecases directories for different modules (Client, Devis, Marche). Each task (Create, Delete, Find, Update) embodies a discrete use case.
• Data Transfer Objects (DTOs) – Defined in the src/dtos directory. They encapsulate input/output data structures exchanged between layers.
• Repositories – Defined by interfaces in src/repositories and implemented in the two subfolders:
• In-Memory Implementations – Useful for testing environments.
• Prisma Implementations – Production-ready repository classes using the PrismaClient for database interactions.
• Data Access Layer – Represented by the Prisma client defined in src/libs/PrismaClient.ts and the prisma folder (containing schema and migration details).
• Helper Functions and Utilities – Various helper files (pagination helpers, error utilities, etc.) that support consistent business logic.
Relationships and Component Interactions
• Incoming HTTP Requests hit the Server and pass through Middlewares (for authentication, error handling, etc.).
• Routed requests then are forwarded from the Routes layer to the corresponding Controllers in the use cases.
• Controllers accept inputs (using DTOs) and invoke the Use Cases that implement the business logic.
• Use Cases, in turn, depend on Repository Interfaces. Depending on configuration, they use either the in-memory or Prisma repository implementations.
• The Repository delegates data operations to the Prisma client, which interacts with the underlying database.
• Responses and any errors flow back through the inverse chain: use case → controller → route → middleware → response to the client.
Architectural Patterns and Principles
• Clean Architecture/Onion Architecture – Separation is evident, as each layer (controllers, use cases, repositories) is independent and communicates via defined interfaces.
• Dependency Inversion – The use cases depend on repository interfaces rather than concrete implementations allowing selection between in-memory and Prisma implementations.
• Modularity – Each domain (e.g., Client, Devis, Marche) is separately organized with its own set of use cases and related DTOs.
• Error Handling and Middleware – Global error handling ensures consistency in reporting and debugging.
Detailed Elements
• Clearly label every component with its name (e.g., “Client Use Case – CreateClient”, “PrismaDevisRepository”, etc.).
• Optional layers such as mocks for testing purposes (realizing that tests and mocks are part of the overall development feedback loop).