# yilbertluna/pio architecture

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

- Interactive diagram: https://gitdiagram.com/yilbertluna/pio
- Repository: https://github.com/yilbertluna/pio

## Overview

##### Main Components
- Frontend: Built with Next.js and Tailwind CSS, organized within the “frontend” directory. Include sub-components like pages (login, profile, notifications, etc.) and UI components (navbar, inputs, forms).
- Backend: Built with Node.js and Express located in the “backend” directory. Organize it further into controllers, models, routers, schemas, and middleware.
- Database: As defined in the README, the system uses PostgreSQL with at least two primary tables (User and Publication) with a clear relationship (userId as a foreign key in the publication table).
- Docker & Compose: Container orchestration for both the frontend and backend, ensuring consistent deployment and smooth development via docker-compose.
- External Services: Mention any external authentication or JWT processes (as seen in backend/src/libs/jwt.js) and potential integrations.

##### Relationships and Interactions
- Data Flow:
- User Actions (e.g., registration, login, posting content) are initiated from the Frontend and sent to the Backend API endpoints.
- The Backend handles these requests (via its controllers and routes), validates them using middleware and schemas, then interacts with the PostgreSQL database to perform CRUD operations.
- Responses from the backend are communicated back to the frontend to update the UI.
- Communication between containers: Use docker-compose to illustrate how the frontend, backend, and database containers interact (even if database service configuration is not explicit in the file tree, the README and backend code imply connectivity).

##### Architectural Patterns and Design Principles
- API Layer: In the backend, segmentation into routers, controllers, and models suggests an MVC (Model-View-Controller) pattern.
- Middleware & Security: Usage of JWT authentication and token validation middleware in the backend.
- Separation of Concerns: Clear directory separation between frontend and backend, with each layer handling its specific part of the functionality.
- Containerization: Emphasize the Docker containers for both application layers which simplify deployment and scaling.

