# hieu36075/dev-manager architecture

> Architecture diagram of the GitHub repository hieu36075/dev-manager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hieu36075/dev-manager
- Repository: https://github.com/hieu36075/dev-manager

## Overview

##### Main Components
- Frontline (Presentation) Layer: This is where HTTP endpoints and controllers are defined (e.g., src/presentation/*). These modules handle incoming requests (for auth, file operations, language, project, technical, etc.).
- Application Layer: Contains use-case implementations and data transfer objects (DTOs), segregating command and query responsibilities. It orchestrates business rules and validates inputs.
- Domain Layer: This layer defines the core business models/entities and includes the interfaces (repositories, adapters) that the application layer relies on. It encapsulates business rules and entities (e.g., language.model.ts, project.model.ts, user.model.ts).
- Infrastructures Layer: Provides the concrete implementation of repositories and services that interact with external systems (e.g., typeORM configuration, repositories for various entities, external integrations like Cloudinary, bcrypt, JWT, and docxtemplate services).

##### Relationships and Interactions
- The Presentation Layer (REST controllers) receives client requests and then calls into the Application Layer. Use controllers (e.g., auth.controller.ts, file.controller.ts) to show entry points.
- The Application Layer is composed of various use-case “commands” and “queries”. Each use-case typically delegates the heavy lifting to business logic and repository interfaces defined in the Domain Layer.
- The Domain Layer defines the core business models/entities and establishes repository contracts. These contracts are then implemented in the Infrastructure layer.
- The Infrastructures Layer implements technical details like database integrations (via TypeORM), external service interactions (Cloudinary for file uploads, JWT for authentication, Docxtemplater for document generation, etc.) and configuration settings.
- Additionally, several decorators, guards, and strategies (located under src/application/common) serve to enforce security and enrich functionality (e.g., JWT strategy, role-based access).

##### Important Architectural Patterns and Design Principles
- Layered (N-tier) Architecture: Clearly separating presentation, application, domain, and infrastructure concerns.
- Domain-Driven Design (DDD): Domain models, repositories, and use-cases are located in their dedicated layers, emphasizing business logic encapsulation.
- Dependency Injection and Inversion of Control: Common NestJS patterns used to inject dependencies (e.g., repository implementations, security strategies) across layers.
- Command and Query Responsibility Segregation (CQRS): Evident in separate command and query directories inside each use-case module.
- Modular Organization: Each major business capability (e.g., language, project, technical) is self-contained and follows similar internal structures (command, query, DTO).

##### Relevant Technologies, Frameworks, or Libraries
- NestJS Framework (TypeScript, controllers, modules, decorators, dependency injection)
- TypeORM (for database interactions, as seen in infrastructures/typeorm)
- JWT, bcrypt, and Cloudinary integrations for authentication, hashing, and media management
- Docxtemplater for document generation (with corresponding services and adapters)
- Testing frameworks (evident from e2e tests and Jest configuration)

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Presentation Layer"
        P1["Auth Controller"]:::pres
        P2["File Controller"]:::pres
        P3["Language Controller"]:::pres
    end

    subgraph "Application Layer"
        A1["Use-Case Handlers & DTOs"]:::app
        A2["JWT Strategy"]:::app
    end

    subgraph "Domain Layer"
        D1["Domain Models"]:::dom
        D2["Domain Repositories"]:::dom
    end

    subgraph "Infrastructures Layer"
        I1["TypeORM Config"]:::infra
        I2["Repository Implementations"]:::infra
        I3["JWT Service"]:::infra
        I4["Bcrypt Service"]:::infra
        I5["Cloudinary Service"]:::infra
        I6["Docxtemplater Service"]:::infra
    end

    P1 -->|"calls"| A1
    P2 -->|"calls"| A1
    P3 -->|"calls"| A1

    A1 -->|"invokes"| D2
    A1 -->|"integrates_with"| I4
    A1 -->|"integrates_with"| I5
    A1 -->|"integrates_with"| I6
    A2 -->|"verifies"| I3
    A1 -.->|"depends_on"| A2

    D1 -->|"defines"| D2
    D2 -->|"implemented_by"| I2
    I2 -->|"uses"| I1

    %% Click Events
    click P1 "https://github.com/hieu36075/dev-manager/blob/main/src/presentation/auth/auth.controller.ts"
    click P2 "https://github.com/hieu36075/dev-manager/blob/main/src/presentation/file/file.controller.ts"
    click P3 "https://github.com/hieu36075/dev-manager/blob/main/src/presentation/language/language.controller.ts"
    click A1 "https://github.com/hieu36075/dev-manager/tree/main/src/application"
    click A2 "https://github.com/hieu36075/dev-manager/blob/main/src/application/common/strategies/jwt.strategy.ts"
    click D1 "https://github.com/hieu36075/dev-manager/tree/main/src/domain/model"
    click D2 "https://github.com/hieu36075/dev-manager/tree/main/src/domain/repositories"
    click I1 "https://github.com/hieu36075/dev-manager/blob/main/src/infrastructures/typeorm/typeorm.config.ts"
    click I2 "https://github.com/hieu36075/dev-manager/tree/main/src/infrastructures/repositories"
    click I3 "https://github.com/hieu36075/dev-manager/blob/main/src/infrastructures/service/jwt/jwt.service.ts"
    click I4 "https://github.com/hieu36075/dev-manager/tree/main/src/infrastructures/service/bcrypt"
    click I5 "https://github.com/hieu36075/dev-manager/tree/main/src/infrastructures/service/cloudinary"
    click I6 "https://github.com/hieu36075/dev-manager/tree/main/src/infrastructures/service/docxtemplate"

    %% Styles
    classDef pres fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef app fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef dom fill:#ffcc99,stroke:#000,stroke-width:2px;
    classDef infra fill:#dda0dd,stroke:#000,stroke-width:2px;
```
