# nottee-project/note_service architecture

> Architecture diagram of the GitHub repository nottee-project/note_service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nottee-project/note_service
- Repository: https://github.com/nottee-project/note_service

## Overview

##### Main Components

a) API Layer:
- REST Endpoints (from /internal/delivery/rest/handler)
- Create Note
- Delete Note
- Get Note
- Notes
- Update Task
- Telegram Handler (indicating external integration)

b) Service Layer:
- Service (/internal/service/note)
- Business Logic Implementation
- Interface Definitions

c) Data Layer:
- Store Adapters (/internal/adapter/store)
- Store
- Transaction Management
- PostgreSQL Database
- Notes Table (with UUID, user references)

d) Configuration:
- Config Management (/internal/config)
- Database Configuration
- Redis Configuration
- Local Settings

##### Architecture Pattern
The project follows a clean architecture pattern with clear separation of concerns:
- Delivery Layer (REST API)
- Service Layer (Business Logic)
- Store Layer (Data Access)
- Models Layer (Domain Objects)

**[External Clients] → [REST API Layer] → [Service Layer] → [Store Layer] → [PostgreSQL]**
- ↘ [Redis]

##### Key Relationships to Highlight

**[Client Requests] → [Middleware] → [REST Handlers]**
- ↓
**[Config Management] → [Service Layer] → [Store Layer]**
- ↓
- [Database Layer]

##### Additional Elements

- Transaction boundary in the store layer
- UUID generation flow
- Foreign key relationship with users table
- Telegram integration point

##### Technical Details
- PostgreSQL with UUID extension
- REST API endpoints
- Transaction management
- User authentication flow (implied by user_id foreign key)

##### Deployment Context
- Docker container boundaries
- Configuration injection points
- External service connections

Remember to:
- Keep the main flow clear and centered
- Use consistent styling for similar components
- Notes about critical architectural decisions
- Error handling paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        EC[External Clients]:::client
        TG[Telegram Bot]:::client
    end

    subgraph API ["API Layer"]
        RT["Router"]:::api
        click RT "https://github.com/nottee-project/note_service/blob/main/internal/delivery/rest/router.go"
        
        MW["Middleware"]:::api
        click MW "https://github.com/nottee-project/note_service/blob/main/internal/delivery/rest/middleware/middleware.go"
        
        subgraph Handlers ["REST Handlers"]
            CN["Create Note"]:::handler
            click CN "https://github.com/nottee-project/note_service/blob/main/internal/delivery/rest/handler/create_note.go"
            DN["Delete Note"]:::handler
            click DN "https://github.com/nottee-project/note_service/blob/main/internal/delivery/rest/handler/delete_note.go"
            GN["Get Note"]:::handler
            click GN "https://github.com/nottee-project/note_service/blob/main/internal/delivery/rest/handler/get_note.go"
            LN["List Notes"]:::handler
            click LN "https://github.com/nottee-project/note_service/blob/main/internal/delivery/rest/handler/list_notes.go"
            UT["Update Task"]:::handler
            click UT "https://github.com/nottee-project/note_service/blob/main/internal/delivery/rest/handler/update_task.go"
            TH["Telegram Handler"]:::handler
            click TH "https://github.com/nottee-project/note_service/blob/main/internal/delivery/rest/handler/telegram_handler.go"
        end
    end

    subgraph Service ["Service Layer"]
        NS["Note Service"]:::service
        click NS "https://github.com/nottee-project/note_service/blob/main/internal/service/note/note.go"
        NSI["Note Service Interface"]:::service
        click NSI "https://github.com/nottee-project/note_service/blob/main/internal/service/note/interface.go"
    end

    subgraph Store ["Store Layer"]
        SI["Store Interface"]:::store
        click SI "https://github.com/nottee-project/note_service/blob/main/internal/adapter/store/store.go"
        NS_Store["Note Store"]:::store
        click NS_Store "https://github.com/nottee-project/note_service/blob/main/internal/adapter/store/note/note_store.go"
        TM["Transaction Management"]:::store
        click TM "https://github.com/nottee-project/note_service/blob/main/internal/adapter/store/common/transaction.go"
        NSM["Note Store Models"]:::store
        click NSM "https://github.com/nottee-project/note_service/blob/main/internal/adapter/store/note/models.go"
    end

    subgraph Config ["Configuration"]
        MC["Main Config"]:::config
        click MC "https://github.com/nottee-project/note_service/blob/main/internal/config/config.go"
        DBC["Database Config"]:::config
        click DBC "https://github.com/nottee-project/note_service/blob/main/internal/config/database.go"
        RC["Redis Config"]:::config
        click RC "https://github.com/nottee-project/note_service/blob/main/internal/config/redis.go"
    end

    subgraph Domain ["Domain Layer"]
        NM["Note Models"]:::domain
        click NM "https://github.com/nottee-project/note_service/blob/main/internal/models/note/models.go"
    end

    subgraph Storage ["Storage Layer"]
        DB[(PostgreSQL)]:::database
        RD[(Redis)]:::database
    end

    subgraph Bootstrap ["Bootstrap"]
        SB["Service Bootstrap"]:::bootstrap
        click SB "https://github.com/nottee-project/note_service/blob/main/internal/bootstrap/service.go"
        MA["Main Application"]:::bootstrap
        click MA "https://github.com/nottee-project/note_service/blob/main/cmd/main.go"
    end

    %% Relationships
    EC --> RT
    TG --> TH
    RT --> MW
    MW --> Handlers
    
    CN & DN & GN & LN & UT & TH --> NS
    NS --> NSI
    NS --> SI
    SI --> NS_Store
    NS_Store --> TM
    NS_Store --> NSM
    NSM --> DB
    NS_Store --> RD
    
    Config --> Service
    Config --> Store
    Config --> Storage
    
    SB --> Service
    MA --> SB

    %% Styles
    classDef client fill:#E1F5FE,stroke:#01579B
    classDef api fill:#E8F5E9,stroke:#2E7D32
    classDef handler fill:#E8F5E9,stroke:#2E7D32
    classDef service fill:#FFF3E0,stroke:#E65100
    classDef store fill:#FCE4EC,stroke:#880E4F
    classDef config fill:#F3E5F5,stroke:#4A148C
    classDef domain fill:#EFEBE9,stroke:#3E2723
    classDef database fill:#ECEFF1,stroke:#263238
    classDef bootstrap fill:#E0F2F1,stroke:#004D40
```
