Commit graph

60 commits

Author SHA1 Message Date
0d589340d9
add Comment entity, dto, repository interface 2026-05-06 22:13:37 +03:00
015e61caf7
merge auth-controller-and-routes 2026-05-06 22:12:56 +03:00
9049f1581b
implement auth controller and routes
Wires AuthController (signup, confirmEmail, login, me, logout)
to the existing auth use cases. Routes mounted under /api with
AuthMiddleware on logout/me. RepositoryServiceProvider gains
EmailConfirmationToken and Post bindings; AppServiceProvider
binds the Emailer/EmailFactory and constructs SignupUser with
the configured from-address.
2026-05-06 22:12:51 +03:00
0ffc4b546c
test auth controller signup, confirm-email, login, me, logout 2026-05-06 22:12:27 +03:00
99433a21c2
merge signup-flow-rewrite 2026-05-06 22:08:58 +03:00
f3c6e2e000
implement SignupUser two-step confirm flow
Signup now collects only email + displayName, creates an
unconfirmed user with empty password hash, mints an
EmailConfirmationToken, and dispatches a confirmation email.
Password is set during ConfirmUserEmail.
2026-05-06 22:08:54 +03:00
11f2823a30
test SignupUser two-step confirm flow 2026-05-06 22:08:25 +03:00
edb0bc0478
merge email-confirmation-domain 2026-05-06 22:07:38 +03:00
6823bdeb50
implement ConfirmUserEmail use case 2026-05-06 22:07:30 +03:00
60308988f7
test ConfirmUserEmail use case 2026-05-06 22:07:08 +03:00
2890781a56
add Emailer and EmailFactory interfaces with laravel + fake impls 2026-05-06 22:06:30 +03:00
e16cb45387
add EmailConfirmationToken persistence: model, migration, eloquent + fake repo 2026-05-06 22:05:52 +03:00
9747d07c31
test EmailConfirmationToken entity 2026-05-06 22:04:57 +03:00
03a1f02843
merge extend-user-entity 2026-05-06 22:03:56 +03:00
4b1689d17e
implement SignupUser displayname requirement 2026-05-06 22:03:49 +03:00
4829a02aac
test SignupUser displayname requirement
Adds displayname to existing assertions and new tests covering:
null/short/invalid-charset displayname, duplicate displayname,
findability by displayname. AuthenticateUser tests pick up the
seedUser displayname argument.
2026-05-06 22:03:40 +03:00
298b8634ec
extend User entity with displayname and email confirmation
Add display_name (unique) and email_confirmed_at columns plus
matching getters, DTO fields, repo methods (findByDisplayName,
update), and migration. Existing auth tests updated to construct
User with the new params.
2026-05-06 22:03:19 +03:00
d547ec2c61
test User entity displayname and email confirmation 2026-05-06 22:00:22 +03:00
eecda40273
merge post-domain 2026-05-06 21:58:29 +03:00
e9ac16377f
implement DeletePost use case 2026-05-06 21:58:25 +03:00
yisroel
fd91da6bab
test DeletePost use case
7 cases: zero postId or requesterId -> BadRequest; unknown post
is idempotent no-op; author can delete own post; admin can
delete anyone's post; non-author non-admin -> ForbiddenException;
forbidden attempts leave post intact.
2026-05-06 15:26:28 +03:00
yisroel
7fda18dde3
implement GetPost use case
validates id > 0, delegates to PostRepository->find. 58 tests
pass.
2026-05-06 15:25:56 +03:00
yisroel
eb0ebc6f63
test GetPost use case
4 cases: zero/negative id -> BadRequest; unknown id -> null
(controller maps to 404); existing id returns the Post.
GetPost takes int id directly (no Request object - the value is
trivial and controllers pull it from a route param).
2026-05-06 15:25:36 +03:00
yisroel
32cbf4229c
implement ListUserPosts use case
validates userId > 0, delegates to PostRepository->findByUserId.
54 tests pass.
2026-05-06 15:25:07 +03:00
yisroel
e97ca28237
test ListUserPosts use case
5 cases: zero/negative userId -> BadRequest; user with no posts
-> []; returns only requested user's posts (filters out other
authors); ordered newest-first by createdAt. fails red.
2026-05-06 15:24:41 +03:00
yisroel
7ec46aa8f9
implement ListRecentPosts use case
validates limit > 0 (zero or negative -> BadRequest), then
delegates to PostRepository->findRecent. 49 tests pass.
2026-05-06 15:24:15 +03:00
yisroel
e9779d8459
test ListRecentPosts use case
5 cases: zero/negative limit -> BadRequest; empty repo -> [];
returns posts ordered newest-first; respects limit truncation.
fails red - ListRecentPosts class missing.
2026-05-06 15:23:53 +03:00
yisroel
4a4e046de4
implement CreatePost use case
trims title and body, rejects empty (post-trim) values with
BadRequest. supplies createdAt from injected Clock. persists
through PostRepository->create and returns the resulting Post.
44 tests pass.
2026-05-06 15:23:21 +03:00
yisroel
504554bf7f
test CreatePost use case
7 cases: null + whitespace title -> BadRequest; null +
whitespace body -> BadRequest; valid request returns Post with
correct userId/title/body and createdAt = clock.now(); the post
is findable via the repo afterwards; title and body get trimmed
of leading/trailing whitespace. fails red - CreatePost class
absent.
2026-05-06 15:22:57 +03:00
yisroel
e3dddc60aa
add Post persistence: model, migration, eloquent + fake repo
PostModel maps posts table (id, user_id fk, title, body text,
created_at indexed). EloquentPostRepository: create, find,
findByUserId (desc by created_at), findRecent (limit, desc),
delete - chain via ::query() to keep larastan happy.
FakePostRepository sorts on read (defensive copy each return).
cascade-on-delete on user_id so removing a user nukes their
posts.

