# tharshen2124/strayos-backend architecture

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

- Interactive diagram: https://gitdiagram.com/tharshen2124/strayos-backend
- Repository: https://github.com/tharshen2124/strayos-backend

## Overview

##### Main Components

A. API Layer
- Two main controller groups:
- Stray Pets Controller
- User Controller (with both Google OAuth and Legacy Auth)

B. Middleware Layer
- Auth Middleware as a security layer between API requests and controllers

C. Business Logic Layer
- Models component showing the data structures
- Utils component containing shared utilities:
- JWT handling
- Password hashing
- Error handling
- Response formatting
- Environment configuration
- Input validation

D. External Services Integration
- Cloudinary SDK integration for (likely) image handling
- Google OAuth service connection

E. Database Layer
- Database connection and management

F. Logging System
- Custom logging implementation with styles and variants

**[Client Requests]**
- ↓
**[API Gateway]**
- ↓
**[Auth Middleware]**
- ↓
**[Controllers Layer]**
- ↓
**[Business Logic Layer]**
- ↓
**[Database Layer]**

##### Specific Implementation Details

A. External Clients → API Gateway
- Supported HTTP methods
- Authentication requirements

B. API Gateway → Controllers
- Split into two main paths:
- Stray Pets management flow
- User authentication flow (both Google and Legacy)

C. Controllers → Models
- Data flow between controllers and models
- CRUD operations

D. Models → Database
- Database operations
- ORM or query patterns

E. Cross-cutting Concerns
- How logging intersects with all layers
- Demonstrate error handling flow
- Middleware intervention points

##### Important Elements to Highlight

A. Authentication Flow:
- Both Google OAuth and Legacy auth paths
- JWT token generation and validation
- Demonstrate middleware authentication checks

B. Data Flow:
- Request/Response cycle
- Error handling paths
- Logging points

C. External Service Integration:
- Cloudinary interaction for media handling
- Google OAuth service communication

##### Technical Stack Indicators

- Go runtime environment
- Database system (based on connection.go)
- JWT for authentication
- Cloudinary for media management
- Google OAuth for authentication
- Custom logging system

- The system's overall architecture
- Authentication and authorization flow
- Data flow between components
- Integration points with external services
- Cross-cutting concerns like logging and error handling

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CR[Client Requests]
    end

    subgraph API_Gateway
        API[API Entry Point]:::gateway
    end

    subgraph Middleware
        AM[Auth Middleware]:::middleware
    end

    subgraph Controllers
        SPC[Stray Pets Controller]:::controller
        GOC[Google OAuth Controller]:::controller
        LAC[Legacy Auth Controller]:::controller
    end

    subgraph Business_Logic
        MOD[Data Models]:::model
        
        subgraph Utils
            JWT[JWT Handler]:::util
            HASH[Password Hash]:::util
            ERR[Error Handler]:::util
            RESP[Response Format]:::util
            ENV[Environment Config]:::util
            VAL[Input Validator]:::util
        end
    end

    subgraph External_Services
        CLD[Cloudinary SDK]:::external
        GAUTH[Google OAuth Service]:::external
    end

    subgraph Database
        DB[Database Connection]:::database
    end

    subgraph Logging
        LOG_S[Log Styles]:::logging
        LOG_V[Log Variants]:::logging
    end

    CR --> API
    API --> AM
    AM --> SPC
    AM --> GOC
    AM --> LAC
    
    SPC --> MOD
    GOC --> MOD
    LAC --> MOD
    
    MOD --> DB
    
    GOC --> GAUTH
    SPC --> CLD
    
    Utils --> MOD
    Utils --> Controllers
    
    LOG_S --> API
    LOG_S --> Controllers
    LOG_S --> Business_Logic
    LOG_V --> API
    LOG_V --> Controllers
    LOG_V --> Business_Logic

    %% Click Events
    click API "https://github.com/Tharshen2124/strayos-backend/blob/main/main.go"
    click SPC "https://github.com/Tharshen2124/strayos-backend/blob/main/Controllers/StrayPetsController/straypetscontroller.go"
    click GOC "https://github.com/Tharshen2124/strayos-backend/blob/main/Controllers/UserController/GoogleOAuthController.go"
    click LAC "https://github.com/Tharshen2124/strayos-backend/blob/main/Controllers/UserController/LegacyAuthController.go"
    click AM "https://github.com/Tharshen2124/strayos-backend/blob/main/Middleware/AuthMiddleware.go"
    click MOD "https://github.com/Tharshen2124/strayos-backend/blob/main/Models/model.go"
    click DB "https://github.com/Tharshen2124/strayos-backend/blob/main/DB/connection.go"
    click CLD "https://github.com/Tharshen2124/strayos-backend/blob/main/SDKs/cloudinary.go"
    click LOG_S "https://github.com/Tharshen2124/strayos-backend/blob/main/Log/LogStyles.go"
    click LOG_V "https://github.com/Tharshen2124/strayos-backend/blob/main/Log/LogVariants.go"
    click JWT "https://github.com/Tharshen2124/strayos-backend/blob/main/utils/JwtToken.go"
    click HASH "https://github.com/Tharshen2124/strayos-backend/blob/main/utils/hashpassword.go"
    click ERR "https://github.com/Tharshen2124/strayos-backend/blob/main/utils/ErrorHandling.go"
    click RESP "https://github.com/Tharshen2124/strayos-backend/blob/main/utils/Response.go"
    click ENV "https://github.com/Tharshen2124/strayos-backend/blob/main/utils/env.go"
    click VAL "https://github.com/Tharshen2124/strayos-backend/blob/main/utils/validator.go"

    classDef gateway fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef middleware fill:#FFE4B5,stroke:#333,stroke-width:2px;
    classDef controller fill:#87CEEB,stroke:#333,stroke-width:2px;
    classDef model fill:#87CEEB,stroke:#333,stroke-width:2px;
    classDef util fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef database fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef logging fill:#D3D3D3,stroke:#333,stroke-width:2px;
```
