How kelvincomputing/node-login-authentication-authorization works
Main Components
• Client/Consumer: External clients (e.g., browsers, mobile apps, or other services) making HTTP requests.
• Presentation Layer:
• Found in the "src/presentation" folder.
• Contains subcomponents like the Express server (src/presentation/server.ts), routes (src/presentation/routes.ts), controllers (src/presentation/auth/controller.ts), and services (src/presentation/services/).
• Domain Layer:
• Located in "src/domain".
• Includes business objects and logic such as the definition of DTOs (Data Transfer Objects in src/domain/dtos), entities (e.g., user.entity.ts), and custom errors.
• Data Layer:
• Found in "src/data".
• Includes database connection and model management (in src/data/mongo and its models).
• Configuration Component:
• Found in "src/config", which includes configurations for environment variables, bcrypt, JWT, and regular expressions.
• Supporting Services:
• These incorporate the auxiliary services (like email service, authentication service) that are part of the presentation layer but provide key interactions with the domain and data layers.
• Infrastructure/DevOps:
• Docker configuration (docker-compose.yml) that suggests if the MongoDB or other services are containerized.
• Environment template (.env.template) for configuration variables.
Interactions Between Components
• Client sends HTTP requests (e.g., login, registration) to the Express server.
• The Express server routes these HTTP requests via specific routes (defined in src/presentation/routes.ts and auth-specific routes) to the corresponding controllers.
• Controllers in the presentation layer then interact with services (e.g., auth.service.ts, email.service.ts) that encapsulate the business logic.
• These services, where necessary, communicate with the domain layer (working with entities, DTOs, and handling business rules) for processing the request.
• Depending on the operation (e.g., saving user data), the services interact with the data layer (via the MongoDB models and connection defined in src/data/mongo) to perform CRUD operations.
• Configuration files (in src/config) provide necessary environment settings and tools (like JWT and bcrypt) that are used across these layers.
• All above interactions follow a clear separation of concerns, ensuring that each layer focuses on its responsibility.
Important Architectural Patterns & Principles
• Separation of Concerns: Distinct layers (configuration, presentation, domain, and data) ensure modularity.
• MVC-like or Layered Architecture: Although not a strict MVC, the separation of controllers (presentation) from services and domain logic implies an organized request handling workflow.
• Use of Adapters: The presence of adapters (e.g., jwt.adapter.ts and bcrypt.adapter.ts) indicates the utilization of adapter patterns to abstract external libraries or mechanisms.
Relevant Technologies & Tools
• TypeScript: All files are written in TypeScript providing type-safety.
• Express: The server framework used for building the REST API.
• MongoDB: The database used, managed with model definitions under src/data/mongo.
• JWT and Bcrypt: For authentication and security purposes.
• Docker: Containerization for database and possibly other services, as indicated by docker-compose.yml.
Specific Elements
• Client/Consumer (Front-end or API consumers)
• Presentation Layer (Express server, Routes, Controllers)
• Domain Layer (DTOs, Entities, Custom Errors)
• Data Layer (MongoDB, Models)
• Configuration/Adapters (JWT, bcrypt, environment configurations)
• Supporting Services (Email service, Auth service)
• From Client → Routes → Controllers → Services → Domain/Data
• Annotations where needed to show key operations like user authentication, registration, and database operations.