# nei-dev/noc-app architecture

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

- Interactive diagram: https://gitdiagram.com/nei-dev/noc-app
- Repository: https://github.com/nei-dev/noc-app

## Overview

##### Project Type and Purpose
- The app is a simulation tool (NOC app) that “saves logs” across multiple persistence layers (file system, MongoDB, and PostgreSQL).
- It uses Node with TypeScript, relies on a Gmail key (presumably for sending email notifications), and utilizes Docker Compose to set up the required databases via Prisma migrations.
- This is a backend service with clear separation of concerns between business logic, infrastructure adapters (for data sources), and presentation (cron jobs and email services).

##### Break Down the File Structure into Key Components
- Configuration & Environment:
– Top-level configuration files (.env.template, docker-compose.yml, package.json) and the src/config folder with environment setups.
- Data Layer:
– The src/data/mongo directory provides connectivity to MongoDB and its initialization code.
- Domain Layer:
– Under src/domain you find subdirectories like datasources, entities, repository, and use-cases.
– This is where the core business logic resides (e.g., log entities, log repository interfaces, check service use cases, and send-logs use cases).
- Infrastructure Layer:
– The src/infraestructure directory holds concrete data source implementations and repository implementations.
– You have integrations for file system logging, a Mongo log data source, and a Postgres log data source (using Prisma migrations/schema in the prisma folder).
- Presentation Layer:
– Located under src/presentation, it contains modules for scheduled tasks (cron) and email services, as well as the main server-app.ts which likely is the entry point of the application.
- Testing:
– There are tests scattered as *.test.ts files within almost every module, indicating a strong emphasis on unit testing.

a. Components to Identify:
– Environment/Configuration: The configuration files and environment variables.
– Presentation Layer: The HTTP server (server-app.ts), cron job services (src/presentation/cron), and email services (src/presentation/email).
– Domain Layer: Consists of use cases (check services, send-logs), domain entities (log entity), and domain repositories (log repository interface).
– Infrastructure Layer: Concrete implementations connecting to file system, MongoDB and PostgreSQL. Include components for:
- File-System Datasource
- MongoDB Datasource
- PostgreSQL Datasource (via prisma)
- Log.repository.impl, which adapts domain repository use.
– Data Access & Connectivity: The src/data/mongo section shows initializations and data connection routines to MongoDB.
– External Dependencies: Docker Compose (to spin up database containers), Gmail service (using obtained key).

b. Relationships and Interactions:
– The Presentation Layer (server & cron/email services) receives requests and triggers Domain Layer use cases.
– Domain Use Cases interact with the domain repository interface to save and process logs.
– The Domain layer abstracts over the actual data persistence, so the Infrastructure Layer provides concrete implementations to handle file-system writes, MongoDB operations, and PostgreSQL persistence.
– Configuration settings (from the env files) flow into both connection setups (for databases and Gmail integration) and other operational parameters.
– Dependencies (such as Prisma for PostgreSQL, mail libraries for Gmail integration, and any MongoDB driver) should be highlighted.

##### Architectural Patterns & Design Principles
- Clear separation of concerns (presentation, domain, and infrastructure layers) suggests a Clean or Hexagonal Architecture style.
- Use of interfaces (domain repository) with separate implementations in the infrastructure layer.
- Dependency injection (implied by separation of domain and implementations) to allow easier swapping or testing.
- Integration of external services (Gmail, Dockerized databases) should be noted.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Configuration Layer
    subgraph "Configuration"
        ConfigEnv["Configuration/Env"]:::config
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Docker["Docker Compose"]:::external
        Gmail["Gmail Integration"]:::external
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        Server["Server App"]:::presentation
        Cron["Cron Service"]:::presentation
        Email["Email Service"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        Entity["Log Entity"]:::domain
        UseCases["Use Cases"]:::domain
        RepoInterface["Repository Interface"]:::domain
        DomainData["Domain Datasources"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        FileSys["File-System Datasource"]:::infra
        MongoInfra["Mongo Log Datasource"]:::infra
        PostgresInfra["Postgres Datasource"]:::infra
        RepoImpl["Log Repository Implementation"]:::infra
        Prisma["PostgreSQL Schema"]:::infra
    end

    %% Data Layer
    subgraph "Data Layer"
        MongoData["MongoDB Connectivity"]:::data
    end

    %% Connections from Configuration
    ConfigEnv -->|"config"| Server
    ConfigEnv -->|"config"| Email
    ConfigEnv -->|"config"| UseCases
    ConfigEnv -->|"config"| MongoData

    %% Presentation to Domain
    Server -->|"invoke"| UseCases
    Cron -->|"schedule"| UseCases
    Email -->|"notify"| UseCases

    %% Domain internal interactions
    UseCases -->|"process"| Entity
    UseCases -->|"abstract_DS"| DomainData
    UseCases -->|"save_logs"| RepoInterface

    %% Domain to Infrastructure Implementation
    RepoInterface -->|"implements"| RepoImpl

    %% Infrastructure datasource usage
    RepoImpl -->|"FS_log"| FileSys
    RepoImpl -->|"Mongo_log"| MongoInfra
    RepoImpl -->|"Postgres_log"| PostgresInfra

    %% Data Layer connection to Infrastructure
    MongoData -->|"connection"| MongoInfra

    %% External influencing Infrastructure and Data Layer
    Docker -->|"init_DB"| PostgresInfra
    Docker -->|"init_DB"| MongoData
    Gmail -->|"auth"| Email

    %% Click Events
    click ConfigEnv "https://github.com/nei-dev/noc-app/tree/main/src/config"
    click Docker "https://github.com/nei-dev/noc-app/blob/main/docker-compose.yml"
    click Gmail "https://github.com/nei-dev/noc-app/blob/main/src/presentation/email/email.service.ts"
    click Server "https://github.com/nei-dev/noc-app/blob/main/src/presentation/server-app.ts"
    click Cron "https://github.com/nei-dev/noc-app/tree/main/src/presentation/cron"
    click Email "https://github.com/nei-dev/noc-app/blob/main/src/presentation/email/email.service.ts"
    click Entity "https://github.com/nei-dev/noc-app/tree/main/src/domain/entities"
    click UseCases "https://github.com/nei-dev/noc-app/tree/main/src/domain/use-cases"
    click RepoInterface "https://github.com/nei-dev/noc-app/tree/main/src/domain/repository"
    click DomainData "https://github.com/nei-dev/noc-app/tree/main/src/domain/datasources"
    click FileSys "https://github.com/nei-dev/noc-app/blob/main/src/infraestructure/datasources/file-system.datasource.ts"
    click MongoInfra "https://github.com/nei-dev/noc-app/blob/main/src/infraestructure/datasources/mongo-log.datasource.ts"
    click PostgresInfra "https://github.com/nei-dev/noc-app/blob/main/src/infraestructure/datasources/postgres-log.datasource.ts"
    click RepoImpl "https://github.com/nei-dev/noc-app/blob/main/src/infraestructure/repository/log.repository.impl.ts"
    click Prisma "https://github.com/nei-dev/noc-app/blob/main/prisma/schema.prisma"
    click MongoData "https://github.com/nei-dev/noc-app/tree/main/src/data/mongo"

    %% Styles
    classDef config fill:#9fdfbf,stroke:#333,stroke-width:2px;
    classDef external fill:#a9def9,stroke:#333,stroke-width:2px;
    classDef presentation fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef domain fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef infra fill:#f94144,stroke:#333,stroke-width:2px;
    classDef data fill:#caffbf,stroke:#333,stroke-width:2px;
```
