How masatotezuka/clean-architecture-sample-app works
Main Components
• Docker Environment: Represent the Docker infrastructure elements such as the Dockerfile, docker-compose.yaml, and the dedicated Docker folder for MySQL initialization (Docker/db/init.sql). This indicates that the application is containerized and runs in a set-up that includes a MySQL database.
• Express Server Application: The core backend server is built using Express. The entry point (src/index.ts) will be the starting point where the server is initialized.
• Application Layers (Clean Architecture):
a. Controllers (src/controller): These handle the incoming HTTP requests and coordinate input validations and responses.
b. Use Cases (src/use-case): This layer encapsulates the business logic. Files like create-user.ts, delete-user.ts, get-users.ts, update-user.ts belong here.
c. Domain (src/domain): This contains domain entities (e.g., user.entity.ts) representing the core business model.
d. Repositories (src/repositories): This handles data persistence (e.g., user.repository.ts) where the business data is interfaced with the database through Prisma.
e. Middlewares (src/middleware): Includes error handling and request validation functionalities.
• External Services:
a. Database (MySQL): Managed by Docker and configured through Prisma (prisma/schema.prisma and prisma/index.ts).
b. Orchestration / Dependency Injection: While not emphasized heavily, tools such as tsyringe are mentioned.
Relationships and Data Flow
• Incoming HTTP requests are received by the Express controllers.
• The controllers pass the request data to the appropriate use case, which represents the application’s business rules.
• The use cases interact with repositories to manage data, where Prisma serves as the ORM interfacing with MySQL.
• Middleware (such as input validation and error handling) intercepts requests and responses, ensuring data integrity and robust error management.
• Docker and Docker Compose set up the environment by orchestrating both the application service and the MySQL database container.
Architectural Patterns & Design Principles
• Clean (Onion) Architecture: Demonstrates a clear separation between different layers (controllers, use cases, domain, and repositories).
• Dependency Injection: Indicated by the use of tsyringe, which enforces loose coupling.
• Modular Design: Separation of concerns across distinct directories (e.g., src/domain vs. src/use-case).