Skip to content

Commit e8bf637

Browse files
committed
refactor: restructure codebase to feature-sliced architecture
Reorganize application into a feature-sliced architecture to improve modularity and maintainability. - Move shared components, hooks, and utilities into a `shared` directory and update all relevant import aliases and paths. - Centralize application constants (API, app, providers, routes, storage) into dedicated `src/constants` files for better organization. - Refactor page components (`DashboardPage`, `ProvidersPage`, `QuotaPage`) to extract business logic into dedicated presenter hooks. - Update store implementations to align with new constant paths and remove redundant comments. - Extract API response parsing logic into dedicated `services/api/parsers` to separate concerns within the API layer. - Introduce `RawApiCallResponse` type for improved type safety in API calls. feat(types): add new quota types for various providers refactor(types): remove PROVIDERS constant and ProviderId type definition refactor(types): remove AuthFilesResponse comment refactor(types): import ProviderId from '@/constants/providers' refactor(utils): remove constants.ts file
1 parent 5c8f4f2 commit e8bf637

63 files changed

Lines changed: 786 additions & 1880 deletions

Some content is hidden

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

components.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
},
1313
"iconLibrary": "lucide",
1414
"aliases": {
15-
"components": "@/components",
16-
"utils": "@/lib/utils",
17-
"ui": "@/components/ui",
18-
"lib": "@/lib",
19-
"hooks": "@/hooks"
15+
"components": "@/shared/components",
16+
"utils": "@/shared/lib/utils",
17+
"ui": "@/shared/components/ui",
18+
"lib": "@/shared/lib",
19+
"hooks": "@/shared/hooks"
2020
},
2121
"registries": {}
2222
}

src/App.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { useEffect } from 'react'
2-
import { useAuthStore, useThemeStore, useCliProxyStore, useUpdateStore } from '@/stores'
2+
import { useAuthStore } from '@/features/auth/auth.store'
3+
import { useThemeStore } from '@/features/settings/theme.store'
4+
import { useCliProxyStore } from '@/features/settings/cliProxy.store'
5+
import { useUpdateStore } from '@/features/about/update.store'
36
import { ProtectedRoute } from '@/router/ProtectedRoute'
47
import { MainRoutes } from '@/router/MainRoutes'
5-
import { LoginPage } from '@/pages/LoginPage'
6-
import Default from './layouts/default'
8+
import { LoginPage } from '@/features/auth/LoginPage'
9+
import Default from './layouts/DefaultLayout'
710
import { invoke } from '@tauri-apps/api/core'
8-
import { Toaster } from '@/components/ui/sonner'
11+
import { Toaster } from '@/shared/components/ui/sonner'
912

