# giriiri-g/toxicitydetection architecture

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

- Interactive diagram: https://gitdiagram.com/giriiri-g/toxicitydetection
- Repository: https://github.com/giriiri-g/toxicitydetection

## Overview

1. **Overall shape**
   - This repo is a two-tier community moderation platform: an **ASP.NET Core backend API** plus an **Angular frontend**.
   - The core product concern is **toxicity detection and moderation**, not just generic posting.

2. **Runtime boundary: backend**
   - The backend lives in `API/` and is the main application service.
   - It exposes domain-specific controllers for **auth, posts, reviewers, and admins**.
   - The API is the boundary between the browser UI and persisted moderation/content data.

3. **Runtime boundary: frontend**
   - The active UI is in `Frontend/`, built with **Angular/TypeScript**.
   - It contains routed pages for **landing, sign-in/sign-up, feed, reviewer workflows, and admin dashboards**.
   - Angular services mirror backend capabilities: `auth.service.ts`, `post.service.ts`, and `reviewer.service.ts`.

4. **Legacy / non-runtime UI code**
   - `Old Frontend components/` appears to be an older Angular implementation kept in the repo for reference or migration.
   - It is useful for understanding the product history, but the current architecture is centered on `Frontend/`.

5. **Backend layering**
   - The API follows a classic layered structure:
     - **Controllers** handle HTTP endpoints.
     - **Services** implement business rules.
     - **Repositories** wrap persistence access.
     - **Entities** define the EF Core domain model.
     - **DTOs** define request/response contracts.
   - This separation is important for diagramming the control flow from UI → API → service → data store.

6. **Domain model / data boundaries**
   - The main entities are `User`, `Post`, `Likes`, `Ban`, `BanHistory`, `TagScore`, `ToxicityConfig`, and `Auth`.
   - These show the system tracks:
     - user identities and authentication,
     - submitted content,
     - moderation outcomes,
     - ban actions and history,
     - toxicity scoring/configuration,
     - user interactions such as likes.
   - `TagScore` and `ToxicityConfig` are especially important because they connect content analysis to moderation decisions.

7. **Toxicity detection and moderation flow**
   - `ToxicityService` is the key business component for content scoring/classification.
   - `ReviewerService` and `AdminService` indicate a moderation pipeline with human oversight:
     - content is ingested,
     - scored for toxicity,
     - reviewed/acted on by moderators,
     - escalated to admin controls when needed.
   - `PostService` likely coordinates post creation and the scoring/moderation lifecycle.

8. **Role-based workflows**
   - The frontend has dedicated pages for **admin**, **reviewer**, and regular user experiences.
   - Guard files (`auth.guard.ts`, `role.guard.ts`) show the UI enforces access by authentication and role.
   - On the backend, the controller split implies separate operational boundaries for user-facing actions versus moderation/admin actions.

9. **Persistence and schema evolution**
   - Data is persisted through **Entity Framework Core** using `AppDbContext`.
   - `API/Migrations/` shows the schema evolved over time: initial auth, posts/tag scores, toxicity config, threaded posts, bans, and likes.
   - `API/HRBC.db` suggests the current repo includes a local **SQLite** database file for development or demo use, even though the README mentions MSSQL/MySQL as supported targets.

10. **API contract layer**
    - DTOs such as `CreatePostDto`, `LoginDto`, `RegisterDto`, `PostResponseDto`, `ReviewerDtos`, `AdminDtos`, and `UserStatsDto` define the data exchanged with the UI.
    - This keeps the frontend decoupled from the EF entities and prevents direct coupling to the persistence model.

11. **Frontend structure**
    - The Angular app is organized by feature pages rather than a single monolith:
      - `feed` for content browsing/detail,
      - `reviewer` for moderation tasks,
      - `admin` with subpages for toxicity control, user control, user stats, and thread ranking,
      - `signin`, `signup`, and `forgot-password` for account access,
      - `landing` and `home` for public entry points.
    - `assets/data/feed.json` suggests there is also some local/demo content used by the UI.

