# emersoncassis/teste-sonoma-sky architecture

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

- Interactive diagram: https://gitdiagram.com/emersoncassis/teste-sonoma-sky
- Repository: https://github.com/emersoncassis/teste-sonoma-sky

## Overview

##### Project Type & Purpose
- Full-stack web application for gym management.
- Frontend: React + TypeScript + Material-UI;
- Backend: Node.js + Express (REST API);
- Database: PostgreSQL;
- Integrations: WhatsApp API, Gympass API, Google Cloud TTS, Instagram Graph API, n8n workflows, Stripe payments.

##### High-Level Components
- Client (Browser)
- React app (login, dashboard, members, scheduling, reports)
- API Server
- Express app (routes → controllers → services → models)
- Auth (JWT) layer in middleware
- Database
- PostgreSQL (tables: Member, Agendamento, Checkin, Pagamento, Relatorio, etc.)
- External Services
- WhatsApp Business API (notifications)
- Gympass Partner API (eligibility validation)
- Google Cloud TTS (radio announcements)
- Instagram Graph API (posts + webhooks)
- n8n (workflow automation via webhook)
- Stripe (payment processing)

##### Interactions & Data Flow
- User → (HTTPS) → React Frontend → (REST) → Express API
- Express API
- Auth middleware (verify JWT)
- Routes dispatch to Controllers
- Controllers call Services
- Services invoke Models (ORM/SQL) → PostgreSQL
- Services call External APIs (via HTTP/SDK)
- Responses flow back: Database → Models → Services → Controllers → Frontend → User
- Background/Automation: n8n webhooks → triggers to Express → services

##### Architectural Patterns & Principles
- Layered (Controller → Service → Model)
- Modular services grouped by domain (members, agendamentos, checkins, pagamentos, relatorios, integrations)
- Single Node.js monolith, containerizable via Docker (docker-compose)
- Stateless API, JWT-based auth
- Database migrations (schema.sql + seed.sql)
- Automated testing (Jest)

- Routes layer → Controllers → Services → Models → DB
- Middleware chain (Auth)
- Integration calls branching from specific Services

