# annerh3/cookies-test architecture

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

- Interactive diagram: https://gitdiagram.com/annerh3/cookies-test
- Repository: https://github.com/annerh3/cookies-test

## Overview

##### Project type and purpose
- This is a full-stack web application demonstrating secure authentication using HTTP-Only cookies instead of localStorage.
- Front-end: React single-page application (client/auth-cookies) built with Vite and Tailwind.
- Back-end: ASP.NET Core Web API (server/CookiesProyect) with Entity Framework Core for data access.
- Purpose: Provide a contacts list app with role-based authorization and automatic token refresh via HTTP-Only cookies.

##### File structure
- Top-level directories:
- bruno/…: Bruno test scripts (automated API calls).
- client/auth-cookies/: React SPA, including src/components, src/pages, src/routes, src/store, src/config, src/hooks, utilities.
- server/CookiesProyect/: ASP.NET solution with Controllers, Services, Database (DbContext, Entities, Configuration, Migrations, SeedData), Dtos, Helpers, appsettings, Program/Startup.
- Architectural hints:
- Front-end uses a Redux-style store (useAuthStore, actions, hooks).
- Back-end follows an MVC-style layering: Controllers → Services → DbContext → Entities.
- Config files for environment (.env), build (vite.config.js), ESLint, Tailwind.

##### README for additional insights
- Describes security threat (XSS) and solution (HTTP-Only cookies).
- Highlights endpoints: /api/auth/login, /api/auth/refresh-token, /api/auth/validate, /api/contacts.
- Lists technologies (React, .NET, JWT, EF Core, Cookie auth).
- Mentions live demo URL and sample users.

##### Detail
- Front-end folder as a sub-component (e.g., src/components, src/store).
- Back-end layer (Controllers, Services, Data).
- Where environment variables (.env, appsettings.json) are loaded.
- HTTP headers vs. HTTP-Only cookies.
- Security boundary around cookies (HTTP-Only flag, SameSite, Secure).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLIENT LAYER
    subgraph "Client (Browser & React SPA)"
        direction TB
        Browser["Browser"]:::external
        CookieStore["HTTP-Only Cookie Store"]:::cookie
        subgraph "React Application" 
            direction TB
            UI["UI Components"]:::frontend
            Router["AppRouter.jsx"]:::frontend
            Store["Auth Store & Hooks"]:::frontend
            APIClient["API Client (api.js)"]:::frontend
            Utilities["Utilities"]:::frontend
            EnvConfig["Environment & Build Config"]:::frontend
        end
    end

    %% SERVER LAYER
    subgraph "Server (.NET Core Web API)"
        direction TB
        subgraph "Controllers"
            AuthController["AuthController"]:::backend
            ContactsController["ContactsController"]:::backend
        end
        subgraph "Services"
            AuthService["AuthService"]:::backend
            ContactService["ContactService"]:::backend
            AuditService["AuditService"]:::backend
        end
        subgraph "Data Access"
            DbContext["ContactsDbContext"]:::backend
            Entities["Entities"]:::backend
            Configuration["Entity Configuration"]:::backend
            Seeder["Test Seeder"]:::backend
        end
        subgraph "Migrations & SeedData"
            Migrations["Migrations"]:::backend
            SeedData["Seed Data (contacts.json)"]:::backend
        end
        subgraph "DTOs"
            AuthDTOs["Auth DTOs"]:::backend
            ContactDTOs["Contact DTOs"]:::backend
            CommonDTOs["Common DTOs"]:::backend
        end
        subgraph "Helpers"
            JwtEvents["CustomJwtBearerEventsFactory"]:::backend
            ResponseHelper["ResponseHelper"]:::backend
        end
        subgraph "Config & Startup"
            Program["Program.cs & Startup.cs"]:::backend
            AppSettings["appsettings.json"]:::backend
        end
        subgraph "Constants"
            Constants["Messages & Roles Constants"]:::backend
        end
    end

    %% DATABASE
    Database["SQL Server Database"]:::database

    %% AUTOMATED TESTING
    Bruno["Bruno Automation"]:::testing

    %% FLOW
    Browser -->|navigates| UI
    UI -->|routes| Router
    Router -->|calls actions| Store
    Store -->|uses| APIClient
    APIClient -->|sends credentials| AuthController
    AuthController -->|issues tokens| CookieStore
    CookieStore -.->|attached in headers| APIClient
    APIClient -->|requests| ContactsController
    ContactsController -->|calls| ContactService
    ContactService -->|uses| DbContext
    DbContext -->|queries| Database
    AuthController -->|calls| AuthService
    AuthService -->|uses| DbContext
    AuthService -->|records audit| AuditService
    AuditService -->|uses| DbContext
    ContactsController -->|returns| APIClient
    APIClient -->|updates UI| UI
    APIClient -.->|on expiry| AuthController
    APIClient -.->|validate session| AuthController
    Bruno -->|tests endpoints| AuthController
    Bruno -->|tests endpoints| ContactsController

    %% CLICK EVENTS - Client
    click UI "https://github.com/annerh3/cookies-test/tree/main/client/auth-cookies/src/components/"
    click Router "https://github.com/annerh3/cookies-test/blob/main/client/auth-cookies/src/routes/AppRouter.jsx"
    click Store "https://github.com/annerh3/cookies-test/tree/main/client/auth-cookies/src/store/"
    click APIClient "https://github.com/annerh3/cookies-test/blob/main/client/auth-cookies/src/config/api.js"
    click Utilities "https://github.com/annerh3/cookies-test/tree/main/client/auth-cookies/src/utilities/"
    click EnvConfig "https://github.com/annerh3/cookies-test/blob/main/client/auth-cookies/.env"
    click EnvConfig "https://github.com/annerh3/cookies-test/blob/main/client/auth-cookies/vite.config.js"

    %% CLICK EVENTS - Server
    click AuthController "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/Controllers/AuthController.cs"
    click ContactsController "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/Controllers/ContactsController.cs"
    click AuthService "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/Services/AuthService.cs"
    click ContactService "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/Services/ContactService.cs"
    click AuditService "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/Services/AuditService.cs"
    click DbContext "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/Database/ContactsDbContext.cs"
    click Entities "https://github.com/annerh3/cookies-test/tree/main/server/CookiesProyect/CookiesProyect/Database/Entities/"
    click Configuration "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/Database/Configuration/ContactConfiguration.cs"
    click Seeder "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/Database/ConstactsTestSeeder.cs"
    click Migrations "https://github.com/annerh3/cookies-test/tree/main/server/CookiesProyect/CookiesProyect/Migrations/"
    click SeedData "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/SeedData/contacts.json"
    click Program "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/Program.cs"
    click AppSettings "https://github.com/annerh3/cookies-test/blob/main/server/CookiesProyect/CookiesProyect/appsettings.json"
    click Constants "https://github.com/annerh3/cookies-test/tree/main/server/CookiesProyect/CookiesProyect/Constants/"

    %% CLICK EVENTS - Bruno
    click Bruno "https://github.com/annerh3/cookies-test/tree/main/bruno/Contacts/"

    %% STYLES
    classDef frontend fill:#cce5ff,stroke:#339af0,color:#000;
    classDef backend fill:#d4f8d4,stroke:#40c057,color:#000;
    classDef database fill:#ffd8a8,stroke:#fa8c16,color:#000;
    classDef cookie fill:#e9ecef,stroke:#adb5bd,color:#000;
    classDef external fill:#f1f3f5,stroke:#868e96,color:#000;
    classDef testing fill:#e5dbff,stroke:#7950f2,color:#000;
```
