# extendedguru4883/encryptednotes architecture

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

- Interactive diagram: https://gitdiagram.com/extendedguru4883/encryptednotes
- Repository: https://github.com/extendedguru4883/encryptednotes

## Overview

##### Project type and purpose
- This is a full-stack demo application showcasing zero-knowledge, end-to-end encrypted note taking.
- Frontend: Blazor WebAssembly client performs all encryption/decryption.
- Backend: .NET 8 Web API supporting authentication (challenge-response) and CRUD operations on encrypted notes.
- Layered architecture: API → BusinessLogic → DataAccess; Shared and Core projects hold DTOs, entities, abstractions.

##### File structure
- Top-level folders:
- Api: Web API controllers, middleware, JWT settings, mapping, program entry.
- BusinessLogic: core services (Auth, Note, Crypto, Signature, User) and mapping profiles.
- DataAccess: EF Core DbContext, migrations, repository implementations.
- Core: entity models, service/repository/infrastructure interfaces (abstractions).
- Shared: cross-cutting DTOs, constants, validation attributes, shared result types.
- Client: Blazor WASM app with pages, components, services (API client, crypto, auth state), models.
- Test: unit and integration tests for all layers.
- Configuration: launchSettings.json in Api and Client, .github/workflows for CI.

##### Insights from the README
- Client-side encryption with BlazorSodium; server uses Sodium.Core.
- Authentication uses a signed-nonce protocol; no passwords on server.
- SQLite (or pluggable) via EF Core; JWT for session tokens.
- Purpose is demo; not production grade.

