# wendersoon/social_networking_app_golang architecture

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

- Interactive diagram: https://gitdiagram.com/wendersoon/social_networking_app_golang
- Repository: https://github.com/wendersoon/social_networking_app_golang

## Overview

##### Main System Components
- API Service: Encapsulated in the "api" folder. This is the backend responsible for direct interaction with the database and handles authentication (JWT), database operations, middleware processing, and response formatting.
- Web Application: Located in the "webapp" folder. This serves as the frontend layer, handling user interactions via HTML views and assets (CSS/JS), and communicating with the API service (either by proxying frontend requests or directly issuing API calls).
- Database: Although not explicitly a folder, the API contains an "sql" script (api/sql/sql.sql); hence, a database (e.g., MySQL) is required as a persistent data store.
- Environment Configurations: Both components (API and WebApp) have dedicated .env files that define critical runtime settings such as credentials and ports.

##### File Structure to Understand the Architectural Boundaries
- In the API:
- The "src" folder is organized into clear packages—autenticacao (JWT management), banco (database connection), config (environment variables), controllers (API request handling), middlewares, modelos (data structures), repositorios (database operations), respostas (API responses), router (route management), and seguranca (credential encryption).
- This separation suggests a layered architecture where each layer (from configuration and routing to business logic and data access) is isolated.
- In the Web Application:
- The "src" folder mirrors much of the API’s structure: config, controllers, middlewares, modelos, and router.
- Additional folders handle cookies, requisicoes (to call the API), and templates (views) in the "views" folder.

- API Component:
- Configuration (config)
- Authentication (autenticacao and seguranca)
- Controllers (handling HTTP requests and responses)
- Middlewares (logging, auth/validation)
- Models and Repositories (representing the business entities and data access)
- Router (defining the REST endpoints)
- Database Connection (banco)

- Web Application Component:
- Assets (CSS/JS)
- Views (HTML templates and their sub-templates)
- Controllers (routing frontend actions)
- Cookies and Sessions management
- Requisicoes (for making API calls) and corresponding responses
- Router (for organizing routes for page navigation)

- Database Component:

