# jhonydomingos/backend-just-connect architecture

> Architecture diagram of the GitHub repository jhonydomingos/backend-just-connect, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jhonydomingos/backend-just-connect
- Repository: https://github.com/jhonydomingos/backend-just-connect

## Overview

##### Main Components
- Client/Request Entry Point: Although the client isn’t part of the repository, note that HTTP requests (from web or mobile clients) hit the API server.
- API Server: Represent the Node.js-based server which is organized into layers:
- Routes: Divided into public and private routes (see src/routes/public and src/routes/private). These define the endpoints and dispatch requests.
- Controllers: Under src/controllers, each module (auth, comments, posts, notifications, search, tag, user) has its own controller that handles HTTP request logic.
- Services: Under src/services, the core business logic is implemented. Each controller calls a corresponding service (for example, CreatePostService, LikePostService, etc.) that encapsulates the core functionality and domain rules.
- Middlewares: In src/middlewares, you have modules for authentication, authorization (Permissions), handling errors, and other common concerns.
- Error Handling: The “src/Error” folder defines custom errors and enums for standard error messages which wrap around the controllers/middlewares.
- Schemas and Interfaces: These define data validation rules (like in src/schemas) and types (in src/interfaces) to ensure structure and consistency.
- Prisma Layer: Use the prisma directory and src/prisma to manage database connections and migrations (handled via Prisma’s ORM, with migration history evident in the file tree).
- Documentation: Swagger is integrated (swagger.ts and swagger_output.json) for API documentation.
- Database: Represented by the underlying SQL database, which is set up and managed through Prisma migrations (see the migrations folder in prisma).

##### Relationships & Interactions
- Requests enter through the server (in src/server.ts) which uses middleware stacks (authentication, permissions, error handling).
- The defined Routes (grouped as public/private) map the request paths to the appropriate controllers.
- Each Controller then calls its corresponding Service to carry out business logic.
- Services interact with the database through the Prisma client.
- The Error Handling and Middlewares ensure uniform responses to clients.
- Docker-compose (docker-compose.yml) indicates that the application (and possibly its dependencies, such as the database) may be containerized and interacting in a multi-container environment.
- External services like email (for password recovery) are handled through dedicated service files (e.g., EmailService.ts).

##### Architectural Patterns & Design Principles
- Layered Architecture: Separation into routing, controller, service, and data access layers.
- Modular Structure: Each feature (auth, post, comment, user, tag, notifications) is broken out into its own subdirectories for controllers, services, and interfaces.
- Clean Error Handling: Centralized error objects and middleware to standardize error responses.
- Dependency Organization: Notice how the project uses Prisma with clearly defined migrations and schemas, and integration with middleware to validate and sanitize inputs.
- Integration with API Docs: Swagger is used for API discovery and documentation.

