# manhhiep2003/ssphis architecture

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

- Interactive diagram: https://gitdiagram.com/manhhiep2003/ssphis
- Repository: https://github.com/manhhiep2003/ssphis

## Overview

##### Main Components
- API Clients & External Consumers: Represent the browsers, mobile apps, or any external systems that interact with this API, likely through HTTP requests.
- API Gateway / Entry Point: The service is started via src/index.ts. This acts as the primary entry point that initializes the server (likely Express or similar) and assembles the middleware, routes, and configuration.
- Routing Layer: Located in the src/routes folder, which maps API endpoints to specific controllers.
- Controllers: Found inside src/controllers. Each controller (e.g., auth.controller.ts, appointments.controller.ts, etc.) handles incoming requests, calls the appropriate service functions, and returns responses.
- Service Layer: In the src/services directory. These files (e.g., user.service.ts, appointments.service.ts) contain the core business logic and coordinate communication between controllers and the database.
- Middleware: Placed in src/middlewares, these provide request validations (e.g., validateRequest, JWT verification, authorization checks). They act as filters or preprocessors for incoming requests.
- Database & ORM: The project uses Prisma as its ORM. This is evident from the prisma directory with migrations and schema files. The Prisma client (generated using npm run prisma:generate) handles database interactions.
- Configuration & Utilities: Settings in src/configs (database, Swagger API docs, and VNPay configuration) and helpers under src/utils support the overall project functionality.
- API Documentation: Swagger files exist in src/docs, and Swagger is initialized through src/swagger.ts. This provides a visual and interactive representation of the API endpoints.
- Deployment & Environment: Files like Dockerfile, docker-compose.yml, .env.example, and configuration files (e.g., eslint.config.mjs, prettierrc) suggest containerized deployment and development consistency tools.

##### Relationships and Interactions
- API Clients send HTTP requests that first hit the Entry Point (src/index.ts) of the application.
- The requests flow into the Routing Layer (src/routes) where endpoints are mapped to specific controllers.
- Controllers then invoke business logic in the Services layer (src/services).
- The service layer makes calls to the database using the Prisma client, with database schema and migration changes defined under the prisma directory.
- Middlewares are applied at various stages (pre-route or post-route) to enforce authentication, validation, and authorization before reaching the controllers.
- Configuration files in src/configs and external integrations (e.g., VNPay for payments) support enhanced features like payment processing and documenting the API via Swagger.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Different layers (controllers, services, routes, middleware) encapsulate distinct responsibilities.
- MVC / Layered Architecture: Although not strictly an MVC model, the organization clearly separates the request handling (controller), business logic (service), and data access (Prisma / database).
- RESTful API Design: Clearly defined endpoints with corresponding routes and controllers.
- Use of Docker & Environment Variables: The presence of Docker-related files indicates containerized deployment best practices.
- Database Migrations and Schema Evolution: Managed via Prisma migrations which reveal the iterative nature of model updates.

##### Key Technologies, Frameworks, and Libraries to Highlight
- Node.js – the runtime environment.
- Express (or comparable HTTP server framework) – likely used given the conventional “controllers” and “routes” structure.
- Prisma – as the ORM for database management and migrations.
- Swagger – for API documentation.
- VNPay Integration – for payment processing (as seen in the configuration and utility files).
- Docker – for containerization and deployment.
- Various utils and middleware libraries for JWT handling, request validation, and authorization.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Interface Layer
    subgraph "Interface Layer"
        A("API Clients/External Consumers"):::external
    end

    %% Application Layer
    subgraph "Application Layer"
        B("Entry Point (src/index.ts)"):::app
        C("Middleware (src/middlewares)"):::app
        D("Routes (src/routes)"):::app
        E("Controllers (src/controllers)"):::app
        F("Services (src/services)"):::app
    end

    %% Data Layer
    subgraph "Data Layer"
        G1("Prisma Client (src/prisma)"):::data
        G2("Prisma Migrations & Schema (prisma)"):::data
    end

    %% Infrastructure
    subgraph "Infrastructure"
        H("Configuration & External Services (src/configs & src/utils)"):::infra
        H1("VNPay Util (src/utils/vnpay.util.ts)"):::infra
        I("API Documentation (src/docs, src/swagger.ts)"):::infra
        subgraph "Deployment & Environment"
            J1("Dockerfile"):::infra
            J2("docker-compose.yml"):::infra
            J3(".env.example"):::infra
            J4("eslint.config.mjs"):::infra
            J5(".prettierrc"):::infra
        end
    end

    %% Flow Connections
    A --> B
    B --> C
    C --> D
    D --> E
    E --> F
    F --> G1
    G1 --> G2

    %% Infrastructure supporting the system
    H --> B
    H1 --> H
    I --> B
    J1 --> B
    J2 --> B
    J3 --> B
    J4 --> B
    J5 --> B

    %% Click Events
    click B "https://github.com/manhhiep2003/ssphis/blob/main/src/index.ts"
    click C "https://github.com/manhhiep2003/ssphis/tree/main/src/middlewares"
    click D "https://github.com/manhhiep2003/ssphis/tree/main/src/routes"
    click E "https://github.com/manhhiep2003/ssphis/tree/main/src/controllers"
    click F "https://github.com/manhhiep2003/ssphis/tree/main/src/services"
    click G1 "https://github.com/manhhiep2003/ssphis/blob/main/src/prisma/index.ts"
    click G2 "https://github.com/manhhiep2003/ssphis/tree/main/prisma"
    click H "https://github.com/manhhiep2003/ssphis/tree/main/src/configs"
    click H1 "https://github.com/manhhiep2003/ssphis/blob/main/src/utils/vnpay.util.ts"
    click I "https://github.com/manhhiep2003/ssphis/tree/main/src/docs"
    click J1 "https://github.com/manhhiep2003/ssphis/tree/main/Dockerfile"
    click J2 "https://github.com/manhhiep2003/ssphis/blob/main/docker-compose.yml"
    click J3 "https://github.com/manhhiep2003/ssphis/blob/main/.env.example"
    click J4 "https://github.com/manhhiep2003/ssphis/blob/main/eslint.config.mjs"
    click J5 "https://github.com/manhhiep2003/ssphis/blob/main/.prettierrc"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:2px;
    classDef app fill:#bbf,stroke:#333,stroke-width:2px;
    classDef data fill:#bfb,stroke:#333,stroke-width:2px;
    classDef infra fill:#feb,stroke:#333,stroke-width:2px;
```
