# arevy/e-commerce-backend architecture

> Architecture diagram of the GitHub repository arevy/e-commerce-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arevy/e-commerce-backend
- Repository: https://github.com/arevy/e-commerce-backend

## Overview

Step 1: Identify the Project Type and Purpose
- This is an e-commerce backend implemented in TypeScript, running on Node.js with Express.js.
- It exposes a GraphQL API for managing categories and products and persists data in an Oracle relational database.
- It follows a layered, modular architecture (configuration, API layer, business logic, data access, utilities).

Step 2: Analyze the File Structure
- Top-level:
- src/ – TypeScript source
– config/ – database connection setup (Oracle), type definitions
– graphql/
· schema.ts – GraphQL schema definitions
· types/ – GraphQL object types (e.g., ProductType)
· resolvers/ – resolver functions for queries & mutations (category, product, user)
– models/ – ORM‐like entity definitions (Category, Product)
– services/ – business logic layer (e.g., productService)
– utils/ – cross-cutting utilities (logger, input validation)
– server.ts – Express app configuration, GraphQL endpoint mount
– index.ts – app entry point (starts server)
- dist/ – compiled JavaScript (mirrors src/)
- sql_script.txt – DDL/DML for creating and seeding tables
- configuration files (tsconfig.json, .eslintrc.json, .prettierrc)

Step 3: Examine the README for Additional Insights
- Technology stack: Node.js, Express.js, GraphQL middleware (express-graphql), Oracle DB, JWT for auth.
- Database schema: CATEGORIES and PRODUCTS tables with foreign key.
- Environment variables (.env) for DB credentials and JWT secret.
- Example GraphQL queries and mutations.

##### GraphQL Layer
- Schema
- Resolvers
##### Utilities (logger, input validation) – cross-cutting

Step 5: Relationships and Interactions
- Client → HTTP POST /graphql → Express server
- Express → GraphQL middleware → parses query against Schema
- Schema → invokes Resolvers
- Resolvers → call Service methods
- Services → interact with Models (data access wrappers)
- Models → execute SQL over Oracle DB connection
- DB → returns data → propagates up through layers back to client
- JWT authentication can happen either in Express middleware (pre-GraphQL) or inside resolvers

Step 6: Highlight Architectural Patterns
- Layered architecture (Presentation → API → Business → Data)
- Separation of concerns:
· config/ for infrastructure
· graphql/ for API contract
· services/ for core logic
· models/ for persistence
· utils/ for shared helpers
- Type safety with TypeScript and strong typing in GraphQL types

Step 7: Diagramming Guidelines
- Client (UI or external consumer)
- API Layer (Express + GraphQL)
- Service Layer
- Data Access Layer
- Oracle Database
- Blue for API components (Express, GraphQL schema)
- Green for business logic (services)
- Orange for persistence (models, DB)
- Gray for utilities/config

