How renatops1991/saturn-service works
Project Type and Purpose
• This is a standalone backend microservice (REST API) for user management (creation, authentication, profile updates) written in TypeScript/Node.js with Express and MongoDB.
• It follows a Clean-Architecture/Onion-style layering (presentation → application/use-cases → domain → infrastructure).
Core Architectural Layers & Components
• Clients/Consumers: Any HTTP client (browser, mobile app, Postman) invoking the API endpoints.
• API Gateway (Express Server)
• Entry point (src/main/server.ts) with global middleware (CORS, body-parser, content-type).
• Routes defined in src/main/config/routes.ts and adapted via express-route-adapter.ts.
• Presentation Layer
• Controllers (src/presentation/controllers/…): Handle HTTP requests/responses, use http-helper.ts.
• Middleware (src/presentation/middlewares/auth-middleware.ts): Enforce JWT auth.
• Application Layer (Use Cases)
• Use-Case Interactors (src/data/use-cases/user.ts): Business rules for signup, signin, fetch/update user.
• Validation Composite (src/validation/validation-composite.ts + factories): Validate incoming DTOs.
• Domain Layer
• Entities (src/domain/entities/user.ts, address.ts): Core business objects.
• Protocols/Interfaces (src/domain/protocols/*.ts): Abstractions for authentication, user repository.
• Infrastructure Layer
• Data Persistence
• MongoDB Adapter (src/infra/mongodb/user-repository-mongo-adapter.ts, mongo-helper.ts) implements UserRepository protocol.
• Cryptography
• Bcrypt Adapter (bcrypt-adapter.ts) and JWT Adapter (jwt-adapter.ts) implement Authentication and Hashed protocols.
• Validators (email-validator-adapter.ts) implement EmailValidator protocol.
• Composition Root (Factories)
• Wiring all dependencies (src/main/factories/*.ts): controllers, use-cases, middleware, validators.
Data Flow & Interactions
1. HTTP Request → Express middleware (CORS, parsing, content-type).
2. Route Matching → express-route-adapter → Selected Controller.
3. Controller
• Extracts DTO
• Runs validation composite
• Calls Use-Case interactor
4. Use-Case
• Uses domain protocols to orchestrate:
• Password hashing via Bcrypt Adapter
• JWT token creation via JWT Adapter
• CRUD via MongoDB Adapter
• Returns domain entity or token.
5. Controller formats response via http-helper → HTTP Response.
Key Architectural Patterns
• Factory Method: For creating controllers, express middleware, validation composites.
• Adapter: Express adapters, MongoDB adapter, cryptography adapters, email validator adapter.
• Composite: Validation pipeline combining multiple field checks.
• Builder: user-builder.ts for test fixtures and data assembly.