From 89036d7b39ea07567ff0475616b30a8608a97df3 Mon Sep 17 00:00:00 2001 From: Tiago Yamamoto Date: Sat, 27 Dec 2025 01:13:11 -0300 Subject: [PATCH] docs: add detailed mermaid diagrams for db, backend and marketplace --- backend/README.md | 91 +++++++++++++++++++++++++++++++++++++++++ docs/DATABASE_SCHEMA.md | 66 ++++++++++++++++++++++++++++++ marketplace/README.md | 91 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+) create mode 100644 backend/README.md create mode 100644 docs/DATABASE_SCHEMA.md create mode 100644 marketplace/README.md diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 0000000..764fc9c --- /dev/null +++ b/backend/README.md @@ -0,0 +1,91 @@ +# SaveInMed Backend API + +This service handles the core business logic, data persistence, and external integrations for the SaveInMed B2B Marketplace. + +## 🏗 Architecture + +The backend follows a layered architecture to ensure separation of concerns and maintainability. + +```mermaid +graph TD + %% Clients + Client([Client Application]) + + %% Entry Point + subgraph "API Layer" + Router[Router / Middleware] + AuthH[Auth Handler] + UserH[User Handler] + ProdH[Product Handler] + CartH[Cart Handler] + OrderH[Order Handler] + PayH[Payment Handler] + ShipH[Shipping Handler] + end + + %% Business Logic + subgraph "Service Layer" + AuthS[Auth Service] + UserS[User Service] + ProdS[Catalog Service] + OrderS[Order Service] + PayS[Payment Service] + ShipS[Shipping Service] + end + + %% Data / Infra + subgraph "Infrastructure Layer" + DB[(PostgreSQL)] + MP[Mercado Pago Adapter] + Asaas[Asaas Adapter] + Stripe[Stripe Adapter] + Mapbox[Mapbox Service] + end + + %% Flows + Client --> Router + Router --> AuthH + Router --> UserH + Router --> ProdH + Router --> CartH + Router --> OrderH + Router --> PayH + Router --> ShipH + + AuthH --> AuthS + UserH --> UserS + ProdH --> ProdS + CartH --> OrderS + OrderH --> OrderS + PayH --> PayS + ShipH --> ShipS + + AuthS --> DB + UserS --> DB + ProdS --> DB + OrderS --> DB + + PayS --> MP + PayS --> Asaas + PayS --> Stripe + + ShipS --> Mapbox + + %% Styling + style Client fill:#f9f,stroke:#333 + style Router fill:#ff9,stroke:#333 + style DB fill:#94a3b8,stroke:#333 +``` + +## 🛠 Tech Stack +- **Language**: Go 1.24+ +- **Framework**: Standard Library + Chi/Mux (inferred) +- **Database**: PostgreSQL +- **Docs**: Swagger/OpenAPI + +## 🚀 Key Features +- High-performance REST API +- JWT Authentication +- Role-Based Access Control +- Payment Gateway Integration (Mercado Pago, Asaas, Stripe) +- Real-time Inventory Management diff --git a/docs/DATABASE_SCHEMA.md b/docs/DATABASE_SCHEMA.md new file mode 100644 index 0000000..204c855 --- /dev/null +++ b/docs/DATABASE_SCHEMA.md @@ -0,0 +1,66 @@ +# Database Schema + +This document visualizes the SaveInMed database schema using Mermaid. + +```mermaid +erDiagram + %% Entities + COMPANY { + int id pk + string name + enum status "ACTIVE | INACTIVE | SUSPENDED" + datetime createdAt + datetime updatedAt + } + + USER { + int id pk + string email uk + string password + string name + enum role "USER | ADMIN" + int companyId fk + string refreshToken + datetime createdAt + datetime updatedAt + } + + PRODUCT { + int id pk + string name + string sku uk + decimal price "10,2" + datetime createdAt + datetime updatedAt + } + + INVENTORY_ITEM { + int id pk + int productId fk, uk + int quantity + datetime updatedAt + } + + ORDER { + int id pk + int buyerId fk + int productId fk + int quantity + decimal total "12,2" + datetime createdAt + } + + SYSTEM_SETTINGS { + string key pk + string value + string category "default: GENERAL" + boolean isSecure "default: false" + datetime updatedAt + } + + %% Relationships + COMPANY ||--|{ USER : "has" + USER ||--|{ ORDER : "places" + PRODUCT ||--|| INVENTORY_ITEM : "has stock" + PRODUCT ||--|{ ORDER : "included in" +``` diff --git a/marketplace/README.md b/marketplace/README.md new file mode 100644 index 0000000..a84e161 --- /dev/null +++ b/marketplace/README.md @@ -0,0 +1,91 @@ +# SaveInMed Marketplace Frontend + +The Marketplace is the customer-facing B2B application where pharmacies purchase products from distributors. + +## 🏗 Architecture + +The frontend is built with React and Vite, utilizing a component-based architecture state management. + +```mermaid +graph TD + %% User + User((User)) + + %% Core + subgraph "Application Core" + App[App Root] + Router[React Router] + Store[Zustand Store] + Query[TanStack Query] + end + + %% Pages + subgraph "Pages / Routes" + LoginP[Login/Auth] + HomeP[Home / Catalog] + ProdP[Product Details] + CartP[Shopping Cart] + CheckoutP[Checkout] + ProfileP[User Profile] + OrdersP[Order History] + end + + %% Feature Components + subgraph "Smart Components" + AuthForm[Auth Forms] + ProdGrid[Product Grid] + CartWidget[Cart Widget] + PayWidget[Payment Widget] + AddressForm[Address Manager] + end + + %% API Layer + subgraph "API Integration" + API[API Client (Axios)] + Backend[Backend API] + end + + %% Flow + User --> App + App --> Router + App --> Store + + Router --> LoginP + Router --> HomeP + Router --> ProdP + Router --> CartP + Router --> CheckoutP + Router --> ProfileP + Router --> OrdersP + + HomeP --> ProdGrid + CartP --> CartWidget + CheckoutP --> PayWidget + CheckoutP --> AddressForm + + ProdGrid --> Store + CartWidget --> Store + PayWidget --> Store + + Store --> API + Query --> API + API --> Backend + + %% Styling + style User fill:#f9f,stroke:#333,stroke-width:2px + style Backend fill:#f87171,stroke:#333,stroke-width:2px + style Store fill:#60a5fa,stroke:#333 +``` + +## 🛠 Tech Stack +- **Framework**: React 18 + Vite +- **Styling**: TailwindCSS +- **State**: Zustand + TanStack Query +- **Routing**: React Router DOM +- **HTTP**: Axios + +## 📦 Key Modules +- **Authentication**: JWT-based login and session management +- **Catalog**: Virtualized product lists with search and filter +- **Checkout**: Multi-step checkout with payment integration +- **Dashboard**: User order history and status tracking