phpstan.neon suppresses staticMethod.dynamicCall under
app/*/Eloquent*Repository.php - phpstan-strict-rules flags
Eloquent's fluent builder idiom (Model::query()->orderBy())
because the static methods become instance calls mid-chain.
suppression scoped to repo files only so the rule still
applies elsewhere.
2026-05-06 15:22:22 +03:00
yisroel
73a3acd39f
add Post entity, dto, repository interface
Post: id, userId (fk -> User), title, body, createdAt as
DateTimeImmutable. CreatePostDto readonly with explicit
createdAt (use case supplies it via Clock; entity remains pure).
PostRepository: create, find, findByUserId, findRecent (limit),
delete.
2026-05-06 15:19:00 +03:00
Yisroel Baum
9ca58f3a9d
merge user-and-auth-domains
phase 2: User + Auth foundations.

User domain: entity (id, email, passwordHash, isAdmin), dto,
repository interface, eloquent + fake impls, users migration,
SignupUser use case (validates email, length, uniqueness; hashes
password; isAdmin always false on signup).

Auth domain: Clock + TokenGenerator + PasswordHasher utility
interfaces with system + bcrypt + random impls and matching
fakes. Session entity + dto + repository interface, eloquent +
fake impls, sessions migration (token primary, fk user_id
cascade, expires_at indexed). AuthenticateUser, CreateSession,
Logout use cases. AuthMiddleware reads auth_token cookie and
attaches User to request attributes.

bindings wired in AppServiceProvider + new
RepositoryServiceProvider.

37 tests, 59 assertions; stan + cs clean.
2026-05-06 15:18:23 +03:00
yisroel
2e3265e568
wire repository and utility bindings
AppServiceProvider binds Clock -> SystemClock, TokenGenerator ->
RandomTokenGenerator, PasswordHasher -> BcryptPasswordHasher.
new RepositoryServiceProvider binds UserRepository ->
EloquentUserRepository, SessionRepository ->
EloquentSessionRepository. bootstrap/providers.php registers
both. verified container resolves: app(Clock::class) returns
SystemClock. migrations create users + sessions tables with
proper unique/foreign-key/index constraints (sqlite roundtrip
confirmed).
2026-05-06 15:18:06 +03:00
yisroel
ca8a2066de
implement AuthMiddleware
reads auth_token cookie (constant COOKIE_NAME for cross-layer
sharing with the AuthController). missing/empty cookie or
unknown token -> 401 json {error: unauthenticated}. expired
session is deleted then 401 returned. valid session attaches
the User entity to request attributes under 'user' so
downstream controllers can read it via request attributes. 37
tests pass.
2026-05-06 15:16:59 +03:00
yisroel
d87215ff9b
test AuthMiddleware
4 cases: missing auth_token cookie -> 401 json
{error: unauthenticated}; unknown token -> 401; expired token
-> 401 + repo cleanup; valid token -> 200 with the User attached
to request->attributes['user']. fails red - middleware class
absent.
2026-05-06 15:16:35 +03:00
yisroel
526a1b8f61
implement Logout use case
thin pass-through to SessionRepository->deleteByToken. test
green; 33 tests pass.
2026-05-06 15:16:03 +03:00
yisroel
30e97864c8
test Logout use case
2 cases: existing token's session gets removed; unknown token
is a no-op (deleteByToken stays idempotent).
2026-05-06 15:15:46 +03:00
yisroel
0697e4af69
implement CreateSession use case
generates token via injected TokenGenerator, asks Clock for now,
sets expiry to now+7d, persists through SessionRepository->create
and returns the resulting Session. all 31 tests pass.
2026-05-06 15:15:25 +03:00
yisroel
adc60a8059
test CreateSession use case
4 cases: returns Session with the generated token + supplied
user; createdAt matches injected Clock now; expiresAt is now+7d;
session is findable via SessionRepository->findByToken. fails
red - CreateSession class missing.
2026-05-06 15:15:04 +03:00
yisroel
5b74e9d76a
implement AuthenticateUser use case
input validation: email + password required. constructs
EmailAddress vo (BadRequest on bad format). looks up user; absent
or password-mismatch -> UnauthorizedException with constant
'invalid credentials' message (no enumeration leak). password
verified through PasswordHasher->verify against stored hash on
the User entity (no separate profile lookup -> tide keeps
password on the user row). returns the User entity for the
caller (typically CreateSession + AuthController). 27 tests
pass.
2026-05-06 15:14:34 +03:00
yisroel
2731e610e5
test AuthenticateUser use case
9 cases: null/empty/malformed email -> BadRequest; null/empty
password -> BadRequest; unknown email -> Unauthorized; wrong
password -> Unauthorized; valid creds return the User entity;
isAdmin flag survives the auth round-trip. fails red - the
AuthenticateUser class does not exist yet.
2026-05-06 15:14:03 +03:00
yisroel
a108b29d19
implement SignupUser use case
validates email present + format (wraps EmailAddress vo's
InvalidArgumentException as BadRequest), password present +
>= 8 chars, then ensures email not already registered. hashes
password through injected PasswordHasher and persists via
UserRepository->create with isAdmin=false (admins are seeder-
only per plan). throws DomainException on duplicate email so
the controller layer can map it to 409. all 18 tests pass.
2026-05-06 15:13:26 +03:00
yisroel
fefc992431
test SignupUser use case
9 cases: null/empty/malformed email -> BadRequest; null or
sub-8-char password -> BadRequest; duplicate email -> DomainException;
valid signup returns User with hashed password and isAdmin=false;
user is findable by email afterwards; EmailAddress vo lowercases
the domain. fails red - SignupUser class not yet defined.
2026-05-06 15:12:52 +03:00
yisroel
05f935f275
add Session entity, persistence, fake
Session: immutable holder of token, owning User, createdAt,
expiresAt. isExpired(now) compares >= expiresAt. SessionModel
keys on token (string primary, non-incrementing). migration adds
sessions table with foreign user_id (cascade on user delete) and
indexed expires_at for cleanup queries. EloquentSessionRepository
takes UserRepository to rehydrate the owning User on findByToken;
sessions for deleted users return null. FakeSessionRepository
mirrors with an in-memory map keyed by token, defensive copies on
read.
2026-05-06 15:12:07 +03:00
yisroel
bb38e544ee
add auth utility interfaces and impls
Clock + SystemClock (DateTimeImmutable in UTC), TokenGenerator +
RandomTokenGenerator (bin2hex(random_bytes(32)) -> 64-char hex),
PasswordHasher + BcryptPasswordHasher (password_hash with
PASSWORD_DEFAULT, password_verify). matching fakes:
FakeClock with mutable setTime, FakeTokenGenerator with a
pre-seeded queue (throws once exhausted), FakePasswordHasher
returns 'hashed:<plain>' for deterministic test assertions.
composer stan now passes --memory-limit=512M (default 128M
overflows once larastan loads more rules).
2026-05-06 15:11:19 +03:00
yisroel
eca73213f5
add User persistence: model, migration, eloquent + fake repo
UserModel maps users table (id, email unique, password_hash,
is_admin bool default false). EloquentUserRepository implements
UserRepository: create from CreateUserDto, find by id,
findByEmail. toDomain() materializes a User entity wrapping email
in EmailAddress vo. FakeUserRepository: in-memory map keyed by
auto-incrementing id, returns defensive copies on read (per
youngstartup pattern). composer stan script now passes
--no-progress for cleaner ci output.
2026-05-06 15:10:21 +03:00
yisroel
533320fcac
add User entity, dto, repository interface
User holds email (EmailAddress vo), passwordHash, isAdmin - tide
keeps password and admin flag on the user row directly (no
separate profile entity like youngstartup). UserRepository
exposes find, findByEmail, create. CreateUserDto is readonly with
explicit isAdmin (per shared.md no-default-args rule).
2026-05-06 15:00:49 +03:00
Yisroel Baum
f47ea1c73d
merge harden-devshell
hot-fix: pgdata anchored to repo root, .postgres/.direnv ignored
at any nesting. resolves stray backend/.postgres tracking caught
during phase 1 merge.
2026-05-06 14:58:44 +03:00
yisroel
ee1b30d0ec
harden devshell: anchor pgdata to repo root, broaden gitignore
shellHook now derives PGDATA from $(git rev-parse --show-toplevel)
instead of $PWD. nix develop / direnv from a subdir (e.g.
backend/) used to seed a duplicate cluster at backend/.postgres
that leaked into git tracking. .gitignore loses its leading slash
on .postgres/ + .direnv/ + .pc.* so any nested cluster also gets
ignored. fallback to pwd preserves behavior outside a git repo.

968 stray backend/.postgres/* blobs already pruned from history
via git-filter-repo before this commit.
2026-05-06 14:58:27 +03:00
Yisroel Baum
0178654535 merge backend-skeleton
phase 1: laravel 12 + ddd tooling + base scaffolding
(exceptions, EmailAddress vo, dev tooling aligned with
youngstartup conventions).
2026-05-06 14:55:27 +03:00