##### Additional Details and Architectural Patterns
- How the API and the Web Application are separated concerns – the API is entirely focused on business logic and persistent data, while the WebApp deals with UI rendering and client-side interaction.
- RESTful architecture for API endpoints.
- Use of middleware for cross-cutting concerns (logging and authentication) and the use of JWT tokens for securing endpoints.
- That configuration management is done via environment files (.env), which should be a part of the deployment considerations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser("Browser (Client)"):::browser

    %% Web Application (Frontend)
    subgraph "Web Application (Frontend)"
        WebApp("Web Application (Frontend)"):::web
        WebApp_Config("WebApp Configuration"):::web_config
        WebApp_Assets("WebApp Assets (CSS/JS)"):::web_assets
        WebApp_Templates("WebApp Templates (HTML Views)"):::web_templates
        WebApp_Controllers("WebApp Controllers"):::web_ctrl
        WebApp_Cookies("WebApp Cookies Management"):::web_cookies
        WebApp_APIReq("WebApp API Requests"):::web_req
        WebApp_Router("WebApp Router (Page Navigation)"):::web_router
    end

    %% API Service (Backend)
    subgraph "API Service (Backend)"
        API("API Service (Backend)"):::api
        API_Config("API Configuration"):::api_config
        API_AuthJWT("API Authentication (JWT)"):::api_auth
        API_AuthSec("API Authentication (Security)"):::api_auth
        API_Controllers("API Controllers (HTTP handling)"):::api_ctrl
        API_Middlewares("API Middlewares"):::api_mw
        API_Models("API Models"):::api_model
        API_Repos("API Repositories"):::api_repo
        API_Responses("API Responses"):::api_resp
        API_Router("API Router (Endpoints)"):::api_router
    end

    %% Database Component
    Database("Database (MySQL)"):::database
    Database_Schema("Database Schema/Script"):::database_schema

    %% Connections between layers
    Browser -->|"HTTPRequest"| WebApp
    WebApp_APIReq -->|"APIRequest"| API
    API -->|"DBOperation"| Database

    %% Internal API interactions
    API_Config -->|"configures"| API
    API_Config -->|"sets up"| API_Router
    API_Router -->|"routes to"| API_Controllers
    API_Controllers -->|"invokes"| API_Middlewares
    API_Middlewares -->|"validates"| API_AuthJWT
    API_AuthJWT -->|"encrypts"| API_AuthSec
    API_Controllers -->|"handles"| API_Models
    API_Models -->|"persists via"| API_Repos
    API_Repos -->|"formats"| API_Responses

    %% Internal WebApp interactions
    WebApp_Config -->|"configures"| WebApp
    WebApp_Router -->|"directs"| WebApp_Controllers
    WebApp -->|"renders"| WebApp_Templates
    WebApp_Templates -->|"uses"| WebApp_Assets
    WebApp -->|"manages"| WebApp_Cookies

    %% Database schema association
    Database ---|"contains"| Database_Schema

    %% Click Events
    click API "https://github.com/wendersoon/social_networking_app_golang/tree/main/api"
    click API_Config "https://github.com/wendersoon/social_networking_app_golang/blob/main/api/src/config/config.go"
    click API_AuthJWT "https://github.com/wendersoon/social_networking_app_golang/blob/main/api/src/autenticacao/token.go"
    click API_AuthSec "https://github.com/wendersoon/social_networking_app_golang/blob/main/api/src/seguranca/seguranca.go"
    click API_Controllers "https://github.com/wendersoon/social_networking_app_golang/tree/main/api/src/controllers"
    click API_Middlewares "https://github.com/wendersoon/social_networking_app_golang/blob/main/api/src/middlewares/middlewares.go"
    click API_Models "https://github.com/wendersoon/social_networking_app_golang/tree/main/api/src/modelos"
    click API_Repos "https://github.com/wendersoon/social_networking_app_golang/tree/main/api/src/repositorios"
    click API_Responses "https://github.com/wendersoon/social_networking_app_golang/blob/main/api/src/respostas/respostas.go"
    click API_Router "https://github.com/wendersoon/social_networking_app_golang/tree/main/api/src/router"
    click Database_Schema "https://github.com/wendersoon/social_networking_app_golang/blob/main/api/sql/sql.sql"
    click WebApp "https://github.com/wendersoon/social_networking_app_golang/tree/main/webapp"
    click WebApp_Assets "https://github.com/wendersoon/social_networking_app_golang/tree/main/webapp/assets"
    click WebApp_Templates "https://github.com/wendersoon/social_networking_app_golang/tree/main/webapp/views"
    click WebApp_Controllers "https://github.com/wendersoon/social_networking_app_golang/tree/main/webapp/src/controllers"
    click WebApp_Cookies "https://github.com/wendersoon/social_networking_app_golang/blob/main/webapp/src/cookies/cookies.go"
    click WebApp_APIReq "https://github.com/wendersoon/social_networking_app_golang/blob/main/webapp/src/requisicoes/requisicoes.go"
    click WebApp_Router "https://github.com/wendersoon/social_networking_app_golang/tree/main/webapp/src/router"
    click WebApp_Config "https://github.com/wendersoon/social_networking_app_golang/blob/main/webapp/src/config/config.go"

    %% Class Definitions (Colors)
    classDef api fill:#ffcccc,stroke:#880000,stroke-width:2px;
    classDef api_config fill:#ffdddd,stroke:#880000,stroke-width:2px;
    classDef api_auth fill:#ffe6e6,stroke:#880000,stroke-width:2px;
    classDef api_ctrl fill:#ffcccc,stroke:#880000,stroke-width:2px;
    classDef api_mw fill:#ffcccc,stroke:#880000,stroke-width:2px;
    classDef api_model fill:#ffcccc,stroke:#880000,stroke-width:2px;
    classDef api_repo fill:#ffcccc,stroke:#880000,stroke-width:2px;
    classDef api_resp fill:#ffcccc,stroke:#880000,stroke-width:2px;
    classDef api_router fill:#ffcccc,stroke:#880000,stroke-width:2px;

    classDef web fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef web_config fill:#ddffdd,stroke:#006600,stroke-width:2px;
    classDef web_assets fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef web_templates fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef web_ctrl fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef web_cookies fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef web_req fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef web_router fill:#ccffcc,stroke:#006600,stroke-width:2px;

    classDef database fill:#ccccff,stroke:#000088,stroke-width:2px;
    classDef database_schema fill:#ccccff,stroke:#000088,stroke-width:2px;
    
    classDef browser fill:#ffffcc,stroke:#999900,stroke-width:2px;
```
