Skip to content

Commit 9bb7d7e

Browse files
authored
Merge pull request #36 from bartstc/chore/lib-api
refactor: centralize API infrastructure with kebab-case naming
2 parents e86f40f + a86a82e commit 9bb7d7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+434
-311
lines changed

.claude/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"allow": [
44
"Bash(find:*)",
55
"Bash(ls:*)",
6+
"Bash(mkdir:*)",
7+
"Bash(rm:*)",
8+
"Bash(rg:*)",
69
"Bash(git status)",
710
"Bash(git add:*)",
811
"Bash(git commit:*)",
@@ -16,7 +19,8 @@
1619
"Bash(pnpm test:coverage)",
1720
"Bash(pnpm test:unit)",
1821
"Bash(pnpm test:storybook)",
19-
"Bash(rg:*)",
22+
"Bash(pnpm exec prettier:*)",
23+
"Bash(pnpm lint:*)",
2024
"Bash(gh pr view:*)",
2125
"Bash(gh pr diff:*)",
2226
"WebFetch(domain:docs.anthropic.com)",

CLAUDE.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
1616
| G-4 | For changes >300 LOC or >3 files, **ask for confirmation**. | ❌ Refactor large modules without human guidance. |
1717
| G-5 | Stay within the current task context. Inform the dev if it'd be better to start afresh. | ❌ Continue work from a prior prompt after "new task" – start a fresh session. |
1818
| G-6 | Modify API contracts only with explicit developer approval and clear documentation. | ❌ Change API contracts (e.g., endpoints, DTOs, mapping logic) without approval. |
19+
| G-7 | Use git commands only when explicitly requested by the developer. | ❌ Stage, commit, or push changes without explicit developer request. |
1920

2021
## Plan & Review
2122

@@ -25,12 +26,13 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
2526
- The plan should be a detailed implementation plan and the reasoning behind them, as well as tasks broken down.
2627
- If the task requires external knowledge or certain package, also research to get latest knowledge (Use Task tool for research).
2728
- Don't over plan it, always think MVP.
28-
- Once you write the plan, firstly ask me to review it. Do not continue until I approve the plan.
29+
- Once you write the plan, firstly ask me to review it. Do not start implementation until I approve the plan.
2930

3031
### While implementing
3132

32-
- You should update the plan as you work.
33-
- After you complete tasks in the plan, you should update and append detailed descriptions of the changes you made, so following tasks can be easily hand over to other engineers.
33+
- You should update the plan in .claude/tasks/TASK_NAME.md as you work.
34+
- After you complete tasks in .claude/tasks/TASK_NAME.md, you should update and append detailed descriptions of the changes you made, so following tasks can be easily hand over to other engineers.
35+
- In case of lint errors/warnings, use `pnpm lint --fix` to resolve them.
3436

3537
### Scanning Repository
3638

@@ -45,6 +47,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
4547

4648
- `pnpm dev` - Start development server on port 5173
4749
- `pnpm lint` - Run ESLint with flat config
50+
- `pnpm lint --fix` - Run ESLint and fix linting errors/warnings
4851
- `pnpm test` - Run all tests (unit + storybook)
4952
- `pnpm test:unit` - Run unit tests only
5053
- `pnpm test:storybook` - Run storybook tests only
@@ -87,6 +90,7 @@ src/
8790
│ ├── carts/ # Shopping cart feature
8891
│ ├── products/ # Product catalog feature
8992
├── lib/ # Shared libraries and utilities
93+
│ ├── api/ # Centralized API layer (queries, commands, DTOs)
9094
│ ├── components/ # Reusable UI components
9195
│ ├── http/ # HTTP client and error handling
9296
│ ├── i18n/ # Internationalization setup
@@ -111,7 +115,8 @@ Each feature follows feature slice architecture patterns with three layers:
111115
- **MSW handlers** - API mocking is centralized in `test-lib/handlers/`
112116
- **Fixture pattern** - Test data generation in `test-lib/fixtures/`
113117
- **Strong typing** - Comprehensive TypeScript usage with branded types
114-
- **Component Composition**: Features export composed components for pages to use
118+
- **Component Composition**: Features export composed components for pages to use,
119+
- **Centralized API** - All API logic consolidated in `src/lib/api/` with endpoint-based organization
115120

116121
### Path Resolution
117122

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ If configured tools and overall setup meet your requirements, you should definit
4646
- Formatting tools for numbers, monetary values, and dates (easily extendable with any date library like [DayJS](https://day.js.org/)).
4747
- State management with [Zustand](https://docs.pmnd.rs/zustand/getting-started/introduction).
4848
- API mocking with [MSW 2](https://mswjs.io/).
49+
- Centralized API architecture with endpoint-based organization and type consolidation.
4950
- A demo app with authentication presenting project structure, good practices, and used tooling in action (with a little help of [Fake Store API](https://fakestoreapi.com/docs)).
5051

5152
# Guideline

eslint.config.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,22 @@ export default config(
197197
},
198198
],
199199
},
200+
},
201+
{
202+
files: ["./src/lib/**"],
203+
rules: {
204+
"import/no-restricted-paths": [
205+
"error",
206+
{
207+
zones: [
208+
{
209+
target: "./src/lib",
210+
from: "./src/features",
211+
message: "Lib should not depend on features.",
212+
},
213+
],
214+
},
215+
],
216+
},
200217
}
201218
);
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
1-
import { omit } from "ramda";
2-
3-
import type { IUser } from "@/features/auth/types/IUser";
4-
import { httpService } from "@/lib/http";
5-
6-
import type { IUserDto } from "./types/IUserDto";
7-
8-
export const getUser = () => {
9-
// mocking current user and its cartId by passing id=1
10-
return httpService
11-
.get<IUserDto>("users/1")
12-
.then((res) => ({ ...(omit(["password"], res) as IUser), cartId: 1 }));
13-
};
1+
export { getUser } from "@/lib/api/auth/users/{user-id}/user-query";
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
1-
import { httpService } from "@/lib/http";
2-
3-
export interface ICredentials {
4-
username: string;
5-
password: string;
6-
}
7-
8-
export const loginUser = (body: ICredentials) => {
9-
return httpService.post<string>("auth/login", body);
10-
};
1+
export { loginUser } from "@/lib/api/auth/login/login-command";
2+
export type { LoginDto as ICredentials } from "@/lib/api/auth/login/login-dto";

src/features/auth/infrastructure/types/IUserDto.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/features/auth/types/IUser.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,2 @@
1-
export interface IUser {
2-
id: number;
3-
email: string;
4-
username: string;
5-
name: {
6-
firstname: string;
7-
lastname: string;
8-
};
9-
phone: string;
10-
address: IAddress;
11-
cartId: number;
12-
}
13-
14-
interface IAddress {
15-
city: string;
16-
street: string;
17-
number: number;
18-
zipcode: string;
19-
geolocation: {
20-
lat: string;
21-
long: string;
22-
};
23-
}
1+
export type { IUser } from "@/lib/api/auth/users/{user-id}/user-query";
2+
export type { IAddress } from "@/lib/api/auth/users/{user-id}/user-dto";

src/features/carts/infrastructure/types/ICartDto.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/features/carts/infrastructure/types/ICartProductDto.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)