# sapatgit/newszoid architecture

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

- Interactive diagram: https://gitdiagram.com/sapatgit/newszoid
- Repository: https://github.com/sapatgit/newszoid

## Overview

##### Main System Components Identification
The project is a microservices architecture with the following key components:

a. Frontend Layer:
- Angular-based SPA (Single Page Application)
- Contains multiple components (login, register, post, search, etc.)

b. API Gateway Layer:
- Zuul API Gateway for routing and security
- JWT authentication implementation

c. Service Discovery:
- Eureka Server for service registration and discovery

d. Configuration Management:
- Config Server for centralized configuration

e. Microservices:
- Login Service (Authentication)
- Registration Service (User Management)
- Content Service (Post Management)
- Search Service (Search Functionality)
- Recommendation Service (Neo4j-based recommendations)

**[Client Layer]**

**[API Gateway Layer]**

**[Service Discovery & Config]**

**[Microservices Layer]**

**[Data Layer]**

##### Specific Elements

a. Client Tier:
- Angular Frontend with main components
- Interaction with API Gateway

b. Gateway Layer:
- Zuul API Gateway
- JWT Authentication Filter
- Security Config

c. Infrastructure Services:
- Eureka Server
- Config Server

d. Microservices (show each with its database):
- Login Service (with User DB)
- Registration Service (with User DB)
- Content Service (with Post DB and AWS S3)
- Search Service (with Search DB)
- Recommendation Service (with Neo4j Graph DB)

e. Communication Patterns:
- REST APIs between services
- RabbitMQ message queues (shown in config files)
- JWT token flow

##### Additional Details

a. Security Flow:
- JWT token generation and validation flow
- Secured endpoints

b. Data Flow:
- User registration/login flow
- Content posting and retrieval
- Search operations
- Recommendation generation

c. Cross-Cutting Concerns:
- Service Discovery registration/lookup
- Configuration management
- Security enforcement

##### Integration Points

- External service integration (AWS S3)
- Database connections
- Message queue connections
- Service-to-service communication

##### Notes
- Scaling indicators
- Stateless vs stateful services
- Containerization (Docker)
- Service discovery mechanism

Remember to highlight the key architectural patterns:
- API Gateway Pattern
- Service Discovery Pattern
- Circuit Breaker Pattern (if implemented)
- Event-Driven Architecture (RabbitMQ)
- Database per Service Pattern

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef gateway fill:#2ecc71,stroke:#27ae60,color:white
    classDef infrastructure fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#f1c40f,stroke:#f39c12,color:black
    classDef database fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white

    %% Frontend Layer
    subgraph Frontend
        SPA["Angular SPA"]:::frontend
        Login["Login Component"]:::frontend
        Register["Register Component"]:::frontend
        Post["Post Component"]:::frontend
        Search["Search Component"]:::frontend
        Recommend["Recommendation Component"]:::frontend
        
        SPA --> Login
        SPA --> Register
        SPA --> Post
        SPA --> Search
        SPA --> Recommend
    end

    %% API Gateway Layer
    subgraph Gateway
        ZUUL["Zuul API Gateway"]:::gateway
        JWT["JWT Security"]:::security
        SecConfig["Security Config"]:::security
        JWTFilter["JWT Filter"]:::security
        
        ZUUL --> JWT
        JWT --> SecConfig
        JWT --> JWTFilter
    end

    %% Infrastructure Layer
    subgraph Infrastructure
        Eureka["Eureka Server"]:::infrastructure
        Config["Config Server"]:::infrastructure
    end

    %% Microservices Layer
    subgraph Services
        LoginSvc["Login Service"]:::service
        RegSvc["Registration Service"]:::service
        ContentSvc["Content Service"]:::service
        SearchSvc["Search Service"]:::service
        RecommendSvc["Recommendation Service"]:::service
    end

    %% Data Layer
    subgraph Databases
        UserDB[(User DB)]:::database
        PostDB[(Post DB)]:::database
        SearchDB[(Search DB)]:::database
        Neo4jDB[(Neo4j Graph DB)]:::database
        S3[("AWS S3")]:::external
    end

    %% Connections
    Frontend --> Gateway
    Gateway --> Infrastructure
    Gateway --> Services
    
    LoginSvc --> UserDB
    RegSvc --> UserDB
    ContentSvc --> PostDB
    ContentSvc --> S3
    SearchSvc --> SearchDB
    RecommendSvc --> Neo4jDB

    %% Service Discovery
    Services --> Eureka
    Gateway --> Eureka

    %% Click Events
    click SPA "https://github.com/sapatgit/newszoid/tree/master/frontend/src/app/"
    click Login "https://github.com/sapatgit/newszoid/tree/master/frontend/src/app/login/"
    click Register "https://github.com/sapatgit/newszoid/tree/master/frontend/src/app/register/"
    click Post "https://github.com/sapatgit/newszoid/tree/master/frontend/src/app/post/"
    click Search "https://github.com/sapatgit/newszoid/tree/master/frontend/src/app/search/"
    click Recommend "https://github.com/sapatgit/newszoid/tree/master/frontend/src/app/recommendation/"
    click ZUUL "https://github.com/sapatgit/newszoid/tree/master/api-gateway/"
    click JWT "https://github.com/sapatgit/newszoid/tree/master/api-gateway/src/main/java/com/stackroute/zuulapi/security/"
    click SecConfig "https://github.com/sapatgit/newszoid/blob/master/api-gateway/src/main/java/com/stackroute/zuulapi/security/SecurityTokenConfig.java"
    click JWTFilter "https://github.com/sapatgit/newszoid/blob/master/api-gateway/src/main/java/com/stackroute/zuulapi/security/JwtTokenAuthenticationFilter.java"
    click Eureka "https://github.com/sapatgit/newszoid/blob/master/eureka-server/src/main/java/com/stackroute/eurekaserver/EurekaServerApplication.java"
    click Config "https://github.com/sapatgit/newszoid/blob/master/config-server/src/main/java/com/stackroute/configserver/ConfigServerApplication.java"
    click LoginSvc "https://github.com/sapatgit/newszoid/tree/master/login-service/"
    click RegSvc "https://github.com/sapatgit/newszoid/tree/master/registration-service/"
    click ContentSvc "https://github.com/sapatgit/newszoid/tree/master/content-service/"
    click SearchSvc "https://github.com/sapatgit/newszoid/tree/master/search-service/"
    click RecommendSvc "https://github.com/sapatgit/newszoid/tree/master/recommendation-service/"
```
