How saviopatrick/api-solid-node works
Main Components
• Client/API Request Layer: Represent external clients (e.g., mobile/web) that interact with your HTTP server.
• HTTP Layer: Include the HTTP server (see src/server.ts and src/app.ts) and the controllers (located in src/http/controllers like login.ts and register.ts). These components expose endpoints for registration, login, and (in planned features) check-ins and gym searches.
• Routing: Capture the routing mechanism (see src/http/routes.ts) that maps incoming HTTP requests to the appropriate controller functions.
• Use Cases/Business Logic: Highlight the use-case layer (in src/use-cases/) that implements the core functionalities (user registration, login, check-ins, and profile management) along with factories (in src/use-cases/factories/) that create specific use-case instances.
• Repository Layer: Split the repository layer into two parts:
• In-memory repositories (for testing purposes) from src/repositores/in-memory/.
• Prisma repositories (production-level implementations) found in src/repositores/prisma/ and src/lib/prisma.ts (which establishes the connection to the database).
• Database/ORM: The PostgreSQL database is accessed using Prisma. The prisma/schema.prisma file and migration directories describe the database schema and migrations.
• Error Handling: Components under src/errors (for various error cases like not-found, unauthorized, etc.) to represent a standardized error management mechanism.
Relationships and Interactions
• External Clients make HTTP requests to the API endpoints.
• The HTTP layer (server/app.ts) forwards requests to appropriate controllers (login, register, etc.).
• Controllers delegate business logic to the corresponding use-cases.
• Use-cases interact with the repository layer which abstracts data persistence.
• The Prisma repository interacts with the PostgreSQL database as defined in prisma/schema.prisma.
• Error handling modules are integrated throughout to handle exceptions and enforce business rules (e.g., duplicate email registration).
• JWT authentication is used to identify users and secure endpoints.
Architectural Patterns
• Layered Architecture: Separate concerns into distinct layers – HTTP server, controllers, use cases (application logic), and repositories (data access).
• Dependency Injection: Observe that use-case factories (src/use-cases/factories/) likely provide specific implementations (whether in-memory or Prisma-backed) to the use-case logic.
• Clean Architecture: The structure emphasizes clear separation between business rules (use cases) and external dependencies (repositories, controllers, database).
Relevant Technologies and Configurations
• Node.js/TypeScript as the implementation language.
• Prisma for ORM and migrations.
• PostgreSQL as the database.
• Docker (docker-compose.yml) indicates containerized deployment.
• ESLint/NPM configuration files (.eslintrc.json, package.json, etc.) for development standards and dependency management.
• JWT for authorization (as stated in the README regarding user identification).
Essential Architectural Elements
• Be as detailed as possible and capture not just the “layers,” but also how components relate:
• Use cases for register, login, and check-ins.
• Existence of both in-memory and Prisma repositories to reflect testing vs. production.
• How database migrations (prisma/migrations) feed into the PostgreSQL schema via Prisma.
Happy diagramming!