# hknsh/project-knedita architecture

> Architecture diagram of the GitHub repository hknsh/project-knedita, 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/hknsh/project-knedita
- Repository: https://github.com/hknsh/project-knedita

## Overview

##### Main components
- API Server: Represented by the NestJS application using Fastify as the HTTP adapter. This is your central coordinator where all requests are processed.
- Modules/Features: Break down the application into its core modules, such as:
- Auth Module (handles authentication with JWT, local strategies, and possibly guards)
- Kweeks Module (managing posts, comments, attachments, and related business logic)
- Users Module (responsible for user operations and profile management)
- Common/shared services (e.g., Prisma integration, S3 service for file storage, custom validators)
- PostgreSQL: Your relational database managed by Prisma migrations.
- Redis: Likely used for caching or session management.
- MinIO: Used as a S3-compatible object storage solution.
- Infrastructure Components: Docker components (Dockerfile, docker-compose setups) that manage container orchestration and deployment environments.

##### Relationships and interactions
- Inside the application, request routing directs traffic to the respective modules (e.g., Auth, Kweeks, Users) using their controllers.
- The application’s business logic (inside services) then interacts with external systems:
- The Prisma service makes queries/transactions against PostgreSQL.
- The S3 (or MinIO) service handles file management.
- Redis is accessed for caching or pub/sub events (e.g., notifications).
- Optionally, include connections between modules if they depend on one another (like using a shared user service in both auth and kweeks).

##### Architectural patterns/design principles
- Modularity: Each domain (auth, kweeks, users) is encapsulated in its own module, promoting separation of concerns.
- RESTful design: Controllers are structured to expose endpoints that follow RESTful conventions.
- Infrastructure as Code: Docker and docker-compose are used to define environment settings and service orchestration.
- Database Migrations: Prisma schema and migration directories underline a versioned and managed approach to database evolution.

##### Relevant technologies and frameworks
- NestJS and Fastify – mark these as the core frameworks for handling HTTP requests and server logic.
- Prisma – denote this as the ORM facilitating communication with PostgreSQL.
- PostgreSQL, Redis, MinIO – Represent these as the key external systems integrated via Docker.
- Other tools: Swagger for API documentation, TypeScript for language features, and Docker for containerization.

## Diagram (Mermaid)