##### Following Elements
- Clear labels:
- “Frontend (Next.js/Tailwind CSS)”
- “Backend (Node.js/Express)”
- “Database (PostgreSQL)”
- “Docker Container Environment”
- User interactions from client-side to backend API endpoints.
- API requests/responses between the frontend and the backend.
- Database queries and data retrieval between the backend and the PostgreSQL database.
- User interface elements versus server-side logic.
- Containerized components (highlighting Docker usage) versus the actual application code.
- Security middleware (like JWT) and validation processes within the backend, such as in the “middleware” and “libs” directories.
- If needed, a small inset to illustrate the database schema (with User and Publication tables) as described in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    User["User (Client)"]:::user

    %% Docker Container Environment
    subgraph "Docker Container Environment"
        direction LR
        FEContainer["Frontend Container"]:::docker
        BEContainer["Backend Container"]:::docker
        DockerCompose["Docker Compose"]:::docker
    end

    %% Frontend Layer
    subgraph "Frontend Layer (Next.js/Tailwind CSS)"
        direction TB
        FE["Frontend (Next.js/Tailwind CSS)"]:::frontend
        subgraph "Frontend Pages"
            direction TB
            LoginPage["Login Page"]:::frontendPage
            ProfilePage["Profile Page"]:::frontendPage
            NotificationsPage["Notifications Page"]:::frontendPage
            ExplorePage["Explore Page"]:::frontendPage
        end
        subgraph "Frontend UI Components"
            direction TB
            Navbar["Navbar"]:::frontendComponent
            Input["Input Component"]:::frontendComponent
            LoginForm["Login Form"]:::frontendComponent
            RegisterForm["Register Form"]:::frontendComponent
            Post["Post Component"]:::frontendComponent
            Logout["Logout Component"]:::frontendComponent
            Settings["Settings Component"]:::frontendComponent
        end
    end

    %% Backend Layer
    subgraph "Backend Layer (Node.js/Express)"
        direction TB
        BE["Backend (Node.js/Express)"]:::backend
        subgraph "Backend Controllers"
            direction TB
            UserController["User Controller"]:::backendController
            PublicationController["Publication Controller"]:::backendController
        end
        subgraph "Backend Models"
            direction TB
            UserModel["User Model"]:::backendModel
            PublicationModel["Publication Model"]:::backendModel
        end
        subgraph "Backend Routers"
            direction TB
            UserRoutes["User Routes"]:::backendRouter
            PublicationRoutes["Publication Routes"]:::backendRouter
        end
        subgraph "Backend Middleware & Schemas"
            direction TB
            ValidatorMiddleware["Validator Middleware"]:::backendMiddleware
            TokenMiddleware["Token Middleware"]:::backendMiddleware
            AuthSchema["Auth Schema"]:::backendSchema
            PostSchema["Post Schema"]:::backendSchema
        end
        JWT["JWT Service"]:::backendLib
    end

    %% Database Layer
    Database["Database (PostgreSQL)"]:::database

    %% Connections Between Layers
    User -->|"interacts"| FE
    FE -->|"sendsAPIRequest"| BE
    BE -->|"performsCRUD"| Database

    %% Containerization Connections
    FEContainer -->|"hosts"| FE
    BEContainer -->|"hosts"| BE
    DockerCompose -->|"orchestrates"| FEContainer
    DockerCompose -->|"orchestrates"| BEContainer
    BEContainer ---|"connects"| Database

    %% Internal Frontend Connections
    FE --> LoginPage
    FE --> ProfilePage
    FE --> NotificationsPage
    FE --> ExplorePage
    FE --> Navbar
    FE --> Input
    FE --> LoginForm
    FE --> RegisterForm
    FE --> Post
    FE --> Logout
    FE --> Settings

    %% Internal Backend Connections
    BE --> UserController
    BE --> PublicationController
    BE --> UserModel
    BE --> PublicationModel
    BE --> UserRoutes
    BE --> PublicationRoutes
    BE --> ValidatorMiddleware
    BE --> TokenMiddleware
    BE --> AuthSchema
    BE --> PostSchema
    BE --> JWT

    %% Click Events for Frontend Mapping
    click FE "https://github.com/yilbertluna/pio/tree/master/frontend/"
    click LoginPage "https://github.com/yilbertluna/pio/blob/master/frontend/src/app/login/page.tsx"
    click ProfilePage "https://github.com/yilbertluna/pio/blob/master/frontend/src/app/(navBar)/profile/page.tsx"
    click NotificationsPage "https://github.com/yilbertluna/pio/blob/master/frontend/src/app/(navBar)/notifications/page.tsx"
    click ExplorePage "https://github.com/yilbertluna/pio/blob/master/frontend/src/app/(navBar)/explore/page.tsx"
    click Navbar "https://github.com/yilbertluna/pio/tree/master/frontend/src/components/navbar/"
    click Input "https://github.com/yilbertluna/pio/blob/master/frontend/src/components/Input/index.tsx"
    click LoginForm "https://github.com/yilbertluna/pio/blob/master/frontend/src/components/forms/loginForm/index.tsx"
    click RegisterForm "https://github.com/yilbertluna/pio/blob/master/frontend/src/components/forms/registerForm/index.tsx"
    click Post "https://github.com/yilbertluna/pio/tree/master/frontend/src/components/post/"
    click Logout "https://github.com/yilbertluna/pio/tree/master/frontend/src/components/logout/"
    click Settings "https://github.com/yilbertluna/pio/tree/master/frontend/src/components/setings/"

    %% Click Events for Backend Mapping
    click BE "https://github.com/yilbertluna/pio/tree/master/backend/"
    click UserController "https://github.com/yilbertluna/pio/blob/master/backend/src/controllers/user.controller.js"
    click PublicationController "https://github.com/yilbertluna/pio/blob/master/backend/src/controllers/publications.controller.js"
    click UserModel "https://github.com/yilbertluna/pio/blob/master/backend/src/models/user.js"
    click PublicationModel "https://github.com/yilbertluna/pio/blob/master/backend/src/models/publications.js"
    click UserRoutes "https://github.com/yilbertluna/pio/blob/master/backend/src/router/user.routes.js"
    click PublicationRoutes "https://github.com/yilbertluna/pio/blob/master/backend/src/router/publication.routes.js"
    click ValidatorMiddleware "https://github.com/yilbertluna/pio/blob/master/backend/src/middleware/validatorMiddleware.js"
    click TokenMiddleware "https://github.com/yilbertluna/pio/blob/master/backend/src/middleware/validatorToken.js"
    click AuthSchema "https://github.com/yilbertluna/pio/blob/master/backend/src/schema/auth.schema.js"
    click PostSchema "https://github.com/yilbertluna/pio/blob/master/backend/src/schema/post.schema.js"
    click JWT "https://github.com/yilbertluna/pio/blob/master/backend/src/libs/jwt.js"

    %% Click Events for Docker Mapping
    click FEContainer "https://github.com/yilbertluna/pio/tree/master/frontend/Dockerfile"
    click BEContainer "https://github.com/yilbertluna/pio/tree/master/backend/Dockerfile"
    click DockerCompose "https://github.com/yilbertluna/pio/blob/master/compose.yaml"

    %% Class Definitions for Styling
    classDef user fill:#ffdb99,stroke:#d98c00,stroke-width:2px;
    classDef docker fill:#cce5ff,stroke:#3399ff,stroke-width:2px;
    classDef frontend fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef frontendPage fill:#e2f0d9,stroke:#28a745,stroke-width:2px;
    classDef frontendComponent fill:#fefefe,stroke:#17a2b8,stroke-width:2px;
    classDef backend fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef backendController fill:#f5c6cb,stroke:#dc3545,stroke-width:2px;
    classDef backendModel fill:#f1b0b7,stroke:#dc3545,stroke-width:2px;
    classDef backendRouter fill:#f1b0b7,stroke:#dc3545,stroke-width:2px;
    classDef backendMiddleware fill:#f5c6cb,stroke:#c82333,stroke-width:2px;
    classDef backendSchema fill:#f1b0b7,stroke:#c82333,stroke-width:2px;
    classDef backendLib fill:#f5c6cb,stroke:#c82333,stroke-width:2px;
    classDef database fill:#ffeeba,stroke:#ffc107,stroke-width:2px;
```
