Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 61 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@

AI-assisted, multi-tenant support platform API built with ASP.NET Core (.NET 10).

![CI](https://github.com/Youssef11-dev/basira-support-api/actions/workflows/ci.yml/badge.svg)
[![CI](https://github.com/Youssef11-dev/basira-support-api/actions/workflows/ci.yml/badge.svg)](https://github.com/Youssef11-dev/basira-support-api/actions/workflows/ci.yml)

> **Status:** in development. Phase 0 (foundation) is done: solution structure,
> architecture tests, CI. Features below are **planned**, not implemented yet.
> **Status:** in development. Phase 0 (foundation) is done. Phase 1 is in
> progress: the Identity domain (organizations and users) and its database
> schema are in place; the first API endpoints are next.

## Planned features
## Features

- Multi-tenant organizations with role-based access
- Support tickets with a defined lifecycle
- Knowledge base: document upload and background processing
- AI-suggested replies grounded in company documents, with sources
- Notifications
- [ ] Multi-tenant organizations with role-based access *(domain and database done)*
- [ ] Support tickets with a defined lifecycle
- [ ] Knowledge base: document upload and background processing
- [ ] AI-suggested replies grounded in company documents, with sources
- [ ] Notifications

## Architecture

A modular monolith: one deployable app, split into modules with enforced
boundaries. See [ADR-0001](docs/adr/0001-modular-monolith.md).
boundaries. Each module has its own layers and its own database schema.
See [ADR-0001](docs/adr/0001-modular-monolith.md).

```mermaid
flowchart TD
Expand All @@ -31,23 +33,51 @@ flowchart TD

Solid arrows are implemented, dashed arrows are planned.

### Architecture decisions

| ADR | Decision |
|-----|----------|
| [0001](docs/adr/0001-modular-monolith.md) | Modular monolith with Clean Architecture per module |
| [0002](docs/adr/0002-postgresql.md) | PostgreSQL as the relational database |
| [0003](docs/adr/0003-authentication.md) | JWT authentication with a custom User and PasswordHasher |
| [0004](docs/adr/0004-email-uniqueness.md) | User email is unique across the whole system |

## Tech stack

- ASP.NET Core Web API, C#, .NET 10
- Entity Framework Core with PostgreSQL
- Entity Framework Core with PostgreSQL (Npgsql)
- xUnit and NetArchTest for tests
- GitHub Actions for CI

## Getting started

Prerequisites: .NET 10 SDK, PostgreSQL.
Prerequisites: .NET 10 SDK, PostgreSQL, and the EF Core CLI
(`dotnet tool install --global dotnet-ef`).

```bash
git clone https://github.com/Youssef11-dev/basira-support-api.git
cd basira-support-api
dotnet user-secrets set "ConnectionStrings:Default" "Host=localhost;Port=5432;Database=basira_dev;Username=postgres;Password=<your-password>" --project src/Host
dotnet run --project src/Host
```
1. Clone the repository:

```bash
git clone https://github.com/Youssef11-dev/basira-support-api.git
cd basira-support-api
```

2. Set the connection string (stored in user secrets, not in the repo):

```bash
dotnet user-secrets set "ConnectionStrings:Default" "Host=localhost;Port=5432;Database=basira_dev;Username=postgres;Password=<your-password>" --project src/Host
```

3. Create the database schema by applying the migrations:

```bash
dotnet ef database update --project src/Modules/Identity/Infrastructure --startup-project src/Host --context IdentityDbContext
```

4. Run the API:

```bash
dotnet run --project src/Host
```

Then open `/health` on the URL printed in the console. It should return `Healthy`.

Expand All @@ -61,20 +91,26 @@ dotnet test

```
src/
Host/ composition root (Program.cs)
BuildingBlocks/ shared abstractions
Host/ composition root (Program.cs)
BuildingBlocks/ shared abstractions (Entity, DomainException)
Modules/
Identity/ Domain, Application, Infrastructure, Contracts, Api
Identity/
Domain/ Organization, User, UserRole
Application/ use cases (planned)
Infrastructure/ IdentityDbContext, Persistence/ (configurations, migrations)
Contracts/ public API for other modules (planned)
Api/ endpoints (planned)
tests/
Architecture.Tests/
Architecture.Tests/ enforces module and layer boundaries
Identity.UnitTests/ domain tests for Organization and User
docs/
adr/ architecture decision records
adr/ architecture decision records
```

## Roadmap

- [x] Phase 0: foundation (structure, architecture tests, CI)
- [ ] Phase 1: Identity and Tickets
- [ ] Phase 1: Identity and Tickets *(in progress)*
- [ ] Phase 2: production concerns (background jobs, caching, observability)
- [ ] Phase 3: knowledge base and AI assistant
- [ ] Phase 4: polish and deployment
- [ ] Phase 4: polish and deployment
33 changes: 33 additions & 0 deletions docs/adr/0004-email-uniqueness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ADR-0004: User email is unique across the whole system

- **Status:** Accepted
- **Date:** 2026-12-03

## Context

Users sign in with email and password, and the organization comes from the
token (ADR-0003). At login time the API must find exactly one user from the
email alone.

## Decision

`users.email` has a unique index across all organizations. One email belongs
to one user in one organization.

## Alternatives considered

- **Unique per organization `(OrganizationId, Email)`:** lets one person have
separate accounts in several organizations, but login becomes ambiguous and
needs the organization as extra input (e.g. a subdomain or org slug).
- **Global user with memberships:** one user, many organizations, a role per
membership. Most flexible, but adds a new entity, an org-switch step at
login, and token reissuing. Deferred; can be revisited later.

## Consequences

**Positive**
- Simple login: email + password.
- The token's `org_id` comes straight from the user.

**Negative**
- A customer of two organizations needs two different emails.
2 changes: 1 addition & 1 deletion src/Modules/Identity/Domain/Organizations/Organization.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;


using Basira.BuildingBlocks.Domain;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Basira.Modules.Identity.Infrastructure.Persistence.Configurations;
internal sealed class OrganizationConfiguration : IEntityTypeConfiguration<Organization>
{
public void Configure(EntityTypeBuilder<Organization> builder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@


using Basira.Modules.Identity.Domain.Organizations;
using Basira.Modules.Identity.Domain.Organizations;
using Basira.Modules.Identity.Domain.Users;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Basira.Modules.Identity.Infrastructure.Configurations;
namespace Basira.Modules.Identity.Infrastructure.Persistence.Configurations;

internal sealed class UserConfiguration : IEntityTypeConfiguration<User>
{
Expand All @@ -33,7 +31,6 @@ public void Configure(EntityTypeBuilder<User> builder)
builder.HasOne<Organization>()
.WithMany()
.HasForeignKey(u => u.OrganizationId).OnDelete(DeleteBehavior.Restrict);
builder.HasIndex(u => new { u.OrganizationId, u.Email })
.IsUnique();
builder.HasIndex(u => u.Email).IsUnique();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Basira.Modules.Identity.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class MakeEmailGloballyUnique : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_users_OrganizationId_Email",
schema: "identity",
table: "users");

migrationBuilder.CreateIndex(
name: "IX_users_Email",
schema: "identity",
table: "users",
column: "Email",
unique: true);

migrationBuilder.CreateIndex(
name: "IX_users_OrganizationId",
schema: "identity",
table: "users",
column: "OrganizationId");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_users_Email",
schema: "identity",
table: "users");

migrationBuilder.DropIndex(
name: "IX_users_OrganizationId",
schema: "identity",
table: "users");

migrationBuilder.CreateIndex(
name: "IX_users_OrganizationId_Email",
schema: "identity",
table: "users",
columns: new[] { "OrganizationId", "Email" },
unique: true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasKey("Id");

b.HasIndex("OrganizationId", "Email")
b.HasIndex("Email")
.IsUnique();

b.HasIndex("OrganizationId");

b.ToTable("users", "identity");
});

Expand Down