# matheusmendescosta/api-my-blog architecture

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

- Interactive diagram: https://gitdiagram.com/matheusmendescosta/api-my-blog
- Repository: https://github.com/matheusmendescosta/api-my-blog

## Overview

##### Project type and purpose
- This is a backend REST API template built with Node.js, Express and TypeScript.
- It uses a layered (hexagonal/clean) architecture: HTTP layer (controllers & routes), business logic layer (services), data access layer (repositories & Prisma), plus utilities for email and environment management.
- It’s containerized with Docker, supports Prisma migrations, and includes CI/CD workflows for build and release.

##### File structure
- Top level: Docker-related files, GitHub Actions workflows, Prisma configs, `src/`, and template scripts in `bin/`.
- `src/server.ts` boots Express; `src/app.ts` wires middleware, routes, error handlers.
- HTTP layer in `src/http`:
- `routes/route.ts` aggregates entity routes.
- `controllers/…`: each resource (user, post, comment, etc.) has controllers mapped to HTTP endpoints.
- `middlewares/`: authentication and rate-limiting.
- Business logic in `src/services`: one folder per domain, each with specialized use-case classes.
- Data access in `src/repositories`: interface definitions + Prisma implementations in `src/repositories/prisma`.
- Utility layers: `src/lib` for Prisma client instantiation and Nodemailer setup; `src/emails` for templated emails.
- Config and env reading in `src/env`.
- Docker and docker-compose define containers for the API and database, migrations.
- Prisma migrations under `prisma/migrations`, schema in `prisma/schema.prisma`.

##### README
- Confirms purpose as a boilerplate/template to start an Express + TypeScript project quickly.

- Don’t simply list files—abstract them into components: e.g., “UserController” rather than every single controller file.
- Middleware applied globally or per-route.
- Prisma Client as the bridge between your code and the relational database.
- Environment config being loaded at startup.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Docker Containers
    subgraph "Docker Environment"
      direction TB

      subgraph "API Container"
        direction TB
        Env["Environment Config"]:::env
        Server["Express Server\n(src/server.ts)"]:::app
        App["Application Setup\n(src/app.ts)"]:::app

        subgraph "HTTP Layer"
          direction TB
          Routes["Routes\n(src/http/routes/route.ts)"]:::http
          Middlewares["Middlewares\n(auth & rate-limit)"]:::http
          Controllers["Controllers\n(src/http/controllers/)"]:::http
        end

        subgraph "Business Logic Layer"
          direction TB
          Services["Services\n(src/services/)"]:::biz
        end

        subgraph "Data Access Layer"
          direction TB
          Repos["Repositories\n(src/repositories/)"]:::data
          PrismaClient["Prisma Client\n(src/lib/prisma.ts)"]:::data
        end

        subgraph "Utilities & Emails"
          direction TB
          EmailLib["Nodemailer Setup\n(src/lib/nodemailer.tsx)"]:::util
          EmailTemplates["Email Templates\n(src/emails/)"]:::util
        end

        Env --> Server --> App
        App --> Routes
        Routes --> Middlewares --> Controllers
        Controllers --> Services
        Services --> Repos
        Repos --> PrismaClient
        PrismaClient --> DB
        Services --> EmailLib --> SMTP
      end

      subgraph "Database Container"
        direction TB
        DB["PostgreSQL\n(prisma/schema.prisma)"]:::db
      end
    end

    %% External Entities
    Client["Client"]:::external
    SMTP["SMTP Provider"]:::external

    Client -->|HTTP Request| Routes

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
      direction TB
      GH["GitHub Actions"]:::ci
      Build["Build & Test"]:::ci
      Deploy["Release"]:::ci
      GH --> Build --> Deploy
    end

    %% Click Events
    click Server "https://github.com/matheusmendescosta/api-my-blog/blob/main/src/server.ts"
    click App "https://github.com/matheusmendescosta/api-my-blog/blob/main/src/app.ts"
    click Routes "https://github.com/matheusmendescosta/api-my-blog/blob/main/src/http/routes/route.ts"
    click Controllers "https://github.com/matheusmendescosta/api-my-blog/tree/main/src/http/controllers/"
    click Middlewares "https://github.com/matheusmendescosta/api-my-blog/blob/main/src/http/middlewares/authenticate-middleware.ts"
    click Middlewares "https://github.com/matheusmendescosta/api-my-blog/blob/main/src/http/middlewares/rate-limit-middleware.ts"
    click Services "https://github.com/matheusmendescosta/api-my-blog/tree/main/src/services/"
    click Repos "https://github.com/matheusmendescosta/api-my-blog/tree/main/src/repositories/"
    click PrismaClient "https://github.com/matheusmendescosta/api-my-blog/blob/main/src/lib/prisma.ts"
    click DB "https://github.com/matheusmendescosta/api-my-blog/blob/main/prisma/schema.prisma"
    click EmailLib "https://github.com/matheusmendescosta/api-my-blog/blob/main/src/lib/nodemailer.tsx"
    click EmailTemplates "https://github.com/matheusmendescosta/api-my-blog/tree/main/src/emails/"
    click Env "https://github.com/matheusmendescosta/api-my-blog/blob/main/src/env/index.ts"
    click GH "https://github.com/matheusmendescosta/api-my-blog/blob/main/.github/workflows/build.yml"
    click Deploy "https://github.com/matheusmendescosta/api-my-blog/blob/main/.github/workflows/release.yml"

    %% Styles
    classDef http fill:#D6EAF8,stroke:#1B4F72,color:#1B2631;
    classDef biz fill:#D5F5E3,stroke:#145A32,color:#1D8348;
    classDef data fill:#FDEBD0,stroke:#B9770E,color:#784212;
    classDef util fill:#E5E7E9,stroke:#566573,color:#1C2833;
    classDef env fill:#E8DAEF,stroke:#6C3483,color:#512E5F;
    classDef app fill:#D6DBDF,stroke:#424949,color:#1C2833;
    classDef db fill:#F9E79F,stroke:#B7950B,color:#7D6608;
    classDef ci fill:#FCF3CF,stroke:#B7950B,color:#7D6608;
    classDef external fill:#F5EEF8,stroke:#7D3C98,color:#4A235A;
```
