# alejandro-albiol/todopro architecture

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

- Interactive diagram: https://gitdiagram.com/alejandro-albiol/todopro
- Repository: https://github.com/alejandro-albiol/todopro

## Overview

##### Project Overview & Context
- toDoPro is a full-stack task manager that enables users to manage and prioritize tasks, enhanced with AI-powered recommendations via the GROQ API.
- It’s structured as a monorepo containing distinct backend, frontend, and public (static assets) directories.
- The backend is built with Node.js, Express, and TypeScript; the frontend uses TypeScript, HTML5, and CSS3; PostgreSQL is used as the database.
- The project is organized with a strong emphasis on SOLID principles and modular design (e.g., separate modules for auth, tasks, users, and AI).

##### Key Components
a. Frontend Components:
- A frontend directory containing business logic handlers written in TypeScript.
- Static HTML pages and CSS in the public folder that provide the UI.
- These represent the user interface and view layer.

b. Backend Components:
- API Server: The backend (express server) starting with entry point files (src/app.ts, index.ts) handling application routing.
- Modular Controllers and Routes:
- Auth Module: Handles user registrations, login, token management.
- Tasks Module: Manages task creation, updates, and deletion.
- Users Module: User management functions.
- AI Module: Provides AI recommendations using the GROQ API.
- Middlewares and Validators: Centralized middleware for authentication, error handling, data validation, and logging.
- Shared Services and Utilities: Common exception handling, hashing (e.g., argon2 in the hash.service), and error utilities.
- Configuration: App and database configuration files that set up environment variables etc.
- Documentation: Swagger setup from the docs folder for API documentation.

c. Database:
- PostgreSQL database that stores users and tasks tables.
- The backend uses configuration files (in config) for database connectivity and queries within the respective modules.

d. External Services:
- GROQ API: An external AI integration that provides intelligent recommendations for tasks.

##### Relationships & Data Flow
- The Frontend sends HTTP/HTTPS requests (e.g., login, task operations) to the Backend API.
- The backend routes (via the express server) process these requests using the respective controllers.
- Controllers then interact with service layers (e.g., ai-recommendation.service, user.service, task.service) and repository layers to perform business logic and data persistence.
- Database interactions occur via repositories which execute CRUD operations against PostgreSQL, and shared exceptions help handle any errors during this process.
- For AI-powered task prioritization, the backend’s AI module calls the GROQ API and integrates the recommendations into the overall task management response.

##### Architectural Patterns & Principles
- Modular Design: Each domain (auth, tasks, users, AI) is separated into its own directory with a clear contract defined by interfaces (see files like i-auth.controller.ts, i-task.service.ts, etc.).
- SOLID Principles: The project adheres to good separation of concerns, including well-defined controllers, services, repositories, and utilities.
- MVC-Like Pattern: Although not a pure MVC, there is a clear separation between the controllers (handling HTTP requests), services (business logic), and models/entities (data representation).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE1["Business Logic (TypeScript)"]:::frontend
        FE2["Static Assets (HTML/CSS)"]:::frontend
    end

    %% Backend API Server
    subgraph "Backend API Server (Express/TypeScript)"
        BE1["Entry Points (app.ts & index.ts)"]:::backend

        subgraph "Modules"
            Auth["Auth Module"]:::module
            Tasks["Tasks Module"]:::module
            Users["Users Module"]:::module
            AI["AI Module"]:::module
        end

        MW["Middlewares & Validators"]:::backend
        Shared["Shared Services & Utilities"]:::backend
        Config["Configuration Files"]:::backend
        Docs["API Documentation (Swagger)"]:::backend
    end

    %% Database & External Services
    DB(["PostgreSQL Database"]):::database
    GROQ["GROQ API"]:::external

    %% Data Flow Connections
    FE1 -->|"HTTP_Requests"| BE1
    FE2 -->|"Static_Content"| BE1

    BE1 -->|"Routes_to"| Auth
    BE1 -->|"Routes_to"| Tasks
    BE1 -->|"Routes_to"| Users
    BE1 -->|"Routes_to"| AI

    Auth -->|"Uses"| MW
    Tasks -->|"Uses"| MW
    Users -->|"Uses"| MW
    AI -->|"Uses"| MW

    Auth -->|"Calls"| Shared
    Tasks -->|"Calls"| Shared
    Users -->|"Calls"| Shared
    AI -->|"Calls"| Shared

    Auth -->|"Configured_by"| Config
    Tasks -->|"Configured_by"| Config
    Users -->|"Configured_by"| Config
    AI -->|"Configured_by"| Config

    Tasks -->|"CRUD_operations"| DB
    Users -->|"CRUD_operations"| DB

    AI -->|"External_call"| GROQ

    BE1 -->|"Docs_Provided"| Docs

    %% Styling classes
    classDef frontend fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef backend fill:#e2e3e5,stroke:#41464b,stroke-width:2px;
    classDef module fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;

    %% Click Events for Component Mapping
    click FE1 "https://github.com/alejandro-albiol/todopro/tree/main/frontend/src"
    click FE2 "https://github.com/alejandro-albiol/todopro/tree/main/public"
    click BE1 "https://github.com/alejandro-albiol/todopro/blob/main/backend/src/app.ts"
    click Auth "https://github.com/alejandro-albiol/todopro/tree/main/backend/src/auth"
    click Tasks "https://github.com/alejandro-albiol/todopro/tree/main/backend/src/tasks"
    click Users "https://github.com/alejandro-albiol/todopro/tree/main/backend/src/users"
    click AI "https://github.com/alejandro-albiol/todopro/tree/main/backend/src/ai"
    click MW "https://github.com/alejandro-albiol/todopro/tree/main/backend/src/middlewares"
    click Shared "https://github.com/alejandro-albiol/todopro/tree/main/backend/src/shared"
    click Config "https://github.com/alejandro-albiol/todopro/tree/main/backend/src/config"
    click Docs "https://github.com/alejandro-albiol/todopro/tree/main/backend/src/docs"
```