##### Detail
- Element is labeled with enough detail to understand which component is handling what responsibility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client/External"):::client
    Client -->|"HTTP_Request"| API("API Server"):::server

    subgraph "API Server"
        ServerEntry("Server Entry Point"):::server_entry
        subgraph "Routes Layer"
            PublicRoutes("Public Routes"):::routes
            PrivateRoutes("Private Routes"):::routes
        end
        subgraph "Controllers Layer"
            AuthControllers("Auth Controllers"):::controllers
            PostControllers("Post Controllers"):::controllers
            CommentControllers("Comment Controllers"):::controllers
            NotificationControllers("Notification Controllers"):::controllers
            SearchControllers("Search Controllers"):::controllers
            TagControllers("Tag Controllers"):::controllers
            UserControllers("User Controllers"):::controllers
        end
        subgraph "Services Layer"
            AuthServices("Auth Services"):::services
            PostServices("Post Services"):::services
            CommentServices("Comment Services"):::services
            NotificationServices("Notification Services"):::services
            SearchServices("Search Services"):::services
            TagServices("Tag Services"):::services
            UserServices("User Services"):::services
            EmailService("Email Service"):::services
        end
        subgraph "Middlewares Layer"
            AuthMiddleware("Auth Middleware"):::middleware
            PermissionsMiddleware("Permissions Middleware"):::middleware
            EnsureMiddleware("Ensure Middleware"):::middleware
            ErrorHandlingMiddleware("Error Handling Middleware"):::middleware
        end
        ErrorDefinitions("Error Definitions"):::error
        Schemas("Schemas"):::schemas
        Interfaces("Interfaces"):::interfaces
        SwaggerDocs("Swagger Docs"):::docs
    end

    subgraph "Data Layer"
        PrismaClient("Prisma Client"):::prisma
        PrismaMigrations("Prisma Migrations"):::prisma
        Database("Database (SQL)"):::database
    end

    DockerCompose("Docker Compose"):::docker

    API --> ServerEntry
    ServerEntry --> PublicRoutes
    ServerEntry --> PrivateRoutes

    PublicRoutes --> AuthControllers
    PublicRoutes --> PostControllers
    PublicRoutes --> CommentControllers
    PublicRoutes --> NotificationControllers
    PublicRoutes --> SearchControllers
    PublicRoutes --> TagControllers
    PublicRoutes --> UserControllers

    PrivateRoutes --> AuthControllers
    PrivateRoutes --> PostControllers
    PrivateRoutes --> CommentControllers
    PrivateRoutes --> NotificationControllers
    PrivateRoutes --> SearchControllers
    PrivateRoutes --> TagControllers
    PrivateRoutes --> UserControllers

    AuthControllers --> AuthServices
    PostControllers --> PostServices
    CommentControllers --> CommentServices
    NotificationControllers --> NotificationServices
    SearchControllers --> SearchServices
    TagControllers --> TagServices
    UserControllers --> UserServices

    AuthServices --> EmailService

    AuthServices --> PrismaClient
    PostServices --> PrismaClient
    CommentServices --> PrismaClient
    NotificationServices --> PrismaClient
    SearchServices --> PrismaClient
    TagServices --> PrismaClient
    UserServices --> PrismaClient

    PrismaClient --> Database
    PrismaMigrations --> Database

    DockerCompose --> API
    DockerCompose --> Database

    %% Cross-layer interactions (illustrative)
    AuthMiddleware -.-> PublicRoutes
    PermissionsMiddleware -.-> PrivateRoutes
    EnsureMiddleware -.-> PublicRoutes
    ErrorHandlingMiddleware -.-> AuthControllers
    ErrorHandlingMiddleware -.-> AuthMiddleware

    %% Click Events
    click ServerEntry "https://github.com/jhonydomingos/backend-just-connect/blob/developer/src/server.ts"
    click PublicRoutes "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/routes/public"
    click PrivateRoutes "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/routes/private"
    click AuthControllers "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/controllers/auth"
    click PostControllers "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/controllers/post"
    click CommentControllers "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/controllers/comments"
    click NotificationControllers "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/controllers/notifications"
    click SearchControllers "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/controllers/search"
    click TagControllers "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/controllers/tag"
    click UserControllers "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/controllers/user"
    click AuthServices "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/services/auth"
    click PostServices "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/services/post"
    click CommentServices "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/services/comments"
    click NotificationServices "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/services/notifications"
    click SearchServices "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/services/search"
    click TagServices "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/services/tag"
    click UserServices "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/services/user"
    click AuthMiddleware "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/middlewares/auth"
    click PermissionsMiddleware "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/middlewares/Permissions"
    click EnsureMiddleware "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/middlewares/ensure"
    click ErrorHandlingMiddleware "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/middlewares/handleErrors"
    click ErrorDefinitions "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/Error"
    click Schemas "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/schemas"
    click Interfaces "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/interfaces"
    click PrismaClient "https://github.com/jhonydomingos/backend-just-connect/tree/developer/src/prisma"
    click PrismaMigrations "https://github.com/jhonydomingos/backend-just-connect/tree/developer/prisma"
    click SwaggerDocs "https://github.com/jhonydomingos/backend-just-connect/blob/developer/swagger.ts"
    click DockerCompose "https://github.com/jhonydomingos/backend-just-connect/blob/developer/docker-compose.yml"

    %% Class Definitions for Colors
    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef server fill:#ccf,stroke:#333,stroke-width:2px;
    classDef server_entry fill:#ccf,stroke:#333,stroke-width:2px;
    classDef routes fill:#ffd,stroke:#d96,stroke-width:2px;
    classDef controllers fill:#cfc,stroke:#393,stroke-width:2px;
    classDef services fill:#fcf,stroke:#939,stroke-width:2px;
    classDef middleware fill:#cff,stroke:#399,stroke-width:2px;
    classDef error fill:#fbb,stroke:#933,stroke-width:2px;
    classDef schemas fill:#bfb,stroke:#484,stroke-width:2px;
    classDef interfaces fill:#bbf,stroke:#446,stroke-width:2px;
    classDef docs fill:#ff9,stroke:#994,stroke-width:2px;
    classDef prisma fill:#ddf,stroke:#55a,stroke-width:2px;
    classDef database fill:#fdd,stroke:#a55,stroke-width:2px;
    classDef docker fill:#efe,stroke:#393,stroke-width:2px;
```