- GraphQL API boundary and the flow from HTTP into schema/resolvers.
- Oracle connection defined in src/config/database.ts.
- Where JWT tokens are verified (Express middleware or inside resolvers).
- Initial SQL script (sql_script.txt) as part of the “Database Setup” sub-component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Client["Client (GraphQL Client)"]:::client

    %% API Layer
    subgraph "API Layer"
        direction TB
        Index["App Entry (src/index.ts)"]:::api
        Server["Express Server (src/server.ts)"]:::api
        GraphQL["GraphQL Middleware"]:::api
        Schema["GraphQL Schema (src/graphql/schema.ts)"]:::api
        subgraph "Resolvers"
            direction TB
            CategoryResolver["Category Resolver"]:::api
            ProductResolver["Product Resolver"]:::api
            UserResolver["User Resolver"]:::api
        end
        subgraph "Types"
            ProductType["Product Type (src/graphql/types/productType.ts)"]:::api
        end
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        ProductService["ProductService (src/services/productService.ts)"]:::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        CategoryModel["Category Model (src/models/category.ts)"]:::data
        ProductModel["Product Model (src/models/product.ts)"]:::data
    end

    %% Configuration and Utilities
    subgraph "Config & Utilities"
        direction TB
        DBConfig["DB Config (src/config/database.ts)"]:::config
        OracleDTs["OracleDB Types (src/config/oracledb.d.ts)"]:::config
        Logger["Logger (src/utils/logger.ts)"]:::util
        ValidateInput["Input Validation (src/utils/validateInput.ts)"]:::util
        SQLScript["DB Setup Script (sql_script.txt)"]:::config
    end

    %% Database
    OracleDB["Oracle Database"]:::db

    %% Connections
    Client -->|"POST /graphql"| Index
    Index -->|starts| Server
    Server -->|use graphqlHTTP| GraphQL
    GraphQL -->|"uses schema"| Schema
    GraphQL -->|"validates JWT"| ValidateInput
    Schema -->|"invokes"| CategoryResolver
    Schema -->|"invokes"| ProductResolver
    Schema -->|"invokes"| UserResolver
    CategoryResolver -->|"calls service"| ProductService
    ProductResolver -->|"calls service"| ProductService
    UserResolver -->|"calls service"| ProductService
    CategoryResolver -->|"logs"| Logger
    ProductResolver -->|"logs"| Logger
    UserResolver -->|"logs"| Logger
    ProductService -->|"queries"| CategoryModel
    ProductService -->|"queries"| ProductModel
    CategoryModel -->|"uses connection"| DBConfig
    ProductModel -->|"uses connection"| DBConfig
    CategoryModel -->|"executes SQL"| OracleDB
    ProductModel -->|"executes SQL"| OracleDB
    SQLScript -->|"initializes"| OracleDB

    %% Click Events
    click Server "https://github.com/arevy/e-commerce-backend/blob/master/src/server.ts"
    click Index "https://github.com/arevy/e-commerce-backend/blob/master/src/index.ts"
    click Schema "https://github.com/arevy/e-commerce-backend/blob/master/src/graphql/schema.ts"
    click CategoryResolver "https://github.com/arevy/e-commerce-backend/blob/master/src/graphql/resolvers/categoryResolver.ts"
    click ProductResolver "https://github.com/arevy/e-commerce-backend/blob/master/src/graphql/resolvers/productResolver.ts"
    click UserResolver "https://github.com/arevy/e-commerce-backend/blob/master/src/graphql/resolvers/userResolver.ts"
    click ProductType "https://github.com/arevy/e-commerce-backend/blob/master/src/graphql/types/productType.ts"
    click ProductService "https://github.com/arevy/e-commerce-backend/blob/master/src/services/productService.ts"
    click CategoryModel "https://github.com/arevy/e-commerce-backend/blob/master/src/models/category.ts"
    click ProductModel "https://github.com/arevy/e-commerce-backend/blob/master/src/models/product.ts"
    click DBConfig "https://github.com/arevy/e-commerce-backend/blob/master/src/config/database.ts"
    click OracleDTs "https://github.com/arevy/e-commerce-backend/blob/master/src/config/oracledb.d.ts"
    click Logger "https://github.com/arevy/e-commerce-backend/blob/master/src/utils/logger.ts"
    click ValidateInput "https://github.com/arevy/e-commerce-backend/blob/master/src/utils/validateInput.ts"
    click SQLScript "https://github.com/arevy/e-commerce-backend/blob/master/sql_script.txt"

    %% Styles
    classDef client fill:#E8F1FB,stroke:#0366D6,color:#0366D6
    classDef api fill:#DCEEFB,stroke:#0366D6,color:#0366D6
    classDef service fill:#DEFBE6,stroke:#34A853,color:#34A853
    classDef data fill:#FFF4E5,stroke:#FBBC04,color:#FBBC04
    classDef db fill:#FCE8E6,stroke:#EA4335,color:#EA4335
    classDef config fill:#F1F3F4,stroke:#5F6368,color:#5F6368
    classDef util fill:#F8F9FA,stroke:#5F6368,color:#5F6368
```
