Second pass on backend/Tests/, covering what Domain+Application (the first
pass) deliberately left out — the parts that talk to real infrastructure:
Musify.Infrastructure.Tests Database/migrations, StorageService,
StreamTicketService, AuditableEntityInterceptor,
PictureService, SingleFlightCache,
PlayListPresetSeeder.
Musify.Api.Tests Real HTTP endpoints via WebApplicationFactory
(routing, auth, ValidationFilter, ErrorOr->HTTP
mapping), plus isolated unit tests for
ErrorOrHttpExtensions, CurrentUser and the
FluentValidation validators.
Musify.StreamingGateway.Tests TicketValidator (RS256) and
TicketValidationMiddleware (path traversal,
prefix boundary, ticket extraction).
Musify.Worker gets no test project: its Program.cs is pure DI/host wiring
(Hangfire, MassTransit, jobs); the logic it runs lives in Musify.Infrastructure,
already covered there.
Per the user's direction, the parts that touch real infrastructure use
Testcontainers instead of fakes: a real Postgres (Testcontainers.PostgreSql)
for Infrastructure.Tests and Api.Tests, and — matching deploy/compose.yml
exactly (chrislusf/seaweedfs:latest, same startup command), not MinIO — a
real SeaweedFS container for StorageService. Api.Tests boots the actual
Musify.Api host against that Postgres (real routing/auth/validation) but
substitutes the services that talk over the network (storage, YouTube, the
message bus, stream-ticket signing) with NSubstitute fakes, and swaps the
JwtBearer scheme for a test-only header-based one (FakeAuthenticationHandler)
so tests don't need a reachable Zitadel. Application.Tests' approach — a real
DbContext (SQLite in-memory) rather than mocking IDatabase, since it exposes
DbSet<T> directly and handlers compose real LINQ queries against it — carries
over into Infrastructure.Tests/Api.Tests via real Postgres instead.
Testing against the real backend (not a fake) found two genuine production
bugs, both fixed here:
- StorageService.RemoveFolderAsync threw NullReferenceException against
SeaweedFS: its DeleteObjects response omits the <Error> list entirely when
nothing failed, which the AWS SDK deserializes as null rather than an empty
list (real AWS S3 always returns one). Now treats null as no errors.
- AuditableEntityInterceptor never bumped UpdatedAt on a normal update (load,
mutate a property, SaveChanges) — only on insert. SavingChanges(Async) fires
before EF's own automatic change detection for that save, so an entity
modified through a plain property setter still reported EntityState.Unchanged
inside the interceptor. Now calls ChangeTracker.DetectChanges() explicitly
first, which is the documented fix for exactly this interceptor pattern.
Also required to make the Api host testable: Program.cs now ends with `public
partial class Program;` (WebApplicationFactory<Program> needs the top-level-
statements Program class to be public — no behavior change), and
Directory.Packages.props gains Microsoft.AspNetCore.Mvc.Testing, Testcontainers
and Testcontainers.PostgreSql.
249 tests total across all five projects, all green: `dotnet test
backend/Musify.slnx` (needs Docker running for Infrastructure.Tests and
Api.Tests).
58 lines
2.4 KiB
Markdown
58 lines
2.4 KiB
Markdown
# Musify
|
|
|
|
Music streaming platform: upload your own tracks (or import them from YouTube),
|
|
process them asynchronously (audio transcoded to `.m4a`, thumbnails generated)
|
|
and stream them without the bytes ever going through the API.
|
|
|
|
```
|
|
backend/ .NET 10 — Domain / Application / Infrastructure / Api / Worker / StreamingGateway / Tests
|
|
web-player/ SvelteKit 2 + Svelte 5 + Tailwind 4 web client
|
|
deploy/ Docker Compose stacks — self-contained, no wrapper scripts
|
|
docs/ What each piece does and why (in Spanish)
|
|
```
|
|
|
|
```sh
|
|
dotnet test backend/Musify.slnx # backend/Tests/ — Docker running (Testcontainers: Postgres, SeaweedFS)
|
|
```
|
|
|
|
## Run it
|
|
|
|
Development (Docker Desktop):
|
|
|
|
```sh
|
|
docker compose -f deploy/compose.yml -f deploy/compose.dev.yml up -d
|
|
```
|
|
|
|
Infrastructure plus stream-ticket keys, database migrations and Zitadel OIDC
|
|
provisioning — all as one-shot jobs baked into the compose file. Apps run from
|
|
the IDE by default; add `--profile apps up -d --build` as a second command to
|
|
run them in Docker instead.
|
|
|
|
Production, on a server with a domain:
|
|
|
|
```sh
|
|
cp deploy/.env.prod.example deploy/.env.prod # fill in the domain and secrets
|
|
docker compose --env-file deploy/.env.prod -f deploy/compose.yml -f deploy/compose.prod.yml up -d
|
|
docker compose --env-file deploy/.env.prod -f deploy/compose.yml -f deploy/compose.prod.yml --profile apps up -d --build
|
|
```
|
|
|
|
Idempotent — run the same commands again to deploy an update. See
|
|
[deploy/README.md](deploy/README.md) for the details, the port map and the
|
|
production prerequisites.
|
|
|
|
## Components
|
|
|
|
| Service | Port (dev) | Role |
|
|
|---|---|---|
|
|
| `Musify.Api` | 5111 | REST API, issues presigned upload URLs and stream tickets |
|
|
| `Musify.StreamingGateway` | 8081 | YARP proxy that validates the stream ticket and serves the audio |
|
|
| `Musify.Worker` | — | MassTransit consumers: transcoding, thumbnails, YouTube downloads |
|
|
| `web-player` | 5173 / 3000 | Web client (SvelteKit, server-side OIDC session) |
|
|
| Zitadel | 8080 | Identity (OIDC/OAuth2) |
|
|
| PostgreSQL / RabbitMQ / SeaweedFS / Jaeger | 59000 / 5672 / 8333 / 16686 | Metadata, messaging, object storage, traces |
|
|
|
|
More in [docs/](docs/README.md): [architecture](docs/architecture.md),
|
|
[authentication](docs/authentication.md), [storage](docs/storage.md),
|
|
[streaming](docs/streaming.md), [media processing](docs/media-processing.md),
|
|
[development](docs/development.md).
|