# justin-a18/clinic-administrator architecture

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

- Interactive diagram: https://gitdiagram.com/justin-a18/clinic-administrator
- Repository: https://github.com/justin-a18/clinic-administrator

## Overview

##### Main Components
- User Interface (UI) / Presentation Layer:
- Located in the src/app folder, which contains pages (organized under admin and other sections) and shared UI components (e.g., headers, footers, data-tables, modals).
- Sub-components such as _components, _hooks, and context providers are responsible for UI interactions and state management.
- Business Logic / Core Layer:
- Found inside the src/core folder, which holds domain entities (e.g., doctor.entity.ts, patient.entity.ts) and use-cases for each functionality (appointment, doctor, package, patient, service).
- This layer encapsulates the actual business rules and operations (e.g., creating or deleting records).
- Infrastructure & Adapters:
- Located in src/infrastructure and src/config, these directories contain interfaces, mappers, HTTP adapters, and API-related configuration files that allow the UI and business logic to communicate with external systems or services.
- Configuration & Helpers:
- The src/config folder includes environment configurations, adapters, and helper functions, ensuring that external API interactions and global constants are centrally managed.

##### Relationships and Interactions
- Data Flow:
- Users interact with the UI (pages and components) that use custom React hooks (_hooks) to invoke business logic.
- These hooks call the core use-case functions, which interact with domain entities and perform operations such as creating, updating, or deleting records.
- The core layer uses infrastructure adapters (HTTP adapters and mappers) from the config and infrastructure layers to communicate with external APIs or data sources.
- Dependency Flow:
- UI → Hooks/Context Providers (State Management) → Core Use-Cases → Infrastructure (Adapters/HTTP).
- Clean Architecture:

##### Important Architectural Patterns and Design Principles
- Clean Architecture: Separates concerns into distinct layers (Presentation, Core/Business Logic, Infrastructure) ensuring modularity and independence of frameworks.
- Adapter Pattern: Used in the config/adapters directory to abstract and encapsulate the external API calls.
- Use-Case Driven: The business operations are implemented as discrete use-case modules within the src/core/use-cases directory, reflecting user actions (e.g., create-appointment, login-user, etc.).
- Separation of Concerns: Each directory and file type (e.g., _components for UI, _hooks for stateful logic, providers for context and store) is neatly separated for clarity and reuse.

##### Relevant Technologies and Frameworks
- Next.js: The base framework for the SPA and routing (using the src/app organization).
- React: Underlying component structure and hooks.
- Tailwind CSS: Indicated by tailwind.config.ts for styling.
- TypeScript: All files use TypeScript (.ts and .tsx extensions), providing type safety.
- Zustand (implied by the store files): For state management.

##### Detailed Component Relationships
- UI/Presentation Layer:
- src/app – Contains the overall layout (layout.tsx) and specific pages (e.g., admin routes).
- _components – Organizes modular React components by functionality (doctors, patients, shared UI elements).
- _hooks – Custom hooks wrapping common operations (e.g., useCreateDoctorMutation, useUserLoginMutation) that interface with the core layer.
- Core/Business Logic Layer:
- src/core/entities – Domain models that capture the business objects (doctor, patient, etc.).
- src/core/use-cases – Logic for each operation; each module (appointments, doctors, etc.) encapsulates related business processes.
- Infrastructure:
- src/infrastructure/interfaces – Contracts for interacting with external services.
- src/config/adapters – HTTP and API adapters serving as bridges between core logic and external systems.
- src/infrastructure/mappers – Data mappers for transforming external API responses into internal entity formats.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    User["User"]:::external

    %% UI / Presentation Layer
    subgraph "UI / Presentation Layer"
        UI_Layout["Layout (UI)"]:::ui
        Admin_Pages["Admin Pages"]:::ui
        UI_Components["UI Components"]:::ui
        UI_Hooks["Custom Hooks"]:::ui
        UI_Providers["Context Providers"]:::ui
    end

    %% Business Logic / Core Layer
    subgraph "Business Logic / Core Layer"
        Core_UseCases["Use Cases"]:::business
        Core_Entities["Domain Entities"]:::business
    end

    %% Infrastructure & Adapters
    subgraph "Infrastructure & Adapters"
        HTTP_Adapter["HTTP Adapter"]:::infra
        API_Adapter["API Adapter"]:::infra
        Data_Mappers["Data Mappers"]:::infra
    end

    %% Configuration & Helpers
    subgraph "Configuration & Helpers"
        Config_Helpers["Configuration & Helpers"]:::config
    end

    %% External API
    External_API["External API"]:::external

    %% Connections: User to UI Layer
    User -->|"interacts"| UI_Layout
    UI_Layout -->|"renders"| Admin_Pages
    UI_Layout -->|"renders"| UI_Components
    UI_Layout -->|"initializes"| UI_Hooks
    UI_Layout -->|"provides"| UI_Providers
    UI_Providers -->|"supplies"| UI_Hooks
    UI_Components -->|"triggers actions"| UI_Hooks

    %% UI to Core Business Logic
    UI_Hooks -->|"triggers"| Core_UseCases

    %% Internal Core Processing
    Core_UseCases -->|"operates on"| Core_Entities

    %% Core to Infrastructure
    Core_UseCases -->|"calls"| HTTP_Adapter

    %% Infrastructure Adapters Chaining
    HTTP_Adapter -->|"forwards"| API_Adapter
    API_Adapter -->|"maps data"| Data_Mappers
    Data_Mappers -->|"communicates with"| External_API

    %% Configuration usage
    API_Adapter -->|"uses"| Config_Helpers

    %% Click Events for UI / Presentation Layer
    click UI_Layout "https://github.com/justin-a18/clinic-administrator/tree/main/src/app"
    click Admin_Pages "https://github.com/justin-a18/clinic-administrator/tree/main/src/app/(pages)"
    click UI_Components "https://github.com/justin-a18/clinic-administrator/tree/main/src/app/_components"
    click UI_Hooks "https://github.com/justin-a18/clinic-administrator/tree/main/src/app/_hooks"
    click UI_Providers "https://github.com/justin-a18/clinic-administrator/tree/main/src/app/_providers"

    %% Click Events for Business Logic / Core Layer
    click Core_UseCases "https://github.com/justin-a18/clinic-administrator/tree/main/src/core"
    click Core_Entities "https://github.com/justin-a18/clinic-administrator/tree/main/src/core"

    %% Click Events for Infrastructure & Adapters
    click HTTP_Adapter "https://github.com/justin-a18/clinic-administrator/tree/main/src/config/adapters/http"
    click API_Adapter "https://github.com/justin-a18/clinic-administrator/blob/main/src/config/adapters/api.adapter.ts"
    click Data_Mappers "https://github.com/justin-a18/clinic-administrator/tree/main/src/infrastructure/mappers"

    %% Click Event for Configuration & Helpers
    click Config_Helpers "https://github.com/justin-a18/clinic-administrator/tree/main/src/config"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#154360,stroke-width:2px,color:#1B4F72
    classDef business fill:#ABEBC6,stroke:#006400,stroke-width:2px,color:#0B5345
    classDef infra fill:#F9E79F,stroke:#B7950B,stroke-width:2px,color:#7D6608
    classDef config fill:#FADBD8,stroke:#C0392B,stroke-width:2px,color:#922B21
    classDef external fill:#D7BDE2,stroke:#512E5F,stroke-width:2px,color:#4A235A
```
