How maxmillernunes/rentx works
Project type and purpose
• This is a backend-only REST API service for car rentals, built with Express, TypeORM, and a set of “modules” (accounts, cars, rentals).
• It follows Clean/Hexagonal principles: each module has domain DTOs, Use Cases, Repositories (interfaces and Infra implementations), Controllers, and Entities.
File structure
• Top-level “src/shared/infra/http” contains the Express server (server.ts), middleware, and route definitions.
• Each feature lives under src/modules/<feature> with subfolders for DTOs, useCases, infra (TypeORM entities & repos), etc.
• src/shared/container holds dependency-injection bindings for providers (Mail, Storage, Date).
• Config files show external dependencies: ormconfig*.json (PostgreSQL via TypeORM), Redis config, upload (multer), mail providers, Docker and docker-compose.
Key README insights
• Business rules for user authentication, car management, rental lifecycle, password reset.
• No frontend here; this service exposes endpoints for these features.
Main components
A. Clients
– Mobile App or Web SPA (HTTP/JSON over REST)
B. API Service (monolithic)
1. HTTP Layer
• Express server (shared/infra/server.ts)
• Middlewares: rateLimiter, ensureAuthenticated, ensureAdmin, error handlers
2. Routing Layer
• Route files: authenticate.routes, cars.routes, categories.routes, rental.routes, users.routes, etc.
3. Controllers
• One controller per Use Case (e.g. CreateCarController)
4. Application/Domain Layer
• Use Cases: each implements business logic (e.g. CreateRentalUseCase)
• DTOs & Mappers (e.g. ICreateUserDTO, UserMap)
5. Infrastructure Adapters
a. Repositories
– Interfaces (IUsersRepository, ICarsRepository, etc.)
– TypeORM implementations (entities + *Repository classes)
– In-Memory implementations (for tests)
b. Providers
– MailProvider (Ethereal, SES, SendGrid)
– StorageProvider (Local, S3)
– DateProvider (DayJs)
c. External Services
– PostgreSQL (via TypeORM)
– Redis (for rate-limiting or token blacklisting)
– SMTP/SES/SendGrid
– S3 (for car images)
C. Data stores & external systems
– PostgreSQL database
– Redis cache
– S3 bucket (object storage)
– Email service (SES/SendGrid/Ethereal)
Relationships and data flows
• Client → HTTP Layer (Express) → Routing → Controller → Use Case
• Use Case → Repository interface → TypeORM Repository → PostgreSQL
• Use Case → Provider interface → Provider implementation → External system (e.g. S3, Mail API, Redis)
• Middleware intercepts Client→Server calls for auth, rate-limiting, error handling.
Architectural patterns & design principles
• Clean (Hexagonal) Architecture: separation of concerns between layers (HTTP adapters, controllers, use cases, repositories, providers)
• Dependency Injection: all external services (DB, mail, storage, date) injected at runtime via shared/container
• Repository Pattern: domain-agnostic interfaces with multiple implementations (TypeORM vs InMemory)
• Provider Pattern / Strategy Pattern for mail, storage, date.
Final checklist
[ ] All major components and layers represented
[ ] External systems and protocols shown
[ ] Note Clean Architecture boundaries (hexagon or ring view if desired)
[ ] Highlight dependency injection bindings (shared/container)