# hugocbb/gerenciador-de-tarefas architecture

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

- Interactive diagram: https://gitdiagram.com/hugocbb/gerenciador-de-tarefas
- Repository: https://github.com/hugocbb/gerenciador-de-tarefas

## Overview

##### Project type and purpose
- This is a full-stack task-management web app (“tarefas” = tasks) with:
- A Go/Gin RESTful backend (controllers, models, GORM+Postgres)
- A React/Vite SPA frontend (pages, components, Axios-style API service)
- Users can register/login, manage tasks (CRUD), with JWT-style or session auth via middleware.

##### File structure
- Top-level:
- backend/ → Go server code
- frontend/ → React app
- backend layers:
- cmd/server/main.go → entry point
- config/ → env vars (godotenv), global config
- routers/ → Gin route definitions
- middleware/ → auth & request guards
- controllers/ → HTTP request handlers
- models/ → GORM structs for User & Tarefa
- database/ → DB connection (Postgres)
- frontend layers:
- src/pages/ → route targets (Home, Login, Cadastrar, Profile, Tarefas)
- src/components/ → reusable UI (Card, Navbar)
- src/services/Api/ → HTTP client wrapper for backend endpoints
- App.jsx + main.jsx → top-level router & mount

##### README for additional insights
- Backend uses Gin, GORM, bcrypt, Godotenv, Air (hot reload)
- Frontend uses React, Vite, ES6+, npm scripts
- DB = PostgreSQL, auth via bcrypt + middleware

a. Main components:
- Client Browser / React SPA
- API Service Layer (frontend service/Api)
- HTTP(s) / Internet
- Backend Server (Gin)
– Router
– Middleware (Auth)
– Controllers (User, Tarefas)
– Models & GORM
– Config & Env Loader
- Database (PostgreSQL)
- External tools (Air hot reload, Godotenv)
b. Relationships & interactions:
1. User interacts with React SPA → triggers UI events
2. SPA → Ajax calls via Api service → Gin endpoints
3. Gin Router dispatches → Middleware → Controllers
4. Controllers use GORM models → Query/Mutate Postgres
5. DB returns data → Controller → JSON → SPA
c. Architectural patterns & principles:
- Layered MVC-style: routers → controllers → models → DB
- Separation of concerns: config, middleware, controllers, models
- Single Page Application (SPA) on frontend, REST API on backend
- Env-driven configuration (12-factor app)
d. Key technologies & libraries:
- Backend: Go 1.19+, Gin, GORM, bcrypt, godotenv, Air, PostgreSQL
- Frontend: React, Vite, Axios-style service
- Build/deploy: npm, go mod, Air hot reload

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Browser
    subgraph "Client Browser"
        Browser["User in Browser"]:::frontend
    end

    %% Frontend Layer
    subgraph "Frontend (React App)"
        App["App.jsx"]:::frontend
        Main["main.jsx"]:::frontend
        ApiSvc["Api Service Layer"]:::frontend
        subgraph "Pages"
            Home["Home Page"]:::frontend
            Login["Login Page"]:::frontend
            Cadastrar["Cadastrar Page"]:::frontend
            Profile["Profile Page"]:::frontend
            TarefasPage["Tarefas Page"]:::frontend
        end
        subgraph "UI Components"
            Card["Card"]:::frontend
            Navbar["Navbar"]:::frontend
        end
    end

    %% Build Config
    subgraph "Build & Config"
        Vite["vite.config.js"]:::external
    end

    %% Backend Layer
    subgraph "Backend (Go/Gin)"
        mainGo["main.go"]:::backend
        config["config.go"]:::backend
        routers["routers.go"]:::backend
        subgraph "Middleware"
            MW["middleware.go"]:::backend
            AuthGuard["requireAuth.go"]:::backend
        end
        subgraph "Controllers"
            UserCtrl["usuarioController.go"]:::backend
            TaskCtrl["tarefasControllers.go"]:::backend
        end
        subgraph "Models & DB"
            UserModel["user.go"]:::backend
            TaskModel["tarefas.go"]:::backend
            DBConn["db.go"]:::backend
            DB["PostgreSQL"]:::database
        end
        Air[".air.toml"]:::external
    end

    %% Data Flow
    Browser -->|"User Actions"| App
    App -->|"Renders Router"| Main
    Main -->|"Imports"| ApiSvc
    Main -->|"Routes To"| Home
    Main -->|"Routes To"| Login
    Main -->|"Routes To"| Cadastrar
    Main -->|"Routes To"| Profile
    Main -->|"Routes To"| TarefasPage
    Home -->|"Uses"| Card
    Login -->|"Uses"| Card
    Cadastrar -->|"Uses"| Card
    Profile -->|"Uses"| Card
    TarefasPage -->|"Uses"| Card
    Home -->|"Navigation"| Navbar
    Login -->|"Navigation"| Navbar
    Cadastrar -->|"Navigation"| Navbar
    Profile -->|"Navigation"| Navbar
    TarefasPage -->|"Navigation"| Navbar
    ApiSvc -->|"HTTP/JSON"| routers
    Vite -->|"Build/Serve"| Main
    mainGo -->|"Loads Env"| config
    mainGo -->|"Starts Server"| routers
    routers -->|"Intercept"| MW
    MW -->|"Authenticate"| AuthGuard
    MW -->|"Dispatch"| UserCtrl
    MW -->|"Dispatch"| TaskCtrl
    UserCtrl -->|"Queries/Mutates"| UserModel
    TaskCtrl -->|"Queries/Mutates"| TaskModel
    UserModel -->|"DB Conn"| DB
    TaskModel -->|"DB Conn"| DB
    DBConn -->|"Connects"| DB
    Air -->|"Hot Reload"| mainGo

    %% Click Events
    click App "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/src/App.jsx"
    click Main "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/src/main.jsx"
    click Home "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/src/pages/Home/index.jsx"
    click Login "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/src/pages/Login/index.jsx"
    click Cadastrar "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/src/pages/Cadastrar/index.jsx"
    click Profile "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/src/pages/Profile/index.jsx"
    click TarefasPage "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/src/pages/Tarefas/index.jsx"
    click Card "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/src/components/Card/index.jsx"
    click Navbar "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/src/components/Navbar/index.jsx"
    click ApiSvc "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/src/services/Api/index.jsx"
    click Vite "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/frontend/vite.config.js"
    click mainGo "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/cmd/server/main.go"
    click config "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/config/config.go"
    click routers "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/routers/routers.go"
    click MW "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/middleware/middleware.go"
    click AuthGuard "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/middleware/requireAuth.go"
    click UserCtrl "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/controllers/usuarioController.go"
    click TaskCtrl "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/controllers/tarefasControllers.go"
    click UserModel "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/models/user.go"
    click TaskModel "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/models/tarefas.go"
    click DBConn "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/database/db.go"
    click Air "https://github.com/hugocbb/gerenciador-de-tarefas/blob/main/backend/.air.toml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef database fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
