# andreydovban/corporative-portal architecture

> Architecture diagram of the GitHub repository andreydovban/corporative-portal, 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/andreydovban/corporative-portal
- Repository: https://github.com/andreydovban/corporative-portal

## Overview

##### Main Components
- Backend Service:
- Entry Point: The “backend/cmd/main.go” file indicates the starting process.
- Configuration & Initialization: Files in “backend/configs” for configuration, “backend/pkg/di” for dependency injection, “backend/pkg/logger” for logging, and “backend/pkg/db” for database connectivity.
- Middleware & Request/Response Handling: Components in “backend/pkg/middleware”, “backend/pkg/request” and “backend/pkg/response” indicate layers for validation, decoding, logging, CORS, and general middleware handling.
- Migrations Utility: “backend/migrations” likely handles schema or data migrations.

- Frontend Service:
- Application Skeleton: The directory “frontend/src/app” along with layout files (e.g., layout.tsx) and various style sheets and page files indicate a Next.js app structure.
- Configuration & Build: Files like “frontend/next.config.ts”, “package.json” and ESLint configurations that help manage build, linting, and overall client-side settings.
- Public Assets & TypeScript Configurations: “frontend/public” and “frontend/tsconfig.json” for static file serving and TypeScript support.

##### Relationships & Interactions
- The frontend communicates with the backend either via RESTful APIs (or potentially GraphQL, though REST is more common given the structure) – clearly representing a client-server interaction.
- The backend, in turn, interacts with a database (as suggested by “backend/pkg/db”) and possibly other external services (mailer service under “backend/pkg/mailer”) to complete its business logic.
- Middleware and logging layers in the backend indicate that incoming HTTP requests are processed through multiple stages before reaching the internal post handlers.

##### Architectural Patterns & Principles
- Separation of Concerns: Frontend and backend components are clearly separated.
- Layered Architecture within the Backend: A clear progression from configuration and initialization, business logic (inside "internal") to infrastructure utilities (middleware, logger, db, etc.).
- Dependency Injection: The presence of a dedicated “di” package supports a design that isn’t tightly coupled, promoting testability and flexibility.
- Middleware Pipeline: Several middleware files indicate that the application uses a pipeline approach for processing requests.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Backend Section
    subgraph "Backend"
        %% Initialization Layer
        subgraph "Initialization Layer"
            BE["Backend Entry (main.go)"]:::backendEntry
            CONFIG["Configuration"]:::backendInfra
            DI["Dependency Injection"]:::backendInfra
            LOGGER["Logging Service"]:::backendInfra
            DB["Database Connectivity"]:::backendInfra
            MAILER["Mailer Service"]:::backendInfra
        end

        %% Business Logic & API Layer
        subgraph "Business Logic & API"
            POST["Business Logic (Post)"]:::businessLogic
        end

        %% Middleware & Request Handling Layer
        subgraph "Middleware & Request Handling"
            MIDDLEWARE["Middleware Pipeline"]:::middleware
            REQUEST["Request Processing"]:::middleware
            RESPONSE["Response Handling"]:::middleware
        end

        %% Migrations Utility
        MIGRATIONS["Migrations Utility"]:::migrations

        %% Internal Flows for Backend
        BE -->|"init"| CONFIG
        BE --> DI
        BE --> LOGGER
        BE --> DB
        BE --> MAILER
        BE --> MIDDLEWARE
        MIDDLEWARE --> REQUEST
        REQUEST --> RESPONSE
        RESPONSE --> POST
        DI --> POST
        LOGGER --> POST
        DB --> POST
        MAILER --> POST
        BE -->|"starts"| MIGRATIONS
    end

    %% Frontend Section
    subgraph "Frontend"
        APP["Frontend Application Structure"]:::frontend
        CONFIG_BUILD["Configuration & Build"]:::frontend
        STATIC["Static Assets"]:::frontend
        TS["TypeScript Configuration"]:::frontend

        %% Internal Flows for Frontend
        APP --> CONFIG_BUILD
        APP --> STATIC
        APP --> TS

        %% Connection to Backend API
        APP ---|"API_Call"| POST
    end

    %% Click Events for Backend Components
    click BE "https://github.com/andreydovban/corporative-portal/blob/master/backend/cmd/main.go"
    click CONFIG "https://github.com/andreydovban/corporative-portal/tree/master/backend/configs"
    click DI "https://github.com/andreydovban/corporative-portal/tree/master/backend/pkg/di"
    click LOGGER "https://github.com/andreydovban/corporative-portal/tree/master/backend/pkg/logger"
    click DB "https://github.com/andreydovban/corporative-portal/tree/master/backend/pkg/db"
    click MAILER "https://github.com/andreydovban/corporative-portal/tree/master/backend/pkg/mailer"
    click POST "https://github.com/andreydovban/corporative-portal/tree/master/backend/internal/post"
    click MIDDLEWARE "https://github.com/andreydovban/corporative-portal/tree/master/backend/pkg/middleware"
    click REQUEST "https://github.com/andreydovban/corporative-portal/tree/master/backend/pkg/request"
    click RESPONSE "https://github.com/andreydovban/corporative-portal/tree/master/backend/pkg/response"
    click MIGRATIONS "https://github.com/andreydovban/corporative-portal/tree/master/backend/migrations"

    %% Click Events for Frontend Components
    click APP "https://github.com/andreydovban/corporative-portal/tree/master/frontend/src/app"
    click CONFIG_BUILD "https://github.com/andreydovban/corporative-portal/blob/master/frontend/next.config.ts"
    click STATIC "https://github.com/andreydovban/corporative-portal/tree/master/frontend/public"
    click TS "https://github.com/andreydovban/corporative-portal/blob/master/frontend/tsconfig.json"

    %% Styles for Backend Components
    classDef backendEntry fill:#a8e6cf,stroke:#333,stroke-width:2px;
    classDef backendInfra fill:#dcedc1,stroke:#333,stroke-width:2px;
    classDef businessLogic fill:#ffd3b6,stroke:#333,stroke-width:2px;
    classDef middleware fill:#ffaaa5,stroke:#333,stroke-width:2px;
    classDef migrations fill:#ff9a76,stroke:#333,stroke-width:2px;

    %% Styles for Frontend Components
    classDef frontend fill:#a0c4ff,stroke:#333,stroke-width:2px;
```