1013
function App() {
1114
const { isAuthenticated, restoreSession, connectionStatus } = useAuthStore()

src/constants/api.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export const MANAGEMENT_API_PREFIX = '/v0/management';
2+
export const REQUEST_TIMEOUT_MS = 30 * 1000;
3+
export const VERSION_HEADER_KEYS = ['x-cpa-version', 'x-server-version'];
4+
export const BUILD_DATE_HEADER_KEYS = ['x-cpa-build-date', 'x-server-build-date'];
5+
6+
export const ANTIGRAVITY_QUOTA_URLS = [
7+
'https://daily-cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels',
8+
'https://daily-cloudcode-pa.sandbox.googleapis.com/v1internal:fetchAvailableModels',
9+
'https://cloudcode-pa.googleapis.com/v1internal:fetchAvailableModels'
10+
];
11+
12+
export const GEMINI_CLI_QUOTA_URL = 'https://cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota';
13+
export const CODEX_USAGE_URL = 'https://chatgpt.com/backend-api/wham/usage';
14+
export const KIRO_USAGE_URL = 'https://codewhisperer.us-east-1.amazonaws.com/getUsageLimits?isEmailRequired=true&origin=AI_EDITOR&resourceType=AGENTIC_REQUEST';
15+
export const COPILOT_ENTITLEMENT_URL = 'https://api.github.com/copilot_internal/user';
16+
17+
export const ANTIGRAVITY_HEADERS: Record<string, string> = {
18+
Authorization: 'Bearer $TOKEN$',
19+
'Content-Type': 'application/json',
20+
'User-Agent': 'antigravity/1.11.5 windows/amd64'
21+
};
22+
23+
export const GEMINI_CLI_HEADERS: Record<string, string> = {
24+
Authorization: 'Bearer $TOKEN$',
25+
'Content-Type': 'application/json'
26+
};
27+
28+
export const CODEX_HEADERS: Record<string, string> = {
29+
Authorization: 'Bearer $TOKEN$',
30+
'Content-Type': 'application/json',
31+
'User-Agent': 'codex_cli_rs/0.76.0 (Debian 13.0.0; x86_64) WindowsTerminal'
32+
};
33+
34+
export const KIRO_HEADERS: Record<string, string> = {
35+
Authorization: 'Bearer $TOKEN$',
36+
'Content-Type': 'application/json',
37+
'User-Agent': 'aws-sdk-js/3.0.0 KiroIDE-0.1.0 os/windows lang/js md/nodejs/18.0.0',
38+
'x-amz-user-agent': 'aws-sdk-js/3.0.0'
39+
};
40+
41+
export const COPILOT_HEADERS: Record<string, string> = {
42+
Authorization: 'Bearer $TOKEN$',
43+
Accept: 'application/vnd.github+json',
44+
'X-GitHub-Api-Version': '2022-11-28'
45+
};

src/constants/app.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CACHE_EXPIRY_MS = 30 * 1000;
2+
export const REFRESH_EVENT = 'app://header-refresh';
3+
export const AUTH_CHECK_INTERVAL_MS = 5000;

src/constants/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './api';
2+
export * from './storage';
3+
export * from './providers';
4+
export * from './routes';
5+
export * from './app';

src/constants/providers.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { OAuthProvider } from '@/types';
2+
3+
export const PROVIDERS = [
4+
{ id: 'antigravity', name: 'Antigravity', requiresProjectId: false },
5+
{ id: 'codex', name: 'OpenAI Codex', requiresProjectId: false },
6+
{ id: 'gemini-cli', name: 'Gemini CLI', requiresProjectId: true },
7+
{ id: 'anthropic', name: 'Claude (Anthropic)', requiresProjectId: false },
8+
{ id: 'kiro', name: 'Kiro (CodeWhisperer)', requiresProjectId: false },
9+
{ id: 'copilot', name: 'GitHub Copilot', requiresProjectId: false },
10+
] as const;
11+
12+
export type ProviderId = typeof PROVIDERS[number]['id'];
13+
14+
export const WEBUI_SUPPORTED: OAuthProvider[] = ['codex', 'anthropic', 'antigravity', 'gemini-cli', 'kiro'];
15+
16+
export const CALLBACK_PROVIDER_MAP: Partial<Record<OAuthProvider, string>> = {
17+
'gemini-cli': 'gemini'
18+
};
19+
20+
export const AUTH_URL_PROVIDER_MAP: Partial<Record<OAuthProvider, string>> = {
21+
'copilot': 'github'
22+
};
23+
24+
export const ANTIGRAVITY_GROUPS = [
25+
{ id: 'claude-gpt', label: 'Claude/GPT', identifiers: ['claude-sonnet-4-5-thinking', 'claude-opus-4-5-thinking', 'claude-sonnet-4-5'] },
26+
{ id: 'gemini-3-pro', label: 'Gemini 3 Pro', identifiers: ['gemini-3-pro-high', 'gemini-3-pro-low'] },
27+
{ id: 'gemini-2-5-flash', label: 'Gemini 2.5 Flash', identifiers: ['gemini-2.5-flash', 'gemini-2.5-flash-thinking'] },
28+
{ id: 'gemini-2-5-flash-lite', label: 'Gemini 2.5 Flash Lite', identifiers: ['gemini-2.5-flash-lite'] },
29+
{ id: 'gemini-2-5-cu', label: 'Gemini 2.5 CU', identifiers: ['rev19-uic3-1p'] },
30+
{ id: 'gemini-3-flash', label: 'Gemini 3 Flash', identifiers: ['gemini-3-flash'] },
31+
{ id: 'gemini-image', label: 'Gemini 3 Pro Image', identifiers: ['gemini-3-pro-image'] }
32+
];

src/constants/routes.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
LayoutDashboard,
3+
BarChart3,
4+
Users,
5+
Settings,
6+
Info,
7+
} from 'lucide-react';
8+
9+
export const NAV_ITEMS = [
10+
{ path: '/dashboard', icon: LayoutDashboard, labelKey: 'nav.dashboard' },
11+
{ path: '/quota', icon: BarChart3, labelKey: 'nav.quota' },
12+
{ path: '/providers', icon: Users, labelKey: 'providers.title' },
13+
{ path: '/settings', icon: Settings, labelKey: 'nav.settings' },
14+
{ path: '/about', icon: Info, labelKey: 'nav.about' },
15+
] as const;
16+
17+
export const ROUTE_PATHS = {
18+
DASHBOARD: '/dashboard',
19+
QUOTA: '/quota',
20+
PROVIDERS: '/providers',
21+
SETTINGS: '/settings',
22+
ABOUT: '/about',
23+
LOGIN: '/login',
24+
} as const;

src/constants/storage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const STORAGE_KEY_AUTH = 'cli-proxy-auth';
2+
export const STORAGE_KEY_THEME = 'cli-proxy-theme';
3+
export const STORAGE_KEY_LANGUAGE = 'cli-proxy-language';
4+
export const STORAGE_KEY_CLI_PROXY = 'cli-proxy-config';

src/features/about/AboutPage.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
*/
44

55
import { useTranslation } from 'react-i18next';
6-
import { Card } from '@/components/ui/card';
7-
import { Badge } from '@/components/ui/badge';
8-
import { Button } from '@/components/ui/button';
9-
import { Progress } from '@/components/ui/progress';
10-
import { useUpdateStore } from '@/stores';
11-
import { useAppVersion } from '@/hooks';
6+
import { Card } from '@/shared/components/ui/card';
7+
import { Badge } from '@/shared/components/ui/badge';
8+
import { Button } from '@/shared/components/ui/button';
9+
import { Progress } from '@/shared/components/ui/progress';
10+
import { useUpdateStore } from '@/features/about/update.store';
11+
import { useAppVersion } from '@/shared/hooks';
1212
import { User, Github, ExternalLink, RefreshCw, Download, Loader2, CheckCircle2 } from 'lucide-react';
1313
import { open } from '@tauri-apps/plugin-shell';
1414

src/features/about/update.store.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* Update Store
3-
* Manages app update state and actions
4-
*/
5-
61
import { create } from 'zustand';
72
import { check, Update } from '@tauri-apps/plugin-updater';
83
import { relaunch } from '@tauri-apps/plugin-process';
@@ -107,7 +102,6 @@ export const useUpdateStore = create<UpdateState & UpdateActions>((set, get) =>
107102
}
108103
});
109104

110-
// Relaunch the app
111105
await relaunch();
112106
} catch (error) {
113107
set({

0 commit comments

Comments
 (0)