# eduardosouzv/my-coffee architecture

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

- Interactive diagram: https://gitdiagram.com/eduardosouzv/my-coffee
- Repository: https://github.com/eduardosouzv/my-coffee

## Overview

##### Main Components

A. Frontend Layer (Port 3000):
- React Application with TypeScript
- Key contexts (Auth, Cart, Products)
- Component structure for UI elements
- Pages (Home, Menu, Checkout)

B. Backend Layer:
- Node.js/TypeScript API
- Controllers layer
- Services layer
- Repositories layer
- Database migrations
- Authentication middleware

C. Database Layer:
- PostgreSQL database
- Main entities: Users, Products, Transactions

##### Component Relationships

Frontend → Backend:
- API calls between frontend contexts and backend controllers
- Authentication flow
- Demonstrate cart and checkout process

Backend → Database:
- Repository patterns
- Database entity relationships
- Transaction flow

##### Detailed Component Breakdown

Frontend Components:
- Contexts
- AuthContext
- CartContext
- ProductsContext
- Pages
- Home
- Menu
- Checkout
- Components
- CartModal
- LoginModal
- Payment

Backend Components:
- Controllers
- Products
- Sessions
- Transactions
- Users
- Services
- Products
- Sessions
- Transactions
- Users
- Repositories
- Transactions
- Users

##### Implementation Details

Use these symbols:
- Rectangles: Components/services
- Diamonds: Decision points
- Clouds: External services

- Component types
- Flow directions
- Authentication boundaries
- Container boundaries

##### Additional Elements

- Environment configuration flow
- Docker container interaction
- Demonstrate TypeScript type sharing between frontend and backend
- Test coverage boundaries

- Authentication flow
- Shopping cart functionality
- Transaction processing
- Product management
- User session handling

Remember to include port numbers, environment configurations, and database migration flows to provide a complete picture of the system's architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Frontend Layer - Port 3000"
        FE["React Application"]
        
        subgraph "Contexts"
            AC["Auth Context"]:::context
            CC["Cart Context"]:::context
            PC["Products Context"]:::context
        end
        
        subgraph "Pages"
            HP["Home Page"]:::page
            MP["Menu Page"]:::page
            CP["Checkout Page"]:::page
        end
        
        subgraph "Components"
            CM["Cart Modal"]:::component
            LM["Login Modal"]:::component
            PM["Payment Component"]:::component
        end
    end

    subgraph "Backend Layer"
        BE["Node.js/TypeScript API"]
        
        subgraph "Controllers"
            PC_C["Products Controller"]:::controller
            SC["Sessions Controller"]:::controller
            TC["Transactions Controller"]:::controller
            UC["Users Controller"]:::controller
        end
        
        subgraph "Services"
            PS["Products Service"]:::service
            SS["Session Service"]:::service
            TS["Transactions Service"]:::service
            US["User Service"]:::service
        end
        
        subgraph "Repositories"
            TR["Transactions Repository"]:::repository
            UR["Users Repository"]:::repository
        end
        
        AM["Auth Middleware"]:::middleware
        AE["App Error"]:::error
    end

    subgraph "Database Layer"
        DB[(PostgreSQL)]
        
        subgraph "Models"
            UM["User Model"]:::model
            TM["Transaction Model"]:::model
            PM_M["Product Model"]:::model
        end
        
        subgraph "Migrations"
            UM_M["Users Migration"]:::migration
            TM_M["Transactions Migration"]:::migration
        end
    end

    %% Relationships
    AC --> SC
    CC --> TC
    PC --> PC_C
    
    PC_C --> PS
    SC --> SS
    TC --> TS
    UC --> US
    
    PS --> DB
    SS --> DB
    TS --> TR
    US --> UR
    
    TR --> DB
    UR --> DB
    
    %% Click Events
    click AC "https://github.com/eduardosouzv/my-coffee/blob/main/frontend/src/contexts/AuthContext.tsx"
    click CC "https://github.com/eduardosouzv/my-coffee/blob/main/frontend/src/contexts/CartContext.tsx"
    click PC "https://github.com/eduardosouzv/my-coffee/blob/main/frontend/src/contexts/ProductsContext.tsx"
    click HP "https://github.com/eduardosouzv/my-coffee/blob/main/frontend/src/pages/Home/index.tsx"
    click MP "https://github.com/eduardosouzv/my-coffee/blob/main/frontend/src/pages/Menu/index.tsx"
    click CP "https://github.com/eduardosouzv/my-coffee/blob/main/frontend/src/pages/Checkout/index.tsx"
    click CM "https://github.com/eduardosouzv/my-coffee/blob/main/frontend/src/components/CartModal/index.tsx"
    click LM "https://github.com/eduardosouzv/my-coffee/blob/main/frontend/src/components/LoginModal/index.tsx"
    click PM "https://github.com/eduardosouzv/my-coffee/blob/main/frontend/src/components/Payment/index.tsx"
    click PC_C "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/controllers/ProductsController.ts"
    click SC "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/controllers/SessionController.ts"
    click TC "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/controllers/TransactionsController.ts"
    click UC "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/controllers/UsersController.ts"
    click PS "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/services/ProductsService.ts"
    click SS "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/services/SessionService.ts"
    click TS "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/services/TransactionsService.ts"
    click US "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/services/UserService.ts"
    click TR "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/repositories/TransactionsRepository.ts"
    click UR "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/repositories/UsersRepository.ts"
    click UM "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/models/User.ts"
    click TM "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/models/Transaction.ts"
    click PM_M "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/models/Product.ts"
    click AM "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/middlewares/ensureAuth.ts"
    click AE "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/errors/AppError.ts"
    click UM_M "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/database/migrations/1622234337900-CreateUsers.ts"
    click TM_M "https://github.com/eduardosouzv/my-coffee/blob/main/backend/src/database/migrations/1623626470691-CreateTransactions.ts"

    %% Styles
    classDef context fill:#a8dadc
    classDef page fill:#457b9d
    classDef component fill:#1d3557
    classDef controller fill:#2a9d8f
    classDef service fill:#e9c46a
    classDef repository fill:#f4a261
    classDef middleware fill:#e76f51
    classDef error fill:#e63946
    classDef model fill:#006d77
    classDef migration fill:#83c5be
```
