# thepkz/genkikoi architecture

> Architecture diagram of the GitHub repository thepkz/genkikoi, 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/thepkz/genkikoi
- Repository: https://github.com/thepkz/genkikoi

## Overview

##### Main Components
- Client Application (User Portal):
– Located in the “client” directory.
– Built with React, TypeScript, and using Ant Design and Tailwind CSS.
– Responsible for presenting the public website, booking system, account management (such as SignIn/SignUp pages), and specialized pages (e.g., About Us, Services, FAQ, Payment outcomes).
– Interacts with the server via RESTful API calls.

- Admin Panel:
– Found in the “admin” directory.
– Also uses React and TypeScript along with a similar tech stack (with custom dashboards, calendars, and role-specific pages for doctors, managers, staff).
– Provides a restricted interface for internal management (appointment scheduling, customer management, treatment records, etc.).
– Communicates with the backend server through its own set of API endpoints.

- Backend Server:
– Housed in the “server” folder.
– Built using Node.js and Express.js.
– Contains a well-organized controller layer (various controllers for appointments, authentication, payments, fish/pond management, etc.), routing modules, middleware (for authentication, role authorization), and services (for email, scheduled tasks, payment updates).
– Manages business logic, authentication using JWT, and integration with external services.
– Interfaces with a MongoDB database (as described in the README) to store data such as appointments, user profiles, records, and transactions.

- Database & External Services:
– MongoDB: The primary data store for services like appointments, prescriptions, records, etc.
– Cloud Storage (Firebase Storage): Configured for storing media or additional asset management.
– Payment Gateway (PayOS): Used to process payments with integration details provided in the environment configuration.
– Email (NodeMailer): For sending notifications and confirmations.

##### Relationships and Interactions
- Both the Client Application and Admin Panel act as frontends that interact with the Backend Server via REST API:
- The Backend Server communicates with the Database (MongoDB) to persist and retrieve application data:
- External services (Payment Gateway, Email Service, Firebase) should be depicted as separate nodes interacting with the Backend Server:
– Similarly, indicate cloud storage or Firebase and email notifications.

##### Architectural Patterns and Principles
- The project follows the separation-of-concerns principle:
– The frontend systems (client and admin) are clearly separated from the backend business logic.
– The backend itself is organized in a layered (controller → service → model) fashion.
- Use of role-based access control:
- API-centric design:
– Emphasize the REST API endpoints that serve both the client and admin applications.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        clientApp["Client Application (React, TypeScript)"]:::frontend
        clientFirebase["Firebase Integration (Client)"]:::integration
        adminApp["Admin Panel (React, TypeScript)"]:::frontend
        adminFirebase["Firebase Integration (Admin)"]:::integration
    end

    %% Application Layer
    subgraph "Application Layer"
        backendServer["Backend Server (Node.js + Express)"]:::backend
        subgraph "Backend Components"
            controllers["Controller Layer"]:::component
            routes["Routing Modules"]:::component
            middleware["Middleware (Auth & Role Control)"]:::component
            models["Data Models (MongoDB Schemas)"]:::component
        end
        backendServer --- controllers
        backendServer --- routes
        backendServer --- middleware
        backendServer --- models
    end

    %% Data & Integration Layer
    subgraph "Data & Integration Layer"
        mongodb["((MongoDB))"]:::external
        firebase["Firebase/Cloud Storage"]:::external
        payos["PayOS Payment Gateway"]:::external
        email["Email Service (NodeMailer)"]:::external
    end

    %% Frontend to Backend Communication
    clientApp -->|"REST_API"| backendServer
    adminApp -->|"REST_API"| backendServer

    %% Frontend Firebase Integration
    clientApp -->|"Uses"| clientFirebase
    adminApp -->|"Uses"| adminFirebase
    clientFirebase -->|"Media_storage"| firebase
    adminFirebase -->|"Media_storage"| firebase

    %% Backend External Service Connections
    backendServer -->|"Payment_processing"| payos
    backendServer -->|"Email_notifications"| email
    backendServer -->|"Data_flow"| mongodb

    %% Click Events
    click clientApp "https://github.com/thepkz/genkikoi/tree/main/client"
    click adminApp "https://github.com/thepkz/genkikoi/tree/main/admin"
    click backendServer "https://github.com/thepkz/genkikoi/tree/main/server"
    click controllers "https://github.com/thepkz/genkikoi/tree/main/server/src/controllers"
    click routes "https://github.com/thepkz/genkikoi/tree/main/server/src/routes"
    click middleware "https://github.com/thepkz/genkikoi/tree/main/server/src/middleware"
    click models "https://github.com/thepkz/genkikoi/tree/main/server/src/models"
    click clientFirebase "https://github.com/thepkz/genkikoi/blob/main/client/src/firebase/firebaseConfig.ts"
    click adminFirebase "https://github.com/thepkz/genkikoi/blob/main/admin/src/firebase/firebaseConfig.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0a74da,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef integration fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef component fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
