# projected1/deel-challenge architecture

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

- Interactive diagram: https://gitdiagram.com/projected1/deel-challenge
- Repository: https://github.com/projected1/deel-challenge

## Overview

**┌─ API Layer ─────────────────────┐**
- (routes.mjs)                    │
- Middleware Layer ──────────────┤
- (getProfile.mjs)               │
- Controller Layer ─────────────┤
- (Various controllers)          │
- Service Layer ───────────────┤
- (Business Logic)              │
- Repository Layer ────────────┤
- (Data Access)                 │
- Database Layer ─────────────┘

##### Component Details

a) External Interface:
- REST endpoints from the README (/contracts, /jobs, /balances, /admin)
- Authentication header (profile_id)

- Controllers (Rectangle): adminController, balanceController, contractController, jobController
- Services (Hexagon): Corresponding service files for business logic
- Error Handling (Triangle): Custom error classes

Request flow through the system:
**Client Request → API Routes → Middleware → Controller → Service → Repository → Database**

##### Key Technical Elements

- Node.js/Express.js framework
- Sequelize ORM
- SQLite database
- Authentication middleware

##### Additional Elements

Include:
- Database schema relationships (Profile ↔ Contract ↔ Job)
- Authentication flow
- Error handling paths
- Important business rules (e.g., 25% deposit limit, payment conditions)

##### Specific Implementation Details

Specialized components for:
- Balance management
- Contract status handling
- Job payment processing
- Admin statistics calculation

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        C[Client]
    end

    subgraph "API Gateway"
        API["/api"]:::api
        API --> |REST| Routes["Routes"]:::api
        click Routes "https://github.com/projected1/deel-challenge/blob/main/src/routes.mjs"
    end

    subgraph "Middleware Layer"
        Auth["Authentication"]:::middleware
        click Auth "https://github.com/projected1/deel-challenge/blob/main/src/middleware/getProfile.mjs"
    end

    subgraph "Controller Layer"
        AdminC["Admin Controller"]:::controller
        BalanceC["Balance Controller"]:::controller
        ContractC["Contract Controller"]:::controller
        JobC["Job Controller"]:::controller

        click AdminC "https://github.com/projected1/deel-challenge/blob/main/src/controller/adminController.mjs"
        click BalanceC "https://github.com/projected1/deel-challenge/blob/main/src/controller/balanceController.mjs"
        click ContractC "https://github.com/projected1/deel-challenge/blob/main/src/controller/contractController.mjs"
        click JobC "https://github.com/projected1/deel-challenge/blob/main/src/controller/jobController.mjs"
    end

    subgraph "Service Layer"
        AdminS["Admin Service"]:::service
        BalanceS["Balance Service"]:::service
        ContractS["Contract Service"]:::service
        JobS["Job Service"]:::service
        ProfileS["Profile Service"]:::service

        click AdminS "https://github.com/projected1/deel-challenge/blob/main/src/service/adminService.mjs"
        click BalanceS "https://github.com/projected1/deel-challenge/blob/main/src/service/balanceService.mjs"
        click ContractS "https://github.com/projected1/deel-challenge/blob/main/src/service/contractService.mjs"
        click JobS "https://github.com/projected1/deel-challenge/blob/main/src/service/jobService.mjs"
        click ProfileS "https://github.com/projected1/deel-challenge/blob/main/src/service/profileService.mjs"
    end

    subgraph "Repository Layer"
        AdminR["Admin Repository"]:::repository
        BalanceR["Balance Repository"]:::repository
        ContractR["Contract Repository"]:::repository
        JobR["Job Repository"]:::repository
        ProfileR["Profile Repository"]:::repository

        click AdminR "https://github.com/projected1/deel-challenge/blob/main/src/repository/adminRepository.mjs"
        click BalanceR "https://github.com/projected1/deel-challenge/blob/main/src/repository/balanceRepository.mjs"
        click ContractR "https://github.com/projected1/deel-challenge/blob/main/src/repository/contractRepository.mjs"
        click JobR "https://github.com/projected1/deel-challenge/blob/main/src/repository/jobRepository.mjs"
        click ProfileR "https://github.com/projected1/deel-challenge/blob/main/src/repository/profileRepository.mjs"
    end

    subgraph "Database Layer"
        DB[(SQLite)]:::database
        ProfileM[("Profile Model")]:::model
        ContractM[("Contract Model")]:::model
        JobM[("Job Model")]:::model

        click ProfileM "https://github.com/projected1/deel-challenge/blob/main/src/model/profileModel.mjs"
        click ContractM "https://github.com/projected1/deel-challenge/blob/main/src/model/contractModel.mjs"
        click JobM "https://github.com/projected1/deel-challenge/blob/main/src/model/jobModel.mjs"
    end

    subgraph "Error Handling"
        BaseErr["Base Error"]:::error
        InputErr["Invalid Input Error"]:::error
        NotFoundErr["Not Found Error"]:::error
        UnauthorizedErr["Unauthorized Error"]:::error

        click BaseErr "https://github.com/projected1/deel-challenge/blob/main/src/error/deelError.mjs"
        click InputErr "https://github.com/projected1/deel-challenge/blob/main/src/error/invalidInputError.mjs"
        click NotFoundErr "https://github.com/projected1/deel-challenge/blob/main/src/error/notFoundError.mjs"
        click UnauthorizedErr "https://github.com/projected1/deel-challenge/blob/main/src/error/unauthorizedError.mjs"
    end

    subgraph "Configuration"
        DBConfig["Database Config"]:::config
        Constants["Constants"]:::config
        Enums["Enums"]:::config

        click DBConfig "https://github.com/projected1/deel-challenge/blob/main/src/config/dbConfig.mjs"
        click Constants "https://github.com/projected1/deel-challenge/blob/main/src/config/constants.mjs"
        click Enums "https://github.com/projected1/deel-challenge/blob/main/src/config/enums.mjs"
    end

    C --> API
    Routes --> Auth
    Auth --> AdminC & BalanceC & ContractC & JobC
    AdminC --> AdminS
    BalanceC --> BalanceS
    ContractC --> ContractS
    JobC --> JobS
    AdminS & BalanceS & ContractS & JobS --> ProfileS
    AdminS --> AdminR
    BalanceS --> BalanceR
    ContractS --> ContractR
    JobS --> JobR
    ProfileS --> ProfileR
    AdminR & BalanceR & ContractR & JobR & ProfileR --> DB
    DB --> ProfileM & ContractM & JobM

    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef middleware fill:#4CAF50,stroke:#2E7D32,color:white
    classDef controller fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef service fill:#FF9800,stroke:#EF6C00,color:white
    classDef repository fill:#795548,stroke:#4E342E,color:white
    classDef database fill:#607D8B,stroke:#37474F,color:white
    classDef model fill:#00BCD4,stroke:#00838F,color:white
    classDef error fill:#F44336,stroke:#C62828,color:white
    classDef config fill:#9E9E9E,stroke:#424242,color:white
```