- Clearly outlines all major components and their interactions
- Captures architectural patterns (layering, modularization)
- Identifies all external dependencies and integration points
- Aligns precisely with the project’s file structure and README specifications

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and Frontend
    User(("User"))
    React["React 18 + MUI"]:::frontend

    User -->|uses| React
    React -->|HTTPS POST/GET| Server

    %% Backend Server
    Server["Express.js (Node 18)"]:::backend
    DBConfig["DB Config"]:::backend
    Server --> DBConfig

    Server --> AuthMW
    AuthMW["Auth Middleware\n(JWT)"]:::backend
    AuthMW --> AuthRoutes
    AuthRoutes["Auth Routes"]:::backend
    AuthRoutes --> AuthController
    AuthController["Auth Controller"]:::backend

    %% Domain Modules
    Server --> MembersRoutes
    MembersRoutes["Members Routes"]:::backend
    MembersRoutes --> MembersController
    MembersController["Members Controller"]:::backend
    MembersController --> MemberModel
    MemberModel["Member Model"]:::backend

    Server --> AgendRoutes
    AgendRoutes["Agendamentos Routes"]:::backend
    AgendRoutes --> AgendController
    AgendController["Agendamentos Controller"]:::backend
    AgendController --> AgendModel
    AgendModel["Agendamento Model"]:::backend

    Server --> CheckinRoutes
    CheckinRoutes["Check-ins Routes"]:::backend
    CheckinRoutes --> CheckinController
    CheckinController["Check-ins Controller"]:::backend
    CheckinController --> CheckinModel
    CheckinModel["Checkin Model"]:::backend

    Server --> PagRoutes
    PagRoutes["Pagamentos Routes"]:::backend
    PagRoutes --> PagController
    PagController["Pagamentos Controller"]:::backend
    PagController --> PagModel
    PagModel["Pagamento Model"]:::backend

    Server --> RelRoutes
    RelRoutes["Relatorios Routes"]:::backend
    RelRoutes --> RelController
    RelController["Relatorios Controller"]:::backend
    RelController --> RelModel
    RelModel["Relatorio Model"]:::backend

    %% Integration Modules
    Server --> WhatsAppRoutes
    WhatsAppRoutes["WhatsApp Routes"]:::backend
    WhatsAppRoutes --> WhatsAppController
    WhatsAppController["WhatsApp Controller"]:::backend
    WhatsAppController --> WhatsAppService
    WhatsAppService["WhatsApp Service"]:::backend

    Server --> GympassRoutes
    GympassRoutes["Gympass Routes"]:::backend
    GympassRoutes --> GympassController
    GympassController["Gympass Controller"]:::backend
    GympassController --> GympassService
    GympassService["Gympass Service"]:::backend

    Server --> RadioRoutes
    RadioRoutes["Radio Routes"]:::backend
    RadioRoutes --> RadioService
    RadioService["Radio Service"]:::backend

    Server --> InstagramRoutes
    InstagramRoutes["Instagram Routes"]:::backend
    InstagramRoutes --> InstagramService
    InstagramService["Instagram Service"]:::backend

    Server --> N8nRoutes
    N8nRoutes["n8n Routes"]:::backend
    N8nRoutes --> N8nService
    N8nService["n8n Service"]:::backend

    PagController --> StripeService
    StripeService["Stripe Service"]:::backend

    %% Database
    MemberModel -->|reads/writes| DB
    AgendModel -->|reads/writes| DB
    CheckinModel -->|reads/writes| DB
    PagModel -->|reads/writes| DB
    RelModel -->|reads/writes| DB
    DB["PostgreSQL 15"]:::db

    %% External Services
    WhatsAppService --> WhatsAppAPI
    GympassService --> GympassAPI
    RadioService --> GoogleTTS
    InstagramService --> InstagramAPI
    N8nService --> N8nWorkflow
    StripeService --> StripeAPI

    %% Nodes for External
    WhatsAppAPI["WhatsApp Business API"]:::external
    GympassAPI["Gympass Partner API"]:::external
    GoogleTTS["Google Cloud TTS"]:::external
    InstagramAPI["Instagram Graph API"]:::external
    N8nWorkflow["n8n Workflows"]:::external
    StripeAPI["Stripe API"]:::external

    %% Click Events
    click Server "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/server.js"
    click DBConfig "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/config/db.js"
    click AuthMW "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/middleware/auth.js"
    click AuthRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/authRoutes.js"
    click AuthController "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/controllers/authController.js"
    click MembersRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/membersRoutes.js"
    click MembersController "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/controllers/membersController.js"
    click MemberModel "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/models/Member.js"
    click AgendRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/agendamentosRoutes.js"
    click AgendController "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/controllers/agendamentosController.js"
    click AgendModel "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/models/Agendamento.js"
    click CheckinRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/checkinsRoutes.js"
    click CheckinController "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/controllers/checkinsController.js"
    click CheckinModel "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/models/Checkin.js"
    click PagRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/pagamentosRoutes.js"
    click PagController "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/controllers/pagamentosController.js"
    click PagModel "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/models/Pagamento.js"
    click RelRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/relatoriosRoutes.js"
    click RelController "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/controllers/relatoriosController.js"
    click RelModel "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/models/Relatorio.js"
    click WhatsAppRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/whatsappRoutes.js"
    click WhatsAppController "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/controllers/whatsappController.js"
    click WhatsAppService "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/services/whatsappService.js"
    click GympassRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/gympassRoutes.js"
    click GympassController "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/controllers/gympassController.js"
    click GympassService "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/services/gympassService.js"
    click RadioRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/radioRoutes.js"
    click RadioService "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/services/radioService.js"
    click InstagramRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/instagramRoutes.js"
    click InstagramService "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/services/instagramService.js"
    click N8nRoutes "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/routes/n8nRoutes.js"
    click N8nService "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/services/n8nService.js"
    click DB "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/migrations/schema.sql"
    click DB "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/migrations/seed.sql"
    click StripeService "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/docs/api.md"
    click StripeService "https://github.com/emersoncassis/teste-sonoma-sky/blob/main/backend/tests/basic.test.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef backend fill:#D6F5D6,stroke:#333,stroke-width:1px
    classDef db fill:#E8D0FF,stroke:#333,stroke-width:1px
    classDef external fill:#FFE0B2,stroke:#333,stroke-width:1px
```
