# 96glory/syk-springboot-webservice architecture

> Architecture diagram of the GitHub repository 96glory/syk-springboot-webservice, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/96glory/syk-springboot-webservice
- Repository: https://github.com/96glory/syk-springboot-webservice

## Overview

##### Main Components

a. Client Layer:
- Web Browser (Client)
- Static Resources (JS, Mustache templates)
- Nginx (Reverse Proxy for zero-downtime deployment)

b. Application Layer:
- Spring Boot Application (Two instances for zero-downtime deployment)
- Core Components:
- Web Controllers (REST APIs)
- Service Layer
- Repository Layer
- Security Configuration
- OAuth2 Integration

c. Data Layer:
- MariaDB (AWS RDS)
- H2 Database (Testing)

d. External Services:
- Google OAuth2
- AWS Services (S3, CodeDeploy)
- Travis CI

**[Client Layer]**
- ↓
**[Nginx Layer]**
- ↓
**[Application Layer]**
- ↓
**[Data Layer]**

**[GitHub] → [Travis CI] → [AWS S3] → [AWS CodeDeploy] → [EC2 Instances]**

##### Component Relationships to Highlight

a. Request Flow:
**Client → Nginx → Spring Boot (8081/8082) → Database**

b. Authentication Flow:
**Client → Spring Security → Google OAuth2 → User Session**

c. Deployment Flow:
**GitHub → Travis CI → S3 → CodeDeploy → EC2 (Nginx + Spring Boot)**

##### Key Technical Details

a. Application Components:
- Controllers: HelloController, IndexController, PostsApiController
- Services: PostsService
- Repositories: PostsRepository, UserRepository
- Security: SecurityConfig, CustomOAuth2UserService
- Domain: Posts, User entities

b. Infrastructure Details:
- Nginx load balancing between ports 8081 and 8082
- MariaDB RDS connection
- Session management
- AWS EC2 instance configuration

##### Additional Elements

- Component types

b. Annotations for:
- Port numbers
- Database schemas
- Key configuration files
- API endpoints

##### Zero-Downtime Deployment Flow

Process of:
##### Traffic redirection

- The separation of concerns between layers
- The role of each AWS service
- The security implementation
- The zero-downtime deployment strategy
- The test coverage and CI/CD pipeline

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that make this project unique, such as the zero-downtime deployment strategy and the OAuth2 implementation.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph ClientLayer
        Browser["Web Browser"]:::client
        StaticRes["Static Resources"]:::client
        click StaticRes "https://github.com/96glory/syk-springboot-webservice/tree/master/src/main/resources/static"
    end

    %% Nginx Layer
    subgraph NginxLayer
        Nginx["Nginx Reverse Proxy"]:::infra
        click Nginx "https://github.com/96glory/syk-springboot-webservice/blob/master/nginx/service-url.inc"
    end

    %% Application Layer
    subgraph AppLayer
        subgraph Instance1
            App1["Spring Boot (8081)"]:::app
            Controllers1["Web Controllers"]:::component
            click Controllers1 "https://github.com/96glory/syk-springboot-webservice/tree/master/src/main/java/com/glory/book/springboot/web"
            Security1["Security Config"]:::component
            click Security1 "https://github.com/96glory/syk-springboot-webservice/blob/master/src/main/java/com/glory/book/springboot/config/auth/SecurityConfig.java"
            Service1["Service Layer"]:::component
            click Service1 "https://github.com/96glory/syk-springboot-webservice/blob/master/src/main/java/com/glory/book/springboot/service/posts/PostsService.java"
            Repo1["Repository Layer"]:::component
            click Repo1 "https://github.com/96glory/syk-springboot-webservice/blob/master/src/main/java/com/glory/book/springboot/domain/posts/PostsRepository.java"
        end

        subgraph Instance2
            App2["Spring Boot (8082)"]:::app
            Controllers2["Web Controllers"]:::component
            Security2["Security Config"]:::component
            Service2["Service Layer"]:::component
            Repo2["Repository Layer"]:::component
        end
    end

    %% Data Layer
    subgraph DataLayer
        MariaDB["MariaDB (RDS)"]:::database
        H2["H2 Database (Test)"]:::database
    end

    %% External Services
    subgraph ExternalServices
        OAuth["Google OAuth2"]:::external
        S3["AWS S3"]:::external
        CodeDeploy["AWS CodeDeploy"]:::external
    end

    %% CI/CD Pipeline
    subgraph CIPipeline
        GitHub["GitHub"]:::cicd
        Travis["Travis CI"]:::cicd
        click Travis "https://github.com/96glory/syk-springboot-webservice/blob/master/.travis.yml"
        Deploy["Deployment Scripts"]:::cicd
        click Deploy "https://github.com/96glory/syk-springboot-webservice/blob/master/scripts/deploy.sh"
    end

    %% Relationships
    Browser --> Nginx
    Nginx --> App1
    Nginx --> App2
    App1 --> MariaDB
    App2 --> MariaDB
    Controllers1 --> Service1
    Service1 --> Repo1
    Controllers2 --> Service2
    Service2 --> Repo2
    Security1 --> OAuth
    Security2 --> OAuth
    GitHub --> Travis
    Travis --> S3
    S3 --> CodeDeploy
    CodeDeploy --> App1
    CodeDeploy --> App2

    %% Styles
    classDef client fill:#3498db,stroke:#2980b9,color:#fff
    classDef app fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef component fill:#95a5a6,stroke:#7f8c8d,color:#fff
    classDef database fill:#f1c40f,stroke:#f39c12,color:#fff
    classDef external fill:#e67e22,stroke:#d35400,color:#fff
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:#fff
    classDef cicd fill:#9b59b6,stroke:#8e44ad,color:#fff

    %% Legend
    subgraph Legend
        Client["Client Component"]:::client
        AppComp["Application Component"]:::app
        DataStore["Data Storage"]:::database
        ExtService["External Service"]:::external
        Infrastructure["Infrastructure"]:::infra
        CICD["CI/CD Component"]:::cicd
    end
```
