# mochavin/fp-pbkk architecture

> Architecture diagram of the GitHub repository mochavin/fp-pbkk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mochavin/fp-pbkk
- Repository: https://github.com/mochavin/fp-pbkk

## Overview

##### Main Components

A. Client Layer:
- Next.js Frontend (Port 3000)
- Route structure (/auth, /protected)
- Components (BoardList, KanbanBoard)
- UI components library (shadcn/ui)
- Firebase integration for authentication

B. API Layer:
- Go Backend Server (Port 8080)
- Controllers (auth, board, card, list)
- Middleware (authentication)
- Routes
- Database connection

C. Database Layer:
- PostgreSQL Database
- Main entities (boards, lists, cards, users)

**[Client Tier]**

- Next.js Frontend                        |
- Public Routes                        |
- Login                            |
- Signup                           |
- Protected Routes                     |
- Boards View                      |
- Kanban Board                     |
- [Show UI Components & Firebase Auth]    |

- ↕️ HTTP/REST
**[API Tier]**

- Go Backend (Gin Framework)              |
- Controllers                          |
- AuthController                   |
- BoardController                  |
- ListController                   |
- CardController                   |
- Middleware                          |
- Routes                              |

- ↕️ GORM
**[Data Tier]**

- PostgreSQL Database                     |
- Users                               |
- Boards                              |
- Lists                               |
- Cards                               |

##### Important Elements to Highlight

a. Authentication Flow:
- JWT token flow between frontend and backend
- Firebase authentication integration
- Auth middleware protection

b. Data Flow:
- REST API calls between frontend and backend
- Database operations through GORM
- Real-time updates system

c. Key Features:
- Board management
- Operations
- Card handling
- User collaboration

##### Technical Details

- API endpoints structure
- Database schema relationships
- Authentication flow
- Real-time update mechanism
- Error handling paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        FE[Next.js Frontend]
        subgraph Routes["Route Structure"]
            AR["Auth Routes"]:::frontend
            PR["Protected Routes"]:::frontend
            BL["Board List"]:::frontend
            KB["Kanban Board"]:::frontend
        end
        UI["UI Components"]:::frontend
        FB["Firebase Auth"]:::auth
        AC["API Client"]:::frontend
        UC["User Context"]:::frontend
    end

    subgraph API["API Layer"]
        BE[Go Backend Server]
        subgraph Controllers["Controllers"]
            AuthC["Auth Controller"]:::backend
            BoardC["Board Controller"]:::backend
            ListC["List Controller"]:::backend
            CardC["Card Controller"]:::backend
        end
        AM["Auth Middleware"]:::auth
        RT["Routes"]:::backend
        DC["DB Connection"]:::backend
    end

    subgraph Data["Data Layer"]
        DB[(PostgreSQL)]
        subgraph Models["Database Models"]
            Users[("Users")]:::db
            Boards[("Boards")]:::db
            Lists[("Lists")]:::db
            Cards[("Cards")]:::db
        end
        Migrations["DB Migrations"]:::db
    end

    %% Relationships
    FE --> AC
    AC --> BE
    FB --> FE
    AR --> FB
    PR --> UC
    BE --> AM
    AM --> Controllers
    Controllers --> RT
    RT --> DC
    DC --> DB

    %% Click events
    click AR "https://github.com/mochavin/FP-PBKK/tree/main/frontend/src/app/(auth)"
    click PR "https://github.com/mochavin/FP-PBKK/tree/main/frontend/src/app/(protected)"
    click UI "https://github.com/mochavin/FP-PBKK/tree/main/frontend/src/components/ui"
    click FB "https://github.com/mochavin/FP-PBKK/blob/main/frontend/src/lib/firebase.js"
    click AC "https://github.com/mochavin/FP-PBKK/blob/main/frontend/src/lib/api.ts"
    click Controllers "https://github.com/mochavin/FP-PBKK/tree/main/backend/controllers"
    click AM "https://github.com/mochavin/FP-PBKK/blob/main/backend/middlewares/auth.go"
    click RT "https://github.com/mochavin/FP-PBKK/blob/main/backend/routes/routes.go"
    click DC "https://github.com/mochavin/FP-PBKK/blob/main/backend/config/db.go"
    click Models "https://github.com/mochavin/FP-PBKK/tree/main/backend/models"
    click Migrations "https://github.com/mochavin/FP-PBKK/tree/main/backend/migrations"
    click KB "https://github.com/mochavin/FP-PBKK/blob/main/frontend/src/app/(protected)/boards/detail/KanbanBoard.tsx"
    click BL "https://github.com/mochavin/FP-PBKK/blob/main/frontend/src/app/(protected)/boards/BoardList.tsx"
    click UC "https://github.com/mochavin/FP-PBKK/blob/main/frontend/src/contexts/user-context.tsx"
    click AuthC "https://github.com/mochavin/FP-PBKK/blob/main/backend/controllers/auth_controller.go"
    click BoardC "https://github.com/mochavin/FP-PBKK/blob/main/backend/controllers/board_controller.go"
    click CardC "https://github.com/mochavin/FP-PBKK/blob/main/backend/controllers/card_controller.go"
    click ListC "https://github.com/mochavin/FP-PBKK/blob/main/backend/controllers/list_controller.go"

    %% Styles
    classDef frontend fill:#2563eb,color:white
    classDef backend fill:#16a34a,color:white
    classDef db fill:#ca8a04,color:white
    classDef auth fill:#dc2626,color:white

    %% Legend
    subgraph Legend
        FrontendL["Frontend Component"]:::frontend
        BackendL["Backend Component"]:::backend
        DatabaseL["Database Component"]:::db
        AuthL["Auth Component"]:::auth
    end
```
