# tristanrenard/anagodev-web architecture

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

- Interactive diagram: https://gitdiagram.com/tristanrenard/anagodev-web
- Repository: https://github.com/tristanrenard/anagodev-web

## Overview

##### Main System Components

A. Frontend Layer
- Client-Side Components (src/components)
- Pages and Routing (src/pages)
- UI Components (src/components/ui)
- Form Components (src/components/form)

B. API Layer
- Authentication Routes (src/pages/api/user)
- Controllers (src/controllers)

C. Database Layer
- Models (src/db/models)
- Migrations (src/db/migrations)

D. External Services
- Stripe Integration (src/lib/stripe.js)
- Email Service (src/utils/mail)

##### Component Relationships

A. Frontend to API:
- REST API calls from pages to API routes
- Authentication flow (register, login, verify)

B. API to Services:
- Controllers to Database Models
- Authentication flow to Email Service
- Payment processing to Stripe

C. Database Relationships:
- User → Address (one-to-many)
- User → PaymentMethod (one-to-many)
- Order → Products (many-to-many through OrderProducts)
- Product → Category (many-to-one)

##### Specific Implementation Details

A. Authentication Flow:
**Register → Phone Verification → Email Verification → User Creation**
**Login → Token Generation → Protected Routes**

B. Data Flow:
**Client Request → API Route → Controller → Model → Database**

##### Key Technical Aspects to Highlight

- Next.js Pages Router architecture
- RESTful API structure
- Knex.js database migrations
- Authentication middleware
- Form handling and validation
- External service integrations

**┌─────────────────────────────────────────────┐**
- Client Layer                 │
- (Pages, Components, Forms, UI Elements)      │
- ┤
- API Layer                   │
- (API Routes, Controllers, Authentication)    │
- ┤
- Service Layer                  │
- (Email, Stripe, Phone Verification)         │
- ┤
- Database Layer                 │
- (Models, Migrations, Relationships)          │
- ┘

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef controller fill:#f1c40f,stroke:#f39c12,color:white
    classDef database fill:#e74c3c,stroke:#c0392b,color:white
    classDef service fill:#9b59b6,stroke:#8e44ad,color:white
    
    %% Client Layer
    subgraph ClientLayer
        UI["UI Components"]
        Forms["Form Components"]
        AuthPages["Authentication Pages"]
        RegForms["Registration Forms"]
    end
    
    %% API Layer
    subgraph APILayer
        Login["Login API"]
        Register["Register API"]
        Verify["Verify API"]
        PhoneVerify["Phone Verify API"]
    end
    
    %% Controller Layer
    subgraph ControllerLayer
        AuthController["Authentication Controllers"]
        AuthUtils["Authentication Utilities"]
    end
    
    %% Service Layer
    subgraph ServiceLayer
        Stripe["Stripe Integration"]
        Email["Email Service"]
        DB["Database Connection"]
    end
    
    %% Database Layer
    subgraph DatabaseLayer
        Models["Database Models"]
        Migrations["Database Migrations"]
        UserModel["User Model"]
        AddressModel["Address Model"]
        OrderModel["Order Model"]
        ProductModel["Product Model"]
        PaymentModel["Payment Method Model"]
    end
    
    %% Relationships
    UI --> Forms
    Forms --> AuthPages
    AuthPages --> Login & Register & Verify & PhoneVerify
    RegForms --> Register
    
    Login & Register & Verify & PhoneVerify --> AuthController
    AuthController --> AuthUtils
    AuthController --> Models
    
    AuthController --> Email
    AuthController --> Stripe
    Models --> DB
    
    UserModel --> AddressModel
    UserModel --> PaymentModel
    OrderModel --> ProductModel
    
    %% Styles
    class UI,Forms,AuthPages,RegForms frontend
    class Login,Register,Verify,PhoneVerify api
    class AuthController,AuthUtils controller
    class Models,Migrations,UserModel,AddressModel,OrderModel,ProductModel,PaymentModel database
    class Stripe,Email,DB service
    
    %% Click Events
    click UI "https://github.com/tristanrenard/anagodev-web/tree/main/src/components/ui"
    click Forms "https://github.com/tristanrenard/anagodev-web/tree/main/src/components/form"
    click AuthPages "https://github.com/tristanrenard/anagodev-web/tree/main/src/pages/auth"
    click RegForms "https://github.com/tristanrenard/anagodev-web/tree/main/src/components/form/register"
    click Login "https://github.com/tristanrenard/anagodev-web/blob/main/src/pages/api/user/login.js"
    click Register "https://github.com/tristanrenard/anagodev-web/blob/main/src/pages/api/user/register.js"
    click Verify "https://github.com/tristanrenard/anagodev-web/blob/main/src/pages/api/user/verify.js"
    click PhoneVerify "https://github.com/tristanrenard/anagodev-web/blob/main/src/pages/api/user/verifyPhoneNumber.js"
    click AuthController "https://github.com/tristanrenard/anagodev-web/tree/main/src/controllers"
    click AuthUtils "https://github.com/tristanrenard/anagodev-web/tree/main/src/utils/user"
    click Stripe "https://github.com/tristanrenard/anagodev-web/blob/main/src/lib/stripe.js"
    click Email "https://github.com/tristanrenard/anagodev-web/tree/main/src/utils/mail"
    click DB "https://github.com/tristanrenard/anagodev-web/blob/main/src/lib/db.js"
    click Models "https://github.com/tristanrenard/anagodev-web/tree/main/src/db/models"
    click Migrations "https://github.com/tristanrenard/anagodev-web/tree/main/src/db/migrations"
    click UserModel "https://github.com/tristanrenard/anagodev-web/blob/main/src/db/models/User.js"
    click AddressModel "https://github.com/tristanrenard/anagodev-web/blob/main/src/db/models/Address.js"
    click OrderModel "https://github.com/tristanrenard/anagodev-web/blob/main/src/db/models/Order.js"
    click ProductModel "https://github.com/tristanrenard/anagodev-web/blob/main/src/db/models/Product.js"
    click PaymentModel "https://github.com/tristanrenard/anagodev-web/blob/main/src/db/models/PaymentMethod.js"
```
