# hossam7amdy/todo-server architecture

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

- Interactive diagram: https://gitdiagram.com/hossam7amdy/todo-server
- Repository: https://github.com/hossam7amdy/todo-server

## Overview

##### Main System Components

a) API Layer
- Entry point through NestJS controllers (auth, todos, user)
- Authentication middleware/guards
- REST endpoints structure

b) Service Layer
- Business logic implementation
- Core services: AuthService, TodosService, UserService, MailerService

c) Data Layer
- MongoDB integration
- Schemas: User and Todo

d) Authentication System
- JWT implementation
- Google OAuth integration
- Password reset flow

##### Component Relationships

a) Client-Server Communication
- HTTP/REST endpoints
- Authentication flow
- Protected routes

b) Internal Service Communication
- Auth service → User service
- Todos service → User service
- Mailer service interactions

##### Specific Implementation Details

Technical aspects:

a) Authentication Flow
- JWT token flow
- Google OAuth flow
- Password reset process

b) Data Flow
- Todo CRUD operations
- User management
- Email notifications

##### Detailed Component Breakdown

a) NestJS Modules:
- AppModule (root)
- AuthModule
- TodosModule
- UserModule
- MailerModule

b) Controllers & Services:
- Relationship between controllers and their corresponding services
- DTOs and schema models

c) External Integrations:
- MongoDB connection
- Google OAuth
- Email service

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CL[Client Application]
    end

    subgraph "API Layer"
        AC["Auth Controller"]:::controller
        TC["Todos Controller"]:::controller
        UC["User Controller"]:::controller
    end

    subgraph "Service Layer"
        AS["Auth Service"]:::service
        TS["Todos Service"]:::service
        US["User Service"]:::service
        MS["Mailer Service"]:::service
    end

    subgraph "Data Layer"
        DB[(MongoDB)]:::database
        US_SCH["User Schema"]:::schema
        TD_SCH["Todo Schema"]:::schema
    end

    subgraph "Authentication"
        JWT["JWT Strategy"]:::auth
        GAUTH["Google OAuth"]:::auth
        JWTG["JWT Guard"]:::auth
    end

    subgraph "Email System"
        MM["Mailer Module"]:::email
        ET["Email Templates"]:::email
    end

    subgraph "Core Application"
        ME["Main Entry"]:::core
        AM["App Module"]:::core
        CF["Configuration"]:::core
    end

    subgraph "Testing"
        E2E["E2E Tests"]:::test
        UNIT["Unit Tests"]:::test
    end

    subgraph "Container"
        DC["Docker Config"]:::container
        DCY["Docker Compose"]:::container
    end

    %% Relationships
    CL --> AC & TC & UC
    AC --> AS
    TC --> TS
    UC --> US
    AS --> US & MS
    TS --> US
    US --> DB
    AS --> JWT & GAUTH
    MS --> MM
    MM --> ET
    
    %% Database Relationships
    US --> US_SCH
    TS --> TD_SCH
    US_SCH --> DB
    TD_SCH --> DB

    %% Core Application Flow
    ME --> AM
    AM --> CF

    %% Click Events
    click AC "https://github.com/hossam7amdy/todo-server/blob/main/src/auth/auth.controller.ts"
    click TC "https://github.com/hossam7amdy/todo-server/blob/main/src/todos/todos.controller.ts"
    click UC "https://github.com/hossam7amdy/todo-server/blob/main/src/user/user.controller.ts"
    click AS "https://github.com/hossam7amdy/todo-server/blob/main/src/auth/auth.service.ts"
    click TS "https://github.com/hossam7amdy/todo-server/blob/main/src/todos/todos.service.ts"
    click US "https://github.com/hossam7amdy/todo-server/blob/main/src/user/user.service.ts"
    click MS "https://github.com/hossam7amdy/todo-server/blob/main/src/mailer/mailer.service.ts"
    click US_SCH "https://github.com/hossam7amdy/todo-server/blob/main/src/user/schemas/user.schema.ts"
    click TD_SCH "https://github.com/hossam7amdy/todo-server/blob/main/src/todos/schemas/todo.schema.ts"
    click JWT "https://github.com/hossam7amdy/todo-server/blob/main/src/auth/jwt.strategy.ts"
    click GAUTH "https://github.com/hossam7amdy/todo-server/blob/main/src/auth/google.strategy.ts"
    click JWTG "https://github.com/hossam7amdy/todo-server/blob/main/src/auth/jwt-auth.guard.ts"
    click MM "https://github.com/hossam7amdy/todo-server/blob/main/src/mailer/mailer.module.ts"
    click ME "https://github.com/hossam7amdy/todo-server/blob/main/src/main.ts"
    click AM "https://github.com/hossam7amdy/todo-server/blob/main/src/app.module.ts"
    click CF "https://github.com/hossam7amdy/todo-server/blob/main/src/config/configuration.ts"
    click E2E "https://github.com/hossam7amdy/todo-server/blob/main/test/app.e2e-spec.ts"
    click DC "https://github.com/hossam7amdy/todo-server/tree/main/Dockerfile"
    click DCY "https://github.com/hossam7amdy/todo-server/blob/main/docker-compose.yml"

    %% Styling
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef database fill:#607D8B,stroke:#455A64,color:white
    classDef auth fill:#FFC107,stroke:#FFA000,color:black
    classDef email fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef core fill:#3F51B5,stroke:#303F9F,color:white
    classDef test fill:#795548,stroke:#5D4037,color:white
    classDef container fill:#FF5722,stroke:#E64A19,color:white
    classDef schema fill:#009688,stroke:#00796B,color:white
```
