# ataekren/prescriptionmanagement architecture

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

- Interactive diagram: https://gitdiagram.com/ataekren/prescriptionmanagement
- Repository: https://github.com/ataekren/prescriptionmanagement

## Overview

##### Project Type & Purpose
- This is a full-stack, microservices-based prescription management system.
- The system supports secure prescription creation, medicine management, and user authentication with clear separation between frontend and backend services.

##### Main Components
a. Frontend Application:
- Built with Next.js (React, TypeScript, Tailwind CSS).
- Represents the user interface and interacts with backend APIs.
b. Backend Microservices (located under src/Services):
- API Gateway: Routes external requests to the appropriate microservices.
- Authentication Service: Manages user authentication, authorization, and user management (using JWT-based security).
- Medicine Service: Handles medicine catalog, inventory, and related operations. It also includes a medicine synchronization job.
- Prescription Service: Manages prescription creation, tracking, and notifications.
c. Shared Library:
- Found under src/Shared/SharedKernel; contains shared DTOs and models to ensure consistency among services.
d. Database & External Resources:
- Although databases aren’t explicitly shown in the file structure, the presence of Entity Framework Core and Migrations in several services implies dedicated databases (or schemas) for Auth, Medicine, and Prescription services.
e. Containerization & Deployment:
- Docker and Docker Compose are used for service orchestration and deployment.
- Configuration files (e.g., docker-compose.yml, Dockerfiles for each microservice).

##### Relationships and Interactions
- The API Gateway acts as the front door into the system, forwarding client requests to the appropriate backend service.
- The Frontend application sends REST/HTTP requests to the API Gateway (or directly to the respective service endpoints, depending on configuration).
- Each microservice communicates with its own database (inferred from the migrations and DbContext files) and may communicate with other microservices when required (e.g., Prescription Service might query the Medicine Service).
- JWT-based authentication is enforced by the Auth Service, interfacing with the API Gateway and possibly used by other services for role-based authorization.
- Shared components (DTOs, models) ensure data consistency when exchanging data between services.

##### Architectural Patterns and Design Principles
- Microservices architecture: Each service is independently deployable, has its own database configuration, and can scale separately.
- API Gateway pattern to centralize request routing.
- Separation of concerns: Distinct modules for authentication, prescriptions, and medicine management.
- Containerization using Docker, helping with deployment and consistent environments.

a. Visual Elements:
b. Detailed Representation:
- Optionally, incorporate the shared library as a common area linked with all services that utilize it.
- Docker containerization and orchestration; show that Docker Compose manages the multiple containers.

##### Detailed Elements
- Component labels: “Frontend (Next.js)”, “API Gateway”, “Authentication Service”, “Medicine Service”, “Prescription Service”, “Shared Library/Kernel”, “Databases” (for each service).
- Use of JWT and role-based authorization on the flow between Frontend and Auth Service.
- Web UI / Client (for user interactions)
- Backend Microservices (for business logic)
- Infrastructure/Containers (for Docker and deployment aspects)

- A client (web browser) interacting with the Frontend.
- The Frontend’s connection to the API Gateway.
- The API Gateway routing traffic to the Authentication, Medicine, and Prescription Services.
- Each service’s integration with its dedicated data storage.
- The underlying shared library for data consistency.
- Deployment aspects showing Docker containerization and orchestration via Docker Compose.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    Client["Client (Browser)"]:::client
    Frontend["Frontend (Next.js)"]:::frontend

    subgraph "Backend Microservices"
        APIGateway["API Gateway"]:::gateway
        subgraph "Services"
            AuthService["Authentication Service"]:::service
            MedicineService["Medicine Service"]:::service
            PrescriptionService["Prescription Service"]:::service
        end
    end

    Shared["Shared Library/Kernel"]:::shared

    AuthDB(("Auth Database")):::database
    MedicineDB(("Medicine Database")):::database
    PrescriptionDB(("Prescription Database")):::database

    subgraph "Container Deployment"
        APIGateway_Docker["API Gateway Dockerfile"]:::dockerfile
        AuthService_Docker["Auth Service Dockerfile"]:::dockerfile
        MedicineService_Docker["Medicine Service Dockerfile"]:::dockerfile
        PrescriptionService_Docker["Prescription Service Dockerfile"]:::dockerfile
        Compose["Deployment Config"]:::deployment
    end

    %% Connections: Client to Frontend to API Gateway and Services
    Client -->|"HTTP/REST"| Frontend
    Frontend -->|"API_Calls"| APIGateway
    APIGateway -->|"Auth_Route"| AuthService
    APIGateway -->|"Medicine_Route"| MedicineService
    APIGateway -->|"Prescription_Route"| PrescriptionService

    %% Service-to-Database connections
    AuthService -->|"DB"| AuthDB
    MedicineService -->|"DB"| MedicineDB
    PrescriptionService -->|"DB"| PrescriptionDB

    %% Shared Library usage connections
    AuthService ---|"UsesDTOs"| Shared
    MedicineService ---|"UsesDTOs"| Shared
    PrescriptionService ---|"UsesDTOs"| Shared

    %% Container Deployment connections: Each service with its Dockerfile and Compose configuration
    APIGateway -->|"Dockerfile"| APIGateway_Docker
    AuthService -->|"Dockerfile"| AuthService_Docker
    MedicineService -->|"Dockerfile"| MedicineService_Docker
    PrescriptionService -->|"Dockerfile"| PrescriptionService_Docker

    APIGateway_Docker -->|"Compose"| Compose
    AuthService_Docker -->|"Compose"| Compose
    MedicineService_Docker -->|"Compose"| Compose
    PrescriptionService_Docker -->|"Compose"| Compose

    %% Styling Classes
    classDef client fill:#ffd1dc,stroke:#333,stroke-width:2px;
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef gateway fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef service fill:#e2e3e5,stroke:#333,stroke-width:2px;
    classDef shared fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef database fill:#d1ecf1,stroke:#333,stroke-width:2px;
    classDef deployment fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef dockerfile fill:#f5c6cb,stroke:#333,stroke-width:2px;

    %% Click Events
    click Frontend "https://github.com/ataekren/prescriptionmanagement/tree/main/frontend/prescriptionsystem"
    click APIGateway "https://github.com/ataekren/prescriptionmanagement/tree/main/src/Services/APIGateway"
    click AuthService "https://github.com/ataekren/prescriptionmanagement/tree/main/src/Services/AuthService"
    click MedicineService "https://github.com/ataekren/prescriptionmanagement/tree/main/src/Services/MedicineService"
    click PrescriptionService "https://github.com/ataekren/prescriptionmanagement/tree/main/src/Services/PrescriptionService"
    click Shared "https://github.com/ataekren/prescriptionmanagement/tree/main/src/Shared/SharedKernel"
    click Compose "https://github.com/ataekren/prescriptionmanagement/blob/main/docker-compose.yml"
    click APIGateway_Docker "https://github.com/ataekren/prescriptionmanagement/tree/main/src/Services/APIGateway/Dockerfile"
    click AuthService_Docker "https://github.com/ataekren/prescriptionmanagement/tree/main/src/Services/AuthService/Dockerfile"
    click MedicineService_Docker "https://github.com/ataekren/prescriptionmanagement/tree/main/src/Services/MedicineService/Dockerfile"
    click PrescriptionService_Docker "https://github.com/ataekren/prescriptionmanagement/tree/main/src/Services/PrescriptionService/Dockerfile"
```