```mermaid
flowchart TD
    client("Client/Browser"):::external

    subgraph "NestJS API Server"
        main("API Bootstrap (src/main.ts)"):::core
        app("Core Module (src/app.module.ts)"):::core

        subgraph "Modules"
            authModule("Auth Module (src/auth/auth.module.ts)"):::module
            authController("Auth Controller (src/auth/auth.controller.ts)"):::module
            authService("Auth Service (src/auth/auth.service.ts)"):::module
            strategies("Auth Strategies (src/auth/jwt.strategy.ts & src/auth/local.strategy.ts)"):::module
            guards("Auth Guards (src/auth/jwt-auth.guard.ts & src/auth/local-auth.guard.ts)"):::module

            kweeksModule("Kweeks Module (src/kweeks/kweeks.module.ts)"):::module
            kweeksController("Kweeks Controller (src/kweeks/kweeks.controller.ts)"):::module
            kweeksService("Kweeks Service (src/kweeks/kweeks.service.ts)"):::module
            commentsController("Comments Controller (src/kweeks/comments.controller.ts)"):::module
            commentsService("Comments Service (src/kweeks/comments.service.ts)"):::module

            usersModule("Users Module (src/users/users.module.ts)"):::module
            usersController("Users Controller (src/users/users.controller.ts)"):::module
            usersService("Users Service (src/users/users.service.ts)"):::module

            subgraph "Common Services"
                prismaModule("Prisma Module (src/services/prisma/prisma.module.ts)"):::service
                prismaService("Prisma Service (src/services/prisma/prisma.service.ts)"):::service
                s3("S3 Service (src/services/s3/s3.service.ts)"):::service
            end

            validators("Custom Validators (src/validators)"):::validator
        end
    end

    subgraph "External Services"
        pg("PostgreSQL"):::database
        redis("Redis"):::external
        minio("MinIO"):::external
    end

    subgraph "Deployment"
        dockerfile("Dockerfile"):::infrastructure
        dockercompose("docker-compose.yml"):::infrastructure
        dockerComposeDB("docker-compose.db.yml"):::infrastructure
        dockerEnv("docker.env.example"):::infrastructure
    end

    client -->|"HTTP_Request"| main
    main --> app
    app --> authModule
    app --> kweeksModule
    app --> usersModule
    authModule --> authController
    authModule --> authService
    authModule --> strategies
    authModule --> guards
    kweeksModule --> kweeksController
    kweeksModule --> kweeksService
    kweeksModule --> commentsController
    kweeksModule --> commentsService
    usersModule --> usersController
    usersModule --> usersService
    app --> prismaModule
    prismaModule --> prismaService
    prismaService -->|"DB_Queries"| pg
    app --> s3
    s3 -->|"File_Operations"| minio
    app --> validators
    validators -->|"Cache_Session"| redis
    dockerfile --- main
    dockercompose --- main
    dockerComposeDB --- main
    dockerEnv --- main

    click main "https://github.com/hknsh/project-knedita/blob/master/src/main.ts"
    click app "https://github.com/hknsh/project-knedita/blob/master/src/app.module.ts"
    click authModule "https://github.com/hknsh/project-knedita/blob/master/src/auth/auth.module.ts"
    click authController "https://github.com/hknsh/project-knedita/blob/master/src/auth/auth.controller.ts"
    click authService "https://github.com/hknsh/project-knedita/blob/master/src/auth/auth.service.ts"
    click strategies "https://github.com/hknsh/project-knedita/blob/master/src/auth/jwt.strategy.ts"
    click guards "https://github.com/hknsh/project-knedita/blob/master/src/auth/jwt-auth.guard.ts"
    click kweeksModule "https://github.com/hknsh/project-knedita/blob/master/src/kweeks/kweeks.module.ts"
    click kweeksController "https://github.com/hknsh/project-knedita/blob/master/src/kweeks/kweeks.controller.ts"
    click kweeksService "https://github.com/hknsh/project-knedita/blob/master/src/kweeks/kweeks.service.ts"
    click commentsController "https://github.com/hknsh/project-knedita/blob/master/src/kweeks/comments.controller.ts"
    click commentsService "https://github.com/hknsh/project-knedita/blob/master/src/kweeks/comments.service.ts"
    click usersModule "https://github.com/hknsh/project-knedita/blob/master/src/users/users.module.ts"
    click usersController "https://github.com/hknsh/project-knedita/blob/master/src/users/users.controller.ts"
    click usersService "https://github.com/hknsh/project-knedita/blob/master/src/users/users.service.ts"
    click prismaModule "https://github.com/hknsh/project-knedita/blob/master/src/services/prisma/prisma.module.ts"
    click prismaService "https://github.com/hknsh/project-knedita/blob/master/src/services/prisma/prisma.service.ts"
    click s3 "https://github.com/hknsh/project-knedita/blob/master/src/services/s3/s3.service.ts"
    click validators "https://github.com/hknsh/project-knedita/tree/master/src/validators"
    click dockerfile "https://github.com/hknsh/project-knedita/tree/master/Dockerfile"
    click dockercompose "https://github.com/hknsh/project-knedita/blob/master/docker-compose.yml"
    click dockerComposeDB "https://github.com/hknsh/project-knedita/blob/master/docker-compose.db.yml"
    click dockerEnv "https://github.com/hknsh/project-knedita/blob/master/docker.env.example"

classDef core fill:#f9f,stroke:#333,stroke-width:2px
classDef module fill:#cfc,stroke:#333,stroke-width:2px
classDef service fill:#ccf,stroke:#333,stroke-width:2px
classDef validator fill:#fc9,stroke:#333,stroke-width:2px
classDef external fill:#fdd,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
classDef database fill:#dff,stroke:#333,stroke-width:2px
classDef infrastructure fill:#ffd,stroke:#333,stroke-width:2px
```
