Skip to content
Draft
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
35 changes: 35 additions & 0 deletions docs/architecture/import-aliases-and-file-structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Import Aliases & File Structure Architecture

## Overview
In accordance with [Issue #195](https://github.com/MobilityData/mobilitydatabase-web/issues/195), path aliases have been configured to eliminate deep, brittle relative path traversal (e.g. `../../../../../../../screens/Feed/Feed.functions`).

## Path Aliases Configured

In `tsconfig.json` and `jest.config.ts`:

- `@/*`: Points to `./src/*` for top-level source modules.
- `@mdb/*`: Points to `./src/app/*` for application modules, components, screens, services, and utilities.

### Comparison Example

#### Before (Brittle Relative Paths)
```typescript
import { formatProvidersSorted } from '../../../../../../../screens/Feed/Feed.functions';
import { displayFormattedDate } from '../../../../../../../utils/date';
import SectionContainer from '../../../../../../../components/SectionContainer';
import FeedReliabilityView from '../../../../../../screens/Feed/components/FeedReliabilityView';
```

#### After (Clean Module Aliases)
```typescript
import { formatProvidersSorted } from '@mdb/screens/Feed/Feed.functions';
import { displayFormattedDate } from '@mdb/utils/date';
import SectionContainer from '@mdb/components/SectionContainer';
import FeedReliabilityView from '@mdb/screens/Feed/components/FeedReliabilityView';
```

## Component Colocation Guidelines
- **Page-specific components:** Placed within the feature route folder (e.g. `src/app/[locale]/feeds/[feedDataType]/[feedId]/components/`).
- **Domain screen components:** Placed in the screen module (e.g. `src/app/screens/Feed/components/`).
- **Global cross-cutting components:** Placed at `@mdb/components/` (e.g. `Header`, `Footer`, `SectionContainer`, `SealOfReliability`).
- **Services and API types:** Placed at `@mdb/services/` for consistent client/server data fetching.
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const config: Config = {
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you based on your tsconfig.json paths)
'^@/(.*)$': '<rootDir>/src/$1',
'^@mdb/(.*)$': '<rootDir>/src/app/$1',
},
testMatch: [
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ReactElement } from 'react';
import FeedView from '../../../../../screens/Feed/FeedView';
import FeedView from '@mdb/screens/Feed/FeedView';
import FeedJsonLd from '../lib/FeedJsonLd';
import type { Metadata, ResolvingMetadata } from 'next';
import { getTranslations } from 'next-intl/server';
Expand All @@ -8,7 +8,7 @@ import { generateFeedMetadata } from '../lib/generate-feed-metadata';
import {
getCurrentUserFromCookie,
isMobilityDatabaseAdmin,
} from '../../../../../utils/auth-server';
} from '@mdb/utils/auth-server';

interface Props {
params: Promise<{ locale: string; feedDataType: string; feedId: string }>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import FeedReliabilityView from '../../../../../../screens/Feed/components/FeedReliabilityView';
import FeedReliabilityView from '@mdb/screens/Feed/components/FeedReliabilityView';
import { type ReactElement } from 'react';
import { fetchCompleteFeedData } from '../../lib/feed-data';
import { fetchAuthedSealAnalysisData } from '../../lib/seal-analysis-data';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ReactElement } from 'react';
import FeedView from '../../../../../screens/Feed/FeedView';
import FeedView from '@mdb/screens/Feed/FeedView';
import FeedJsonLd from '../lib/FeedJsonLd';
import type { Metadata, ResolvingMetadata } from 'next';
import { notFound } from 'next/navigation';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import FeedReliabilityView from '../../../../../../screens/Feed/components/FeedReliabilityView';
import FeedReliabilityView from '@mdb/screens/Feed/components/FeedReliabilityView';
import { type ReactElement } from 'react';
import { notFound } from 'next/navigation';
import { fetchGuestFeedData } from '../../lib/guest-feed-data';
Expand Down
12 changes: 6 additions & 6 deletions src/app/screens/Feed/components/FeedReliabilityView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import CriterionSection from './CriterionSection';
import CriterionStatusChip from './CriterionStatusChip';

// Utils
import { type AllFeedType } from '../../../services/feeds/utils';
import { type components } from '../../../services/feeds/types';
import { type SealAnalysisData } from '../../../[locale]/feeds/[feedDataType]/[feedId]/lib/seal-analysis-data';
import { type AllFeedType } from '@mdb/services/feeds/utils';
import { type components } from '@mdb/services/feeds/types';
import { type SealAnalysisData } from '@mdb/[locale]/feeds/[feedDataType]/[feedId]/lib/seal-analysis-data';
import {
getCriterionDisplayStatus,
type SealCriterionContext,
} from '../../../constants/sealCriteria';
} from '@mdb/constants/sealCriteria';
import { formatProvidersSorted } from '../Feed.functions';
import { displayFormattedDate } from '../../../utils/date';
import SectionContainer from '../../../components/SectionContainer';
import { displayFormattedDate } from '@mdb/utils/date';
import SectionContainer from '@mdb/components/SectionContainer';

interface Props {
feed: AllFeedType;
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
"jest",
"cypress"
],
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@mdb/*": ["./src/app/*"],
"react": [
"./node_modules/@types/react"
]
Expand Down