# instagram-clone-coding/spring_instagram-clone architecture

> Architecture diagram of the GitHub repository instagram-clone-coding/spring_instagram-clone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/instagram-clone-coding/spring_instagram-clone
- Repository: https://github.com/instagram-clone-coding/spring_instagram-clone

## Overview

##### Main Components
- Controllers per Domain: Each module has its own REST controller layer (e.g., MemberAuthController, PostController, ChatController, etc.)
- Services: Business logic is encapsulated in service classes (e.g., MemberService, PostService, ChatService, etc.).
- Data Access Layer (Repositories): Using Spring Data JPA, JDBC, and Querydsl repositories.
- Global Configuration & Cross-cutting Concerns:
– Security & Authentication (Spring Security filters, JWT authentication providers, security handlers, etc.)
– Exception Handling (Centralized using @RestControllerAdvice)
– Global Configurations (SwaggerConfig, AsyncConfig, QuerydslConfig, RedisConfig, etc.)
- Infrastructure Integration:
– AWS S3 integration for image uploads and storage (S3Uploader)
– Email service for confirmations and resets
– Kakao API for map/location support
– Redis for caching, refresh tokens, and temporary codes (like RegisterCode, ResetPasswordCode)
- External Systems:
– MySQL for persistent relational data storage
– Redis as an in-memory datastore for caching and session/token management

##### Layered Architecture and Relationships
- Client Layer: External requests from the frontend (or any client) arrive via HTTP.
- Presentation Layer: Controllers which expose REST endpoints.
- Service (Business Logic) Layer: Connect controllers to service classes that process requests.
- Data Access Layer: Services call Repository components using JPA/Querydsl.
- Infrastructure Layer:
– Security Components: Show integration with filters (JwtAuthenticationFilter, Custom Exception Filters), security providers for authentication.
– External Integrations: AWS S3, Email, Kakao, and Redis are used by various service modules.
– Database: Connect the Repository layer to MySQL.
– Caching/Session Management: Connect services or security layer to Redis.

##### Architectural Patterns/Principles
- Layered architecture / Clean separation between Controller, Service, and Repository.
- Use of Domain-Driven Design: Multiple domain modules (member, feed, dm, follow, hashtag, story, alarm, search, etc.) are self-contained, following similar folder structures (controller, service, dto, entity, repository, exception).
- Security and Error-Handling are implemented in a cross-cutting manner using AOP and global exception handling (with a unified ErrorResponse and ResultResponse design).
- Use of Dependency Injection and Inversion of Control via Spring Boot.

– A “Presentation” tier (Controllers), “Business Logic” (Services), “Persistence” (Repositories).
c. A “Security” block where filters (JwtAuthenticationFilter, ReissueAuthenticationFilter, etc.) and provider components reside.
f. Configuration components (e.g., SwaggerConfig, GlobalExceptionHandler, AsyncConfig) that affect multiple domains.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client (Frontend)"):::client

    subgraph "Presentation Layer"
        MC("Member REST Controller"):::presentation
        FC("Feed REST Controller"):::presentation
        DC("DM REST Controller"):::presentation
    end

    subgraph "Business Logic Layer"
        MS("Member Service"):::service
        PS("Feed Service"):::service
        CS("DM Service"):::service
    end

    subgraph "Data Access Layer"
        MR("Member Repository"):::repository
        PR("Post Repository"):::repository
        RTR("RefreshTokenRedisRepository"):::repository
    end

    subgraph "Global & Configurations"
        WSC("WebSecurityConfig"):::global
        JAF("JwtAuthenticationFilter"):::global
        JAP("JwtAuthenticationProvider"):::global
        GEH("GlobalExceptionHandler"):::global
        SC("SwaggerConfig"):::global
        AC("AsyncConfig"):::global
        QC("QuerydslConfig"):::global
        RC("RedisConfig"):::global
    end

    subgraph "External Integrations"
        AW("AWS S3 Integration"):::infra
        EM("Email Integration"):::infra
        KA("Kakao API Integration"):::infra
    end

    MySQL[(MySQL)]:::external
    RedisDB[(Redis)]:::external

    %% Client to Presentation Layer
    Client -->|"HTTP"| MC
    Client -->|"HTTP"| FC
    Client -->|"HTTP"| DC

    %% Presentation to Business Logic
    MC -->|"ServiceCall"| MS
    FC -->|"ServiceCall"| PS
    DC -->|"ServiceCall"| CS

    %% Business Logic to Data Access
    MS -->|"DataAccess"| MR
    PS -->|"DataAccess"| PR
    MS -->|"DataAccess"| RTR

    %% Data Access to External Databases
    MR -->|"Stores"| MySQL
    PR -->|"Stores"| MySQL
    RTR -->|"Stores"| RedisDB

    %% Global Config influences Presentation Layer
    WSC -.-> MC
    WSC -.-> FC
    WSC -.-> DC
    JAF -.-> MC
    JAF -.-> FC
    JAF -.-> DC
    JAP -.-> MC
    JAP -.-> FC
    JAP -.-> DC
    GEH -.-> MC
    GEH -.-> FC
    GEH -.-> DC

    %% Business Logic integration with External Services
    MS -.-> AW
    MS -.-> EM
    PS -.-> AW
    PS -.-> KA
    CS -.-> AW
    CS -.-> KA

    %% Redis configuration connection
    RC -.-> RedisDB

    %% Styles
    classDef client fill:#ccf,stroke:#333,stroke-width:2px;
    classDef presentation fill:#f9f,stroke:#333,stroke-width:2px;
    classDef service fill:#cfc,stroke:#333,stroke-width:2px;
    classDef repository fill:#fc9,stroke:#333,stroke-width:2px;
    classDef global fill:#cff,stroke:#333,stroke-width:2px;
    classDef infra fill:#fcc,stroke:#333,stroke-width:2px;
    classDef external fill:#efe,stroke:#333,stroke-width:2px;

    %% Click Events
    click MC "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/domain/member/controller/MemberAuthController.java"
    click FC "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/domain/feed/controller/PostController.java"
    click DC "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/domain/dm/controller/ChatController.java"
    click MS "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/domain/member/service/MemberService.java"
    click PS "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/domain/feed/service/PostService.java"
    click CS "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/domain/dm/service/ChatService.java"
    click MR "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/domain/member/repository/MemberRepository.java"
    click PR "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/domain/feed/repository/PostRepository.java"
    click RTR "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/domain/member/repository/redis/RefreshTokenRedisRepository.java"
    click WSC "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/global/config/security/WebSecurityConfig.java"
    click JAF "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/global/config/security/filter/JwtAuthenticationFilter.java"
    click JAP "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/global/config/security/provider/JwtAuthenticationProvider.java"
    click GEH "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/global/error/GlobalExceptionHandler.java"
    click SC "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/global/config/SwaggerConfig.java"
    click AC "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/global/config/AsyncConfig.java"
    click QC "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/global/config/QuerydslConfig.java"
    click RC "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/global/config/RedisConfig.java"
    click AW "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/infra/aws/S3Uploader.java"
    click EM "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/infra/email/EmailService.java"
    click KA "https://github.com/instagram-clone-coding/spring_instagram-clone/blob/develop/src/main/java/cloneproject/Instagram/infra/kakao/KakaoMap.java"
```