12. **Supporting artifacts**
    - `DesignDoc/` contains design and sample website materials that document intended behavior and UI.
    - `CLAUDE.md`, `.slnx`, and the various `README`/guideline files are supporting documentation, not runtime components.
    - For an architecture diagram, the main live path is: **Angular UI → ASP.NET Core API → EF Core/DB**, with **toxicity/moderation services** as the central business core.

Main entry points: [`Frontend/src/app`](https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app) (Angular app), [`API/Controllers`](https://github.com/giriiri-g/toxicitydetection/tree/master/API/Controllers) (Controllers), [`API/Data/AppDbContext.cs`](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Data/AppDbContext.cs) (DbContext), [`API/Services`](https://github.com/giriiri-g/toxicitydetection/tree/master/API/Services) (Business services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["Angular app<br/>ui-shell"]
  node_frontend_auth["Auth pages<br/>ui-pages"]
  node_frontend_feed["Feed pages<br/>ui-pages"]
  node_frontend_reviewer["Reviewer page<br/>moderation-ui"]
  node_frontend_admin["Admin pages<br/>admin-ui"]
  node_frontend_services["API services<br/>client-services"]
  node_frontend_guards{{"Route guards<br/>access-control"}}
end

subgraph group_backend["API"]
  node_api_controllers["Controllers<br/>http-api"]
  node_api_auth_controller["Auth controller<br/>endpoint<br/>[AuthController.cs]"]
  node_api_post_controller["Post controller<br/>endpoint<br/>[PostController.cs]"]
  node_api_reviewer_controller["Reviewer controller<br/>endpoint"]
  node_api_admin_controller["Admin controller<br/>endpoint<br/>[AdminController.cs]"]
  node_api_services["Business services<br/>application-services"]
  node_api_auth_service["Auth service<br/>account-logic<br/>[AuthService.cs]"]
  node_api_post_service["Post service<br/>content-logic<br/>[PostService.cs]"]
  node_api_reviewer_service["Reviewer service<br/>moderation-logic<br/>[ReviewerService.cs]"]
  node_api_admin_service["Admin service<br/>admin-logic<br/>[AdminService.cs]"]
  node_api_toxicity_service{{"Toxicity service<br/>scoring-core<br/>[ToxicityService.cs]"}}
  node_api_repositories["Repositories<br/>data-access"]
end

subgraph group_legacy["Legacy UI"]
  node_legacy_ui["Old frontend<br/>legacy-angular"]
end

subgraph group_data["Data"]
  node_api_dbcontext["DbContext<br/>ef-core<br/>[AppDbContext.cs]"]
  node_api_domain[("Domain model<br/>entities")]
  node_api_db[("SQLite DB<br/>database<br/>[HRBC.db]")]
end

subgraph group_docs["Docs"]
  node_docs_pack["Design docs<br/>documentation"]
end

node_frontend_app -->|"routes"| node_frontend_auth
node_frontend_app -->|"routes"| node_frontend_feed
node_frontend_app -->|"routes"| node_frontend_reviewer
node_frontend_app -->|"routes"| node_frontend_admin
node_frontend_app -->|"uses"| node_frontend_services
node_frontend_app -->|"protects"| node_frontend_guards
node_frontend_services -->|"HTTP API"| node_api_controllers
node_api_controllers -->|"includes"| node_api_auth_controller
node_api_controllers -->|"includes"| node_api_post_controller
node_api_controllers -->|"includes"| node_api_reviewer_controller
node_api_controllers -->|"includes"| node_api_admin_controller
node_api_auth_controller -->|"calls"| node_api_auth_service
node_api_post_controller -->|"calls"| node_api_post_service
node_api_reviewer_controller -->|"calls"| node_api_reviewer_service
node_api_admin_controller -->|"calls"| node_api_admin_service
node_api_services -->|"uses"| node_api_toxicity_service
node_api_services -->|"reads/writes"| node_api_repositories
node_api_repositories -->|"uses"| node_api_dbcontext
node_api_dbcontext -->|"maps"| node_api_domain
node_api_dbcontext -->|"persists"| node_api_db
node_legacy_ui -.->|"references"| node_docs_pack
node_docs_pack -.->|"informs"| node_frontend_app

click node_frontend_app "https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app"
click node_frontend_auth "https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/signin"
click node_frontend_feed "https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/pages/feed"
click node_frontend_reviewer "https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/pages/reviewer"
click node_frontend_admin "https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/pages/admin"
click node_frontend_services "https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/services"
click node_frontend_guards "https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/guards"
click node_api_controllers "https://github.com/giriiri-g/toxicitydetection/tree/master/API/Controllers"
click node_api_auth_controller "https://github.com/giriiri-g/toxicitydetection/blob/master/API/Controllers/AuthController.cs"
click node_api_post_controller "https://github.com/giriiri-g/toxicitydetection/blob/master/API/Controllers/PostController.cs"
click node_api_reviewer_controller "https://github.com/giriiri-g/toxicitydetection/blob/master/API/Controllers/ReviewerController.cs"
click node_api_admin_controller "https://github.com/giriiri-g/toxicitydetection/blob/master/API/Controllers/AdminController.cs"
click node_api_services "https://github.com/giriiri-g/toxicitydetection/tree/master/API/Services"
click node_api_auth_service "https://github.com/giriiri-g/toxicitydetection/blob/master/API/Services/AuthService.cs"
click node_api_post_service "https://github.com/giriiri-g/toxicitydetection/blob/master/API/Services/PostService.cs"
click node_api_reviewer_service "https://github.com/giriiri-g/toxicitydetection/blob/master/API/Services/ReviewerService.cs"
click node_api_admin_service "https://github.com/giriiri-g/toxicitydetection/blob/master/API/Services/AdminService.cs"
click node_api_toxicity_service "https://github.com/giriiri-g/toxicitydetection/blob/master/API/Services/ToxicityService.cs"
click node_api_repositories "https://github.com/giriiri-g/toxicitydetection/tree/master/API/Data/Repositories"
click node_api_dbcontext "https://github.com/giriiri-g/toxicitydetection/blob/master/API/Data/AppDbContext.cs"
click node_api_domain "https://github.com/giriiri-g/toxicitydetection/tree/master/API/Entities"
click node_api_db "https://github.com/giriiri-g/toxicitydetection/blob/master/API/HRBC.db"
click node_legacy_ui "https://github.com/giriiri-g/toxicitydetection/tree/master/Old Frontend components"
click node_docs_pack "https://github.com/giriiri-g/toxicitydetection/tree/master/DesignDoc"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_app,node_frontend_auth,node_frontend_feed,node_frontend_reviewer,node_frontend_admin,node_frontend_services,node_frontend_guards toneBlue
class node_api_controllers,node_api_auth_controller,node_api_post_controller,node_api_reviewer_controller,node_api_admin_controller,node_api_services,node_api_auth_service,node_api_post_service,node_api_reviewer_service,node_api_admin_service,node_api_toxicity_service,node_api_repositories toneAmber
class node_legacy_ui toneMint
class node_api_dbcontext,node_api_domain,node_api_db toneRose
class node_docs_pack toneIndigo
```

## Components

### Frontend

Active Angular UI

- [Angular app](https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app): ui-shell · Routes, guards, and feature composition for the active browser app · `Frontend/src/app`
- [Auth pages](https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/signin): ui-pages · Sign-in, sign-up, and password recovery flows · `Frontend/src/app/signin`
- [Feed pages](https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/pages/feed): ui-pages · Landing feed and post detail experience · `Frontend/src/app/pages/feed`
- [Reviewer page](https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/pages/reviewer): moderation-ui · Reviewer workflow for human moderation tasks · `Frontend/src/app/pages/reviewer`
- [Admin pages](https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/pages/admin): admin-ui · Admin dashboards for toxicity, users, stats, and ranking · `Frontend/src/app/pages/admin`
- [API services](https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/services): client-services · Auth, post, and reviewer service wrappers for backend calls · `Frontend/src/app/services`
- [Route guards](https://github.com/giriiri-g/toxicitydetection/tree/master/Frontend/src/app/guards): access-control · Authentication and role-based route protection · `Frontend/src/app/guards`

### API

ASP.NET Core backend

- [Controllers](https://github.com/giriiri-g/toxicitydetection/tree/master/API/Controllers): http-api · HTTP entry points for auth, posts, reviewer, and admin operations · `API/Controllers`
- [Auth controller](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Controllers/AuthController.cs): endpoint · Login, registration, and account access endpoints · `API/Controllers/AuthController.cs`
- [Post controller](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Controllers/PostController.cs): endpoint · Post creation and content retrieval endpoints · `API/Controllers/PostController.cs`
- [Reviewer controller](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Controllers/ReviewerController.cs): endpoint · Reviewer workflow endpoints for moderation actions · `API/Controllers/ReviewerController.cs`
- [Admin controller](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Controllers/AdminController.cs): endpoint · Admin endpoints for toxicity control and user management · `API/Controllers/AdminController.cs`
- [Business services](https://github.com/giriiri-g/toxicitydetection/tree/master/API/Services): application-services · Core moderation and account business logic · `API/Services`
- [Auth service](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Services/AuthService.cs): account-logic · Authentication and registration rules · `API/Services/AuthService.cs`
- [Post service](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Services/PostService.cs): content-logic · Post lifecycle and moderation coordination · `API/Services/PostService.cs`
- [Reviewer service](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Services/ReviewerService.cs): moderation-logic · Reviewer workflow and decisions · `API/Services/ReviewerService.cs`
- [Admin service](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Services/AdminService.cs): admin-logic · Administrative controls and oversight functions · `API/Services/AdminService.cs`
- [Toxicity service](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Services/ToxicityService.cs): scoring-core · Content scoring and toxicity classification · `API/Services/ToxicityService.cs`
- [Repositories](https://github.com/giriiri-g/toxicitydetection/tree/master/API/Data/Repositories): data-access · Persistence abstractions for posts and users · `API/Data/Repositories`

### Legacy UI

Older frontend implementation

- [Old frontend](https://github.com/giriiri-g/toxicitydetection/tree/HEAD/Old%20Frontend%20components): legacy-angular · Previous UI implementation kept for reference and migration · `Old Frontend components`

### Data

Persistence and domain model

- [DbContext](https://github.com/giriiri-g/toxicitydetection/blob/master/API/Data/AppDbContext.cs): ef-core · Entity Framework Core unit of work and model mapping · `API/Data/AppDbContext.cs`
- [Domain model](https://github.com/giriiri-g/toxicitydetection/tree/master/API/Entities): entities · User, Post, Ban, Likes, TagScore, ToxicityConfig, and Auth entities · `API/Entities`
- [SQLite DB](https://github.com/giriiri-g/toxicitydetection/blob/master/API/HRBC.db): database · Local development database file · `API/HRBC.db`

### Docs

Design and supporting material

- [Design docs](https://github.com/giriiri-g/toxicitydetection/tree/master/DesignDoc): documentation · Requirements, architecture notes, and sample UI artifacts · `DesignDoc`

## Connections

- Angular app → Auth pages: routes · Maps browser routes to account pages
- Angular app → Feed pages: routes · Maps browser routes to feed pages
- Angular app → Reviewer page: routes · Maps browser routes to reviewer workflows
- Angular app → Admin pages: routes · Maps browser routes to admin dashboards
- Angular app → API services: uses · Feature components call client services
- Angular app → Route guards: protects · Guards restrict authenticated and role-based routes
- API services → Controllers: HTTP API · Client services invoke backend endpoints
- Controllers → Auth controller: includes · Authentication endpoints
- Controllers → Post controller: includes · Post endpoints
- Controllers → Reviewer controller: includes · Reviewer endpoints
- Controllers → Admin controller: includes · Admin endpoints
- Auth controller → Auth service: calls · Delegates account logic to services
- Post controller → Post service: calls · Delegates post operations to services
- Reviewer controller → Reviewer service: calls · Delegates reviewer actions to services
- Admin controller → Admin service: calls · Delegates admin actions to services
- Business services → Toxicity service: uses · Moderation services depend on toxicity scoring
- Business services → Repositories: reads/writes · Business services persist through repositories
- Repositories → DbContext: uses · Repositories execute through EF Core context
- DbContext → Domain model: maps · DbContext maps the entity model
- DbContext → SQLite DB: persists · EF Core stores data in the local database
- Old frontend → Design docs: references · Legacy UI and design artifacts document the earlier product shape
- Design docs → Angular app: informs · Design materials mirror the current UI structure
