# duydev/rao-vat architecture

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

- Interactive diagram: https://gitdiagram.com/duydev/rao-vat
- Repository: https://github.com/duydev/rao-vat

## Overview

##### Main Components

A. Frontend Layer (Next.js):
- Client-side Components
- Server-side Components (Next.js Pages)
- API Integration Layer
- Routing System

B. Backend Layer (Go):
- HTTP Server
- Domain Layer
- Use Cases Layer
- Repository Layer
- Infrastructure Layer

C. Database:
- Firestore (Firebase)

D. Cloud Infrastructure:
- Vercel (Frontend Hosting)
- Google Cloud Run (Backend Hosting)

**[Client Browser] → [Frontend (Vercel)] → [Backend (Cloud Run)] → [Firestore]**

##### Key Relationships to Highlight

- Frontend to Backend API calls (via articles-api.js)
- Backend Clean Architecture layers interaction
- Database operations flow
- Cloud platform integration points

##### Specific Implementation Details

Frontend Flow:
**[Pages] → [Components] → [API Layer] → [Backend Requests]**

Backend Flow:
**[HTTP Handlers] → [Use Cases] → [Domain] → [Repository] → [Firestore]**

##### Additional Notes

- Clean architecture boundaries in the backend
- Stateless nature of the services
- Deployment flows
- Error handling paths

##### Implementation Recommendations

- Version information
- Notes for important architectural decisions
- Scaling points

This system design should emphasize:

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph Cloud["Cloud Infrastructure"]
        Vercel["Vercel Platform"]
        CloudRun["Google Cloud Run"]
    end

    subgraph Frontend["Frontend Layer"]
        direction TB
        Pages["Pages"]
        Components["Components"]:::component
        APILayer["API Integration Layer"]:::api
        Router["Routing System"]:::router

        subgraph Pages
            HomePage["Homepage"]:::page
            CreatePage["Article Creation Page"]:::page
            DetailPage["Article Detail Page"]:::page
        end
    end

    subgraph Backend["Backend Layer"]
        direction TB
        HTTPServer["HTTP Server"]:::server
        BackendRouter["Router"]:::router

        subgraph Handlers["Handlers Layer"]
            ArticleHandlers["Article Handlers"]:::handler
        end

        subgraph Domain["Domain Layer"]
            ArticleDomain["Article Domain"]:::domain
        end

        subgraph UseCases["Use Cases Layer"]
            ArticleUseCases["Article Use Cases"]:::usecase
        end

        subgraph Repository["Repository Layer"]
            ArticleRepo["Article Repository"]:::repo
        end

        DBInfra["Database Infrastructure"]:::infra
    end

    subgraph Database
        Firestore[(Firestore)]
    end

    %% Connections
    Browser --> Vercel
    Vercel --> Frontend
    Frontend --> CloudRun
    CloudRun --> Backend
    Backend --> Firestore

    %% Frontend Internal Connections
    Router --> Pages
    Pages --> Components
    Pages --> APILayer
    APILayer --> HTTPServer

    %% Backend Internal Connections
    HTTPServer --> BackendRouter
    BackendRouter --> ArticleHandlers
    ArticleHandlers --> ArticleUseCases
    ArticleUseCases --> ArticleDomain
    ArticleDomain --> ArticleRepo
    ArticleRepo --> DBInfra
    DBInfra --> Firestore

    %% Click Events
    click Router "https://github.com/duydev/rao-vat/tree/main/frontend/src/app/"
    click Components "https://github.com/duydev/rao-vat/tree/main/frontend/src/app/components/"
    click APILayer "https://github.com/duydev/rao-vat/blob/main/frontend/src/app/apis/articles-api.js"
    click HTTPServer "https://github.com/duydev/rao-vat/blob/main/backend/infra/http/server.go"
    click BackendRouter "https://github.com/duydev/rao-vat/blob/main/backend/infra/http/router.go"
    click ArticleHandlers "https://github.com/duydev/rao-vat/tree/main/backend/infra/http/handlers/"
    click ArticleDomain "https://github.com/duydev/rao-vat/blob/main/backend/app/domains/article_domain.go"
    click ArticleUseCases "https://github.com/duydev/rao-vat/tree/main/backend/app/usecases/article/"
    click ArticleRepo "https://github.com/duydev/rao-vat/blob/main/backend/infra/repositories/article_repository.go"
    click DBInfra "https://github.com/duydev/rao-vat/blob/main/backend/infra/database/firestore.go"
    click HomePage "https://github.com/duydev/rao-vat/blob/main/frontend/src/app/page.jsx"
    click CreatePage "https://github.com/duydev/rao-vat/blob/main/frontend/src/app/dang-tin/page.jsx"
    click DetailPage "https://github.com/duydev/rao-vat/blob/main/frontend/src/app/[slug]/page.jsx"

    %% Styles
    classDef default fill:#fff,stroke:#333,stroke-width:2px
    classDef component fill:#a8d1ff,stroke:#333
    classDef api fill:#ffb3ba,stroke:#333
    classDef router fill:#baffc9,stroke:#333
    classDef server fill:#ffffba,stroke:#333
    classDef handler fill:#ffdfba,stroke:#333
    classDef domain fill:#bae1ff,stroke:#333
    classDef usecase fill:#dcd3ff,stroke:#333
    classDef repo fill:#c4ffd4,stroke:#333
    classDef infra fill:#ffdcf4,stroke:#333
    classDef page fill:#e6e6e6,stroke:#333
```
