# gnud-na/blog-api architecture

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

- Interactive diagram: https://gitdiagram.com/gnud-na/blog-api
- Repository: https://github.com/gnud-na/blog-api

## Overview

##### Project type and purpose
- This is a backend full-stack application (RESTful API) for a blog platform.
- Built with NestJS (Node.js framework) and PostgreSQL via TypeORM.
- Responsible for user authentication (JWT), post and comment management, and role-based access control.

##### File structure
- Top-level files:
- nest-cli.json, tsconfig*.json – NestJS and TypeScript configuration
- package.json / lock – dependencies and scripts
- .prettierrc, eslint.config.mjs – formatting and linting
- src/ directory:
- main.ts – application entry point, bootstraps Nest application
- app.module.ts – root module, imports other feature modules
- app.controller.ts / spec.ts – sample controller and its unit test
- app.service.ts – sample service
- test/ directory for end-to-end tests (jest-e2e.json, app.e2e-spec.ts)

##### README for additional insights
- Tech stack highlights: NestJS, PostgreSQL, TypeORM, JWT, class-validator, Docker readiness.
- Key features: user registration/auth, CRUD for posts, commenting, RBAC, validation, error handling.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Global entities
    Client["Client (Frontend / API Consumer)"]:::external
    DB["PostgreSQL Database"]:::external
    SMTP["SMTP Service"]:::external
    Redis["Redis Cache"]:::external

    %% NestJS Application Container
    subgraph "NestJS Application"
        direction TB

        Main["API Gateway / HTTP Interface\n(main.ts)"]:::infra
        AppModule["Root Module\n(app.module.ts)"]:::infra

        subgraph "Sample Module"
            direction TB
            AppController["AppController"]:::controller
            AppService["AppService"]:::service
        end

        subgraph "Auth Module"
            direction TB
            AuthGuard["JWT Auth Guard"]:::infra
            AuthService["AuthService"]:::service
        end

        subgraph "User Module"
            direction TB
            UserController["UserController"]:::controller
            UserService["UserService"]:::service
            UserEntity["UserEntity"]:::repo
        end

        subgraph "Post Module"
            direction TB
            PostController["PostController"]:::controller
            PostService["PostService"]:::service
            PostEntity["PostEntity"]:::repo
        end

        subgraph "Comment Module"
            direction TB
            CommentController["CommentController"]:::controller
            CommentService["CommentService"]:::service
            CommentEntity["CommentEntity"]:::repo
        end
    end

    %% Connections
    Client -->|"HTTP Request"| Main
    Main -->|"Bootstrap"| AppModule

    AppModule --> AppController
    AppModule --> AppService
    AppModule --> AuthGuard
    AppModule --> AuthService
    AppModule --> UserController
    AppModule --> UserService
    AppModule --> UserEntity
    AppModule --> PostController
    AppModule --> PostService
    AppModule --> PostEntity
    AppModule --> CommentController
    AppModule --> CommentService
    AppModule --> CommentEntity

    AppController -->|"calls"| AppService
    AppService -->|"dummy logic"| DB

    AuthGuard -->|"validates JWT"| AuthService
    AuthService -->|"verifies token"| DB

    UserController -->|"calls"| UserService
    UserService -->|"TypeORM.save / find"| UserEntity
    UserEntity -->|"queries"| DB

    PostController -->|"calls"| PostService
    PostService -->|"TypeORM.save / find"| PostEntity
    PostEntity -->|"queries"| DB

    CommentController -->|"calls"| CommentService
    CommentService -->|"TypeORM.save / find"| CommentEntity
    CommentEntity -->|"queries"| DB

    %% Optional External Services
    AuthService -.->|"send verification email"| SMTP
    UserService -.->|"cache user data"| Redis

    %% Click Events
    click Main "https://github.com/gnud-na/blog-api/blob/main/src/main.ts"
    click AppModule "https://github.com/gnud-na/blog-api/blob/main/src/app.module.ts"
    click AppController "https://github.com/gnud-na/blog-api/blob/main/src/app.controller.ts"
    click AppController "https://github.com/gnud-na/blog-api/blob/main/src/app.controller.spec.ts"
    click AppService "https://github.com/gnud-na/blog-api/blob/main/src/app.service.ts"
    click E2ETests "https://github.com/gnud-na/blog-api/blob/main/test/app.e2e-spec.ts"
    click E2EConfig "https://github.com/gnud-na/blog-api/blob/main/test/jest-e2e.json"
    click NestCLI "https://github.com/gnud-na/blog-api/blob/main/nest-cli.json"
    click TSConfig1 "https://github.com/gnud-na/blog-api/blob/main/tsconfig.json"
    click TSConfig2 "https://github.com/gnud-na/blog-api/blob/main/tsconfig.build.json"
    click PackageJSON "https://github.com/gnud-na/blog-api/blob/main/package.json"
    click PackageLock "https://github.com/gnud-na/blog-api/blob/main/package-lock.json"
    click Prettier "https://github.com/gnud-na/blog-api/blob/main/.prettierrc"
    click ESLint "https://github.com/gnud-na/blog-api/blob/main/eslint.config.mjs"
    click README "https://github.com/gnud-na/blog-api/blob/main/README.md"
    click Contrib "https://github.com/gnud-na/blog-api/blob/main/.CONTRIBUTING.md"

    %% Styles
    classDef controller fill:#d0e7ff,stroke:#024a86,stroke-width:1px
    classDef service fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef repo fill:#fff3cd,stroke:#856404,stroke-width:1px
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:1px,stroke-dasharray: 5 5
    classDef infra fill:#f8d7da,stroke:#721c24,stroke-width:1px
```