a. Main components
- Blazor WebAssembly Client
- Web API (Api project)
- BusinessLogic layer
- DataAccess layer / SQLite database
- Shared/Core libraries (DTOs, entities, interfaces)
- External services: JWT issuer/audience configurations, optional CORS / static file hosting
b. Relationships & interactions
1. Client → Api (over HTTPS):
- Auth calls: Login / Signup (challenge-response endpoints)
- Calls: CRUD endpoints, sending/receiving encrypted payloads
2. Api → BusinessLogic: Api controllers use injected BusinessLogic services via Core abstractions
3. BusinessLogic → DataAccess: Services call repository interfaces to query/update data
4. DataAccess → SQLite: EF Core executes migrations and CRUD queries
5. Client Crypto: BlazorSodium library derives keys, encrypts/decrypts notes locally
6. Api Crypto: Sodium.Core verifies signatures, signs nonces, issues JWTs, but never sees plaintext notes
c. Architectural patterns & principles
- Onion/Clean architecture: UI → API → BusinessLogic → DataAccess → Database
- Dependency inversion: Core abstractions injected into upper layers
- Single responsibility: Controllers orchestrate, services implement logic, repos handle data
- Zero-knowledge encryption model enforced at client boundary
d. Key technologies/frameworks
- .NET 8 Web API, Blazor WebAssembly
- Entity Framework Core, SQLite
- BlazorSodium (client), Sodium.Core (server)
- AutoMapper profiles for mapping between DTOs/entities
- JWT for stateless auth

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Blazor WASM Client" 
        direction TB
        ClientUI["UI Pages"]:::client
        ClientServices["Services"]:::client
        ClientModels["Models/DTOs"]:::client
    end

    %% API Layer
    subgraph "Web API (.NET 8)" 
        direction TB
        ApiControllers["Controllers"]:::server
        ApiMiddleware["Middlewares"]:::server
        ApiConfig["JWTSettings & Mapping"]:::server
    end

    %% BusinessLogic Layer
    subgraph "BusinessLogic" 
        direction TB
        BLServices["AuthService<br/>NoteService<br/>CryptoService<br/>SignatureService<br/>UserService"]:::server
        BLMapping["AutoMapper Profile"]:::server
    end

    %% DataAccess Layer
    subgraph "DataAccess" 
        direction TB
        Repositories["NoteRepository<br/>UserRepository"]:::server
        DbContext["AppDbContext"]:::server
    end

    %% Shared/Core Libraries
    subgraph "Shared/Core Libraries" 
        direction TB
        CoreEntities["Entities & Abstractions"]:::shared
        SharedDTOs["DTOs, Constants, Validations, Results"]:::shared
    end

    %% Database
    SQLite["SQLite Database"]:::db

    %% Dependencies and Data Flow
    ClientUI -->|uses| ClientServices
    ClientServices -->|calls| ApiControllers
    ApiControllers -->|"injects Core abstractions"| BLServices
    BLServices -->|"calls repositories"| Repositories
    Repositories -->|uses| DbContext
    DbContext -->|CRUD| SQLite

    %% Library References
    ClientServices -.->|references| CoreEntities
    ApiControllers -.->|references| SharedDTOs
    BLServices -.->|uses| SharedDTOs
    Repositories -.->|implements| CoreEntities

    %% Click Events for Client
    click ClientUI "https://github.com/extendedguru4883/encryptednotes/tree/main/Client/Pages"
    click ClientServices "https://github.com/extendedguru4883/encryptednotes/tree/main/Client/Services"
    click ClientModels "https://github.com/extendedguru4883/encryptednotes/tree/main/Client/Models"

    click ClientUI "https://github.com/extendedguru4883/encryptednotes/blob/main/Client/Pages/Home.razor"
    click ClientUI "https://github.com/extendedguru4883/encryptednotes/blob/main/Client/Pages/Login.razor"
    click ClientUI "https://github.com/extendedguru4883/encryptednotes/blob/main/Client/Pages/Notes.razor"
    click ClientUI "https://github.com/extendedguru4883/encryptednotes/blob/main/Client/Pages/Signup.razor"

    click ClientServices "https://github.com/extendedguru4883/encryptednotes/blob/main/Client/Services/Clients/ApiClient.cs"
    click ClientServices "https://github.com/extendedguru4883/encryptednotes/blob/main/Client/Services/AuthService.cs"
    click ClientServices "https://github.com/extendedguru4883/encryptednotes/blob/main/Client/Services/CryptoService.cs"
    click ClientServices "https://github.com/extendedguru4883/encryptednotes/blob/main/Client/Services/NoteService.cs"
    click ClientServices "https://github.com/extendedguru4883/encryptednotes/blob/main/Client/Services/SignatureService.cs"
    click ClientServices "https://github.com/extendedguru4883/encryptednotes/blob/main/Client/Services/AuthStateService.cs"

    %% Click Events for API
    click ApiControllers "https://github.com/extendedguru4883/encryptednotes/blob/main/Api/Controllers/AuthController.cs"
    click ApiControllers "https://github.com/extendedguru4883/encryptednotes/blob/main/Api/Controllers/NotesController.cs"
    click ApiControllers "https://github.com/extendedguru4883/encryptednotes/blob/main/Api/Controllers/UserController.cs"
    click ApiMiddleware "https://github.com/extendedguru4883/encryptednotes/blob/main/Api/Middlewares/ErrorHandlingMiddleware.cs"
    click ApiConfig "https://github.com/extendedguru4883/encryptednotes/blob/main/Api/Configurations/JWTSettings.cs"
    click ApiConfig "https://github.com/extendedguru4883/encryptednotes/blob/main/Api/Mapping/ApiMappingProfile.cs"
    click ApiConfig "https://github.com/extendedguru4883/encryptednotes/blob/main/Api/Program.cs"

    %% Click Events for BusinessLogic
    click BLServices "https://github.com/extendedguru4883/encryptednotes/blob/main/BusinessLogic/Services/AuthService.cs"
    click BLServices "https://github.com/extendedguru4883/encryptednotes/blob/main/BusinessLogic/Services/NoteService.cs"
    click BLServices "https://github.com/extendedguru4883/encryptednotes/blob/main/BusinessLogic/Services/CryptoService.cs"
    click BLServices "https://github.com/extendedguru4883/encryptednotes/blob/main/BusinessLogic/Services/SignatureService.cs"
    click BLMapping "https://github.com/extendedguru4883/encryptednotes/blob/main/BusinessLogic/Mapping/BusinessLogicMappingProfile.cs"

    %% Click Events for DataAccess
    click DbContext "https://github.com/extendedguru4883/encryptednotes/blob/main/DataAccess/AppDbContext.cs"
    click Repositories "https://github.com/extendedguru4883/encryptednotes/blob/main/DataAccess/Repositories/NoteRepository.cs"
    click Repositories "https://github.com/extendedguru4883/encryptednotes/blob/main/DataAccess/Repositories/UserRepository.cs"

    %% Click Events for Shared/Core
    click CoreEntities "https://github.com/extendedguru4883/encryptednotes/blob/main/Core/Entities/NoteEntity.cs"
    click CoreEntities "https://github.com/extendedguru4883/encryptednotes/blob/main/Core/Abstractions/BusinessLogic/IAuthService.cs"
    click SharedDTOs "https://github.com/extendedguru4883/encryptednotes/blob/main/Shared/Dto/Requests/Auth/LoginRequest.cs"
    click SharedDTOs "https://github.com/extendedguru4883/encryptednotes/blob/main/Shared/Dto/Responses/LoginResponse.cs"

    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef server fill:#98FB98,stroke:#333,stroke-width:1px;
    classDef shared fill:#D3D3D3,stroke:#333,stroke-width:1px;
    classDef db fill:#F5DEB3,stroke:#333,stroke-width:1px;
```
