# moayyadfaris/susanoo architecture

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

- Interactive diagram: https://gitdiagram.com/moayyadfaris/susanoo
- Repository: https://github.com/moayyadfaris/susanoo

## Overview

##### Project Type and Purpose
- This project is a backend RESTful API with a service-based architecture. It is built using ES6 classes and emphasizes modular, action‐ and service-based design.
- Key features include JWT-based authentication, role-based access control, request validation (via Joi), CRUD operations on users and posts, API documentation generation, and migration management via Knex for PostgreSQL.
- It is clearly designed as a robust backend system that handles complex business logic, authentication, and integrations.

##### Analyzing the File Structure
- The top-level directories are highly modular:
- “acl”: Implements role-based access control policies and permissions.
- “clients”: Contains modules to interact with external systems (Email, SMS, IP lookup, Redis, S3, Slack, Queue).
- “config”: Holds configuration files for various functionalities such as JWT, basic authentication, rate limiting, and more.
- “database”: Manages Data Access Objects (DAOs), migrations, and seeds. This indicates a SQL-based persistence layer using PostgreSQL and Knex.
- “controllers” & “handlers”: Separate API layers that likely correspond to different API versions (v1/app versus v1/web) and handle incoming requests and business logic.
- “core”: Provides common classes and libraries (e.g., BaseDAO, BaseMiddleware, Logger, etc.) used throughout the project.
- “middlewares”: Contains Express-style middleware components for authentication, CORS, error handling, etc.
- “models”: Contains models that represent the business data (User, Story, Tag, etc.), likely used with an ORM/ODM or custom database layer.
- “notifications”: Stores templates and modules for sending various types of notifications.
- “sockets”: Indicates the presence of a service for real-time connections (e.g., QR Socket Service).
- Additional configuration and CI/CD files (Dockerfile, .ebextensions, Travis, Bitbucket pipelines) further suggest that the project is architected for both local and cloud deployment environments.

##### Architecture and Component Relationships
- API Layer: Clients (mobile, web frontends, or external systems) send RESTful API requests to the backend. These requests are handled via controllers located under “controllers/v1/app” and “controllers/v1/web”.
- Handlers: Once a controller receives a request, it delegates the specific business logic to handlers (organized by domain, e.g., auth, users, stories). This separation of concerns enhances clarity and testability.
- Middleware: Prior to reaching controllers/handlers, middlewares (e.g., authentication, validation, error handling) process the requests to ensure security, data integrity, and compliance with the API’s contracts.
- ACL: The “acl” module is responsible for enforcing access policies. It interacts with various controllers and handlers to control user permissions based on roles (like Admin, Editor, User, etc.).
- Data Persistence: The “database” folder contains DAOs for interacting with a PostgreSQL database. Migrations and seeds indicate how the schema is managed and data is initialized.
- External Clients: Modules under “clients” act as interface layers to external systems (for integration with email servers, SMS platforms, Redis for caching, S3 for storage, Slack for notifications, etc.). Handlers and controllers call these to send notifications or perform other integrations.
- Core Libraries: The “core” components provide fundamental functionalities (logging, configuration, error handling) that are imported across the system.
- Real-Time Communication: The “sockets” directory includes services for real-time functionalities, enhancing responsiveness for specific API features.
- Testing: The “test” directory emphasizes that automated tests are in place, ensuring that the architectural components interact as expected.

##### Key Architectural Patterns and Principles
- Modular and Layered Architecture: Distinct folders for controllers, handlers, models, middlewares, and clients illustrate a separation of concerns.
- Service-Based and Action-Based Design: Business logic is encapsulated in service handlers which are triggered by API actions.
- Role-Based Access Control (RBAC): Clearly implemented within the “acl” directory, ensuring that security and permissions are centrally managed.
- Use of Configuration and Environment Files: This shows a high level of configurability, making the system adaptable to different environments (development, testing, production).

##### Final Suggestions
- Use clear, legible labels for every component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CR("External Client Request"):::external
    APIGW("API Gateway"):::api

    subgraph "Security Layer"
        M("Middlewares: Authentication,Validation,ErrorHandling"):::middleware
        ACL("Access Control (RBAC)"):::middleware
    end

    subgraph "API Controllers Layer"
        CA1("API Controller (v1/app)"):::api
        CA2("API Controller (v1/web)"):::api
    end

    subgraph "Business Logic Layer"
        HL1("Business Logic Handler (v1/app)"):::business
        HL2("Business Logic Handler (v1/web)"):::business
        RL("Real-Time Communication Service"):::realtime
    end

    subgraph "Data Persistence Layer"
        DAO("DAOs"):::database
        MIG("Migrations"):::database
        SEED("Seeds"):::database
        DB("PostgreSQL Database"):::db
    end

    subgraph "Integration Layer"
        EC("External Client Integrations"):::external
    end

    subgraph "Utility Layer"
        CL("Core Libraries & Utilities"):::utility
        CF("Configuration"):::utility
        DM("Data Models"):::utility
    end

    subgraph "Deployment & CI/CD"
        DF("Dockerfile"):::deployment
        EB(".ebextensions"):::deployment
    end

    %% Data Flow
    CR --> APIGW
    APIGW --> M
    M --> ACL
    ACL --> CA1
    ACL --> CA2
    CA1 --> HL1
    CA2 --> HL2
    HL1 --> DAO
    HL2 --> DAO
    DAO --> DB
    HL1 --> MIG
    HL2 --> MIG
    MIG --> DB
    HL1 --> SEED
    HL2 --> SEED
    SEED --> DB
    HL1 --> EC
    HL2 --> EC
    HL1 --> RL
    HL2 --> RL
    HL1 --> CL
    HL2 --> CL
    HL1 --> CF
    HL2 --> CF
    HL1 --> DM
    HL2 --> DM

    %% Click Events
    click CA1 "https://github.com/moayyadfaris/susanoo/tree/master/controllers/v1/app"
    click CA2 "https://github.com/moayyadfaris/susanoo/tree/master/controllers/v1/web"
    click HL1 "https://github.com/moayyadfaris/susanoo/tree/master/handlers/v1/app"
    click HL2 "https://github.com/moayyadfaris/susanoo/tree/master/handlers/v1/web"
    click M "https://github.com/moayyadfaris/susanoo/tree/master/middlewares"
    click ACL "https://github.com/moayyadfaris/susanoo/tree/master/acl"
    click DAO "https://github.com/moayyadfaris/susanoo/tree/master/database/dao"
    click MIG "https://github.com/moayyadfaris/susanoo/tree/master/database/migrations"
    click SEED "https://github.com/moayyadfaris/susanoo/tree/master/database/seeds"
    click EC "https://github.com/moayyadfaris/susanoo/tree/master/clients"
    click CL "https://github.com/moayyadfaris/susanoo/tree/master/core"
    click CF "https://github.com/moayyadfaris/susanoo/tree/master/config"
    click DM "https://github.com/moayyadfaris/susanoo/tree/master/models"
    click RL "https://github.com/moayyadfaris/susanoo/blob/master/sockets/QRSocketService.js"
    click DF "https://github.com/moayyadfaris/susanoo/tree/master/Dockerfile"
    click EB "https://github.com/moayyadfaris/susanoo/blob/master/.ebextensions"

    %% Styling
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef middleware fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef business fill:#FFFF99,stroke:#000,stroke-width:1px;
    classDef database fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef db fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef realtime fill:#EE82EE,stroke:#000,stroke-width:1px;
    classDef utility fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef deployment fill:#F4A460,stroke:#000,stroke-width:1px;
```
