# klebervirgilio/react-crud-app-with-golang architecture

> Architecture diagram of the GitHub repository klebervirgilio/react-crud-app-with-golang, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/klebervirgilio/react-crud-app-with-golang
- Repository: https://github.com/klebervirgilio/react-crud-app-with-golang

## Overview

##### Main high-level components
- Front-end SPA: React application (pkg/http/web/app)
- API Server: Go HTTP server (cmd/main.go + pkg/http)
- Service Layer: Business logic (pkg/kudo/service.go)
- Domain & Repository Interface: Core models and interfaces (pkg/core)
- Persistence Layer: MongoDB concrete repository (pkg/storage)
- Auth Provider: Okta JWT verification (pkg/http/middlewares.go)
- External API: GitHub REST API for searching repos
- Database: MongoDB (via docker-compose)

##### Relationships and data flows
- User’s browser → React UI →
- Calls Go API endpoints (/kudos) with Authorization header
- Calls GitHub API for search (client-direct)
- Redirects to Okta for login, receives JWT token
- Go API server →
- Middleware chain: CORS → JWT validation with Okta → JSON headers → Logging
- Router (httprouter) dispatches to handlers → Service layer → Repository interface
- Repository interface bound to MongoRepository implementation → MongoDB
- Go API server does *not* call GitHub API directly.
- MongoDB persists Kudo documents.

##### Architectural patterns
- Layered/Clean architecture:
- Presentation (pkg/http)
- Application/service (pkg/kudo)
- Domain (pkg/core)
- Infrastructure (pkg/storage)
- Interface-driven design: `core.Repository` interface decouples service from persistence.
- Middleware pipeline for cross-cutting concerns (auth, CORS, logging, JSON API).
- Micro-frontend-style SPA: React app isolated under `/pkg/http/web/app`.

##### Technologies/frameworks
- Front-end: React (create-react-app), Material-UI, react-router, Okta React SDK
- Back-end: Go, julienschmidt/httprouter, okta-jwt-verifier, rs/cors
- Persistence: MongoDB (globalsign/mgo driver), Docker Compose
- Build & deploy: Makefile, Procfile, Docker Compose

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Browser & Front-end
    subgraph "User Browser & Front-end"
        direction TB
        Browser["User Browser\nReact SPA"]:::frontend
        ReactApp["pkg/http/web/app"]:::frontend
        Browser -->|"load SPA"| ReactApp
        ReactApp -->|"https://api.github.com/search/... "| GitHubAPI
        ReactApp -->|"redirect to Okta\n(OIDC flow)"| OktaAuth
        ReactApp -->|"GET/POST/DELETE /kudos\nBearer <JWT>"| APIServer
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GitHubAPI["GitHub REST API"]:::external
        OktaAuth["Okta Auth (OIDC)\nJWT Verification"]:::external
    end

    %% API Server Layer
    subgraph "API Server"
        direction TB
        APIServer["Go API Server"]:::api
        EntryPoint["cmd/main.go"]:::api
        Handlers["pkg/http/handlers.go"]:::api
        Middleware["pkg/http/middlewares.go"]:::api
        APIServer --> EntryPoint
        EntryPoint --> Middleware
        Middleware --> Handlers
        Handlers --> Service
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        Service["pkg/kudo/service.go"]:::api
        Service --> Domain
    end

    %% Domain Layer
    subgraph "Domain & Repository Interface"
        direction TB
        KudoModel["pkg/core/kudo.go"]:::api
        RepoInterface["pkg/core/repository.go"]:::api
        Service --> KudoModel
        Service --> RepoInterface
    end

    %% Persistence Layer
    subgraph "Infrastructure & Persistence"
        direction TB
        MongoRepo["pkg/storage/mongo.go"]:::persistence
        MongoTests["pkg/storage/mongo_test.go\npkg/storage/storage_suite_test.go"]:::persistence
        DockerCompose["docker-compose.yml"]:::persistence
        DBSetup["cmd/db/setup.go"]:::persistence
        RepoInterface --> MongoRepo
        MongoRepo --> MongoDB
    end

    %% Database
    subgraph "Database"
        direction TB
        MongoDB["MongoDB Container"]:::persistence
    end

    %% Auth Verification Flow
    OktaAuth -->|"Okta JWT verification"| Middleware

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:1px;
    classDef api fill:#d4edda,stroke:#333,stroke-width:1px;
    classDef persistence fill:#fff3cd,stroke:#333,stroke-width:1px;
    classDef external fill:#e2e3e5,stroke:#333,stroke-width:1px;

    %% Click Events
    click ReactApp "https://github.com/klebervirgilio/react-crud-app-with-golang/tree/master/pkg/http/web/app"
    click EntryPoint "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/cmd/main.go"
    click Handlers "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/pkg/http/handlers.go"
    click Middleware "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/pkg/http/middlewares.go"
    click Service "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/pkg/kudo/service.go"
    click KudoModel "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/pkg/core/kudo.go"
    click RepoInterface "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/pkg/core/repository.go"
    click MongoRepo "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/pkg/storage/mongo.go"
    click MongoTests "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/pkg/storage/mongo_test.go"
    click MongoTests "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/pkg/storage/storage_suite_test.go"
    click DockerCompose "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/docker-compose.yml"
    click DBSetup "https://github.com/klebervirgilio/react-crud-app-with-golang/blob/master/cmd/db/setup.go"
```
