# yamori/cidrizer architecture

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

- Interactive diagram: https://gitdiagram.com/yamori/cidrizer
- Repository: https://github.com/yamori/cidrizer

## Overview

##### Main Components Identification

a. Web Interface Layer
- EJS templating engine (views directory)
- Frontend components (pages and partials)

b. Application Layer
- Main server (index.js)
- Serverless handler (serverless_for_lambda.js)
- Core CIDR processing module (cidrizer.js)

c. Deployment Options
- Traditional web server
- AWS Lambda (indicated by serverless.yml)

**[Client Layer]**

- ▼
**[Load Balancer/API Gateway]**

- ┐

- ▼                     ▼
**[Web Server]        [AWS Lambda]**
**(index.js)    (serverless_for_lambda.js)**

- ┬─────────┘

- ▼
- [CIDR Processing Module]
- (modules/cidrizer.js)

##### Important Details

a. Request Flow:
- How requests can come through either the traditional web server or Lambda
- API endpoint (/do_cidr/) for CURL requests
- Template rendering flow for web interface

b. Processing Flow:
- Demonstrate how the cidrizer module processes CIDR calculations
- Validation and error handling paths
- Output formatting process

##### Technical Specifications

- Node.js runtime (v13.7)
- npm version (v6.13)
- EJS templating engine
- Serverless framework
- AWS Lambda support

Create distinct sections for:
a. User Interface Layer
- EJS templates
- Partial views
- Result rendering

b. Processing Layer
- CIDR calculations
- Range validation
- Overlap detection

c. Deployment Layer
- Traditional server
- Serverless functions

##### Key Interactions

Highlight:
- Input validation flow
- CIDR space calculations
- Error handling paths
- Response formatting

Remember to include both synchronous paths (web interface) and asynchronous paths (API calls) in the request handling flow, and clearly indicate where the core CIDR processing logic is shared between both deployment options.

This architecture should clearly demonstrate how the application can handle both web-based and API-based interactions while maintaining consistent CIDR processing logic across both deployment models.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]:::client
        CURL["CURL/API Client"]:::client
    end

    subgraph "Gateway Layer"
        LB["Load Balancer/API Gateway"]:::gateway
    end

    subgraph "Deployment Layer"
        WS["Web Server"]:::server
        Lambda["AWS Lambda"]:::aws
        click WS "https://github.com/yamori/cidrizer/blob/master/index.js"
        click Lambda "https://github.com/yamori/cidrizer/blob/master/serverless_for_lambda.js"
    end

    subgraph "Processing Layer"
        CIDR["CIDR Processing Module"]:::core
        click CIDR "https://github.com/yamori/cidrizer/blob/master/modules/cidrizer.js"
    end

    subgraph "Web Interface Layer"
        Templates["EJS Templates"]:::ui
        MainPage["Main Page Template"]:::ui
        Results["Result Display"]:::ui
        Errors["Error Displays"]:::ui
        UIComps["UI Components"]:::ui
        click Templates "https://github.com/yamori/cidrizer/tree/master/views"
        click MainPage "https://github.com/yamori/cidrizer/blob/master/views/pages/index.ejs"
        click Results "https://github.com/yamori/cidrizer/blob/master/views/partials/cidr_results.ejs"
        click Errors "https://github.com/yamori/cidrizer/blob/master/views/partials/cidr_warning.ejs"
        click UIComps "https://github.com/yamori/cidrizer/tree/master/views/partials"
    end

    subgraph "Testing Layer"
        Parser["Parser Tests"]:::test
        CoreTests["Core Logic Tests"]:::test
        DebugTests["Debug Tests"]:::test
        click Parser "https://github.com/yamori/cidrizer/blob/master/test/test_parsing.js"
        click CoreTests "https://github.com/yamori/cidrizer/blob/master/test/test_theProcedure.js"
        click DebugTests "https://github.com/yamori/cidrizer/blob/master/test/test_debugging.js"
    end

    Browser --> LB
    CURL --> LB
    LB --> WS
    LB --> Lambda
    WS --> CIDR
    Lambda --> CIDR
    WS --> Templates
    Templates --> MainPage
    Templates --> Results
    Templates --> Errors
    Templates --> UIComps
    CIDR -.-> Parser
    CIDR -.-> CoreTests
    CIDR -.-> DebugTests

    classDef client fill:#3498db,stroke:#2980b9,color:white
    classDef gateway fill:#e67e22,stroke:#d35400,color:white
    classDef server fill:#2ecc71,stroke:#27ae60,color:white
    classDef aws fill:#f1c40f,stroke:#f39c12,color:black
    classDef core fill:#9b59b6,stroke:#8e44ad,color:white
    classDef ui fill:#1abc9c,stroke:#16a085,color:white
    classDef test fill:#e74c3c,stroke:#c0392b,color:white

    %% Legend
    subgraph Legend
        L1["Client Components"]:::client
        L2["Gateway Layer"]:::gateway
        L3["Server Components"]:::server
        L4["AWS Services"]:::aws
        L5["Core Processing"]:::core
        L6["UI Components"]:::ui
        L7["Testing Components"]:::test
    end
```
