# pregna-care-system/pregna-care-client architecture

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

- Interactive diagram: https://gitdiagram.com/pregna-care-system/pregna-care-client
- Repository: https://github.com/pregna-care-system/pregna-care-client

## Overview

Based on our analysis, this project is a React application built using TypeScript and Vite. Although the README mentions a minimal template with some ESLint configuration guidelines, the file tree reveals a more extensive full-fledged frontend solution. It is structured to support multiple user roles (e.g., Admin and Member), has distinct pages (for blog, community, checkout, etc.), and includes a solid architecture with clear segregation of concerns such as presentation (components and layouts), routing, state management (Redux with sagas), and service layers (API interactions).

##### Main Components
- Entry Point & Bootstrapping:
- Entry file: src/main.tsx.
- App container: src/App.tsx.
- Presentation Layer:
- Components: Located under src/components (cards, carousel, modal, chat, etc.).
- Layouts: Found under src/layouts (AdminLayout, MainLayout, MemberLayout, NoHeaderLayout).
- Pages: In src/pages (distinct directories for Admin, Blog, Community, Member, etc.) – these represent screens/views.
- Routing & Guards:
- Routing configuration: src/routes/index.tsx.
- Auth and Role Guards: Under src/guards (AdminGuard, AuthGuard, GuestGuard, MemberGuard) ensuring security and access control.
- State Management:
- Redux-related code: src/store (modules, rootReducer.ts, rootSaga.ts, store.ts).
- This layer handles global state, asynchronous actions (sagas), and selectors.
- Business/Service Layer:
- Service files: Inside src/services (adminService, blogService, userService, etc.) that abstract API interaction.
- Utilities & Constants:
- Utility functions and configuration: Under src/utils (axiosClient, helper, configuration of routes, constants, etc.).
- Theming and Styling:
- Theme files: Located in src/theme.
- Global CSS: Including index.css in src and Tailwind configurations.
- Configuration & Build:
- Vite configuration (vite.config.ts) and TypeScript configurations (tsconfig files).
- Dockerfile and .dockerignore indicate containerization support.
- GitHub CI workflows in .github/workflows for building and checks.

##### Relationships/Interactions
- The entry point (src/main.tsx) initializes the application by rendering the App component.
- App.tsx acts as the high-level container setting up routes via src/routes.
- Each page under src/pages is rendered based on the active route – and pages combine numerous reusable components.
- Layouts wrap pages and enforce structural consistency (for example, AdminLayout for all admin pages).
- Guards (AuthGuard, AdminGuard, etc.) sit in front of route components to control access.
- State flows using Redux: actions and sagas (in src/store) update the global state while pages and components subscribe to the state via selectors.
- The Services layer abstracts and handles external API calls, which are then used by Redux sagas or directly in components.
- Utility modules (e.g., axiosClient) support external API interactions, while constants and helper functions facilitate application-wide behaviors.
- The external build and configuration files (Dockerfile, Vite config, ESLint and Prettier settings) support development, testing, and deployment pipelines.

##### Architectural Patterns/Design Principles
- Component-Based Architecture: Separation into reusable UI components (cards, modals, charts, etc.).
- Container-Presenter Paradigm: Pages and layouts serve as containers that orchestrate state and routing, while components focus on rendering.
- Redux for State Management: The store, reducers, sagas, and selectors provide a clear data flow and predictable state container.
- Separation of Concerns: Distinct folders for services, hooks, helpers, and types keep logic modular.
- Role-based Access/Guarding: The use of guard components enforces user authentication and role-specific access.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Bootstrapping: Entry Point & App Container"
        A["src/main.tsx"]:::entry
        B["src/App.tsx"]:::entry
        A -->|"renders"| B
    end

    subgraph "Routing & Guards"
        C["src/routes/index.tsx"]:::routing
        D["src/guards (AuthGuard, AdminGuard, GuestGuard, MemberGuard)"]:::routing
        B -->|"sets up routes"| C
        C -->|"enforces access via"| D
    end

    subgraph "Presentation Layer"
        E["src/pages (Admin, Blog, Community, Member, etc.)"]:::ui
        F["src/layouts (AdminLayout, MainLayout, MemberLayout, NoHeaderLayout)"]:::ui
        G["src/components (Cards, Carousel, Chat, Modal, etc.)"]:::ui
        C -->|"renders pages"| E
        E -->|"wrapped with"| F
        F -->|"composed of"| G
    end

    subgraph "State Management (Redux & Sagas)"
        H["src/store (Redux modules, rootReducer.ts, rootSaga.ts, store.ts)"]:::state
        E -->|"uses state from"| H
    end

    subgraph "Services/Business Logic"
        I["src/services (adminService, blogService, etc.)"]:::services
        H -->|"triggers API calls via sagas to"| I
    end

    subgraph "Utilities & Theming"
        J["src/utils (axiosClient, helpers, route configuration, constants)"]:::utils
        K["src/theme (color.ts, index.ts) & Global CSS (src/index.css, Tailwind config)"]:::styles
        G -->|"utilizes"| J
        F -->|"styled with"| K
    end

    subgraph "Build & Configuration"
        L["vite.config.ts, tsconfig files"]:::config
        M["Dockerfile, .dockerignore, .github/workflows"]:::config
        J -->|"configuration supports"| L
        L -->|"integrates with"| M
    end

    %% Click Events
    click A "https://github.com/pregna-care-system/pregna-care-client/blob/main/src/main.tsx"
    click B "https://github.com/pregna-care-system/pregna-care-client/blob/main/src/App.tsx"
    click C "https://github.com/pregna-care-system/pregna-care-client/blob/main/src/routes/index.tsx"
    click D "https://github.com/pregna-care-system/pregna-care-client/tree/main/src/guards"
    click E "https://github.com/pregna-care-system/pregna-care-client/tree/main/src/pages"
    click F "https://github.com/pregna-care-system/pregna-care-client/tree/main/src/layouts"
    click G "https://github.com/pregna-care-system/pregna-care-client/tree/main/src/components"
    click H "https://github.com/pregna-care-system/pregna-care-client/tree/main/src/store"
    click I "https://github.com/pregna-care-system/pregna-care-client/tree/main/src/services"
    click J "https://github.com/pregna-care-system/pregna-care-client/tree/main/src/utils"
    click K "https://github.com/pregna-care-system/pregna-care-client/tree/main/src/theme"
    click L "https://github.com/pregna-care-system/pregna-care-client/blob/main/vite.config.ts"
    click M "https://github.com/pregna-care-system/pregna-care-client/tree/main/Dockerfile"

    %% Styles
    classDef entry fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef routing fill:#aed6f1,stroke:#1b4f72,stroke-width:2px;
    classDef ui fill:#d5f5e3,stroke:#145a32,stroke-width:2px;
    classDef state fill:#fadbd8,stroke:#922b21,stroke-width:2px;
    classDef services fill:#fcf3cf,stroke:#7d6608,stroke-width:2px;
    classDef utils fill:#d6eaf8,stroke:#1b4f72,stroke-width:2px;
    classDef styles fill:#ebdef0,stroke:#6c3483,stroke-width:2px;
    classDef config fill:#f5b7b1,stroke:#922b21,stroke-width:2px;
```
