Page MenuHomePhabricator
Authored By
Fauwaz
Dec 13 2025, 11:12 PM
Size
2 KB
Referenced Files
None
Subscribers
None

README.md

# Server Architecture
## ๐Ÿ“ Project Structure
```
server/
โ”œโ”€โ”€ models/
โ”‚ โ””โ”€โ”€ Case.ts # Type definitions and interfaces
โ”œโ”€โ”€ services/
โ”‚ โ”œโ”€โ”€ wikidataService.ts # Wikidata API integration
โ”‚ โ””โ”€โ”€ caseFilterService.ts # Case filtering logic
โ”œโ”€โ”€ controllers/
โ”‚ โ””โ”€โ”€ caseController.ts # Request handlers
โ”œโ”€โ”€ server.ts # Express app setup and routes
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ tsconfig.json
```
## ๐Ÿ“‹ Module Descriptions
### Models (`models/Case.ts`)
- **Case**: Interface defining the structure of a Supreme Court case
- **CaseFilters**: Interface for filter criteria
- **FilterResponse**: Response structure for filter endpoint
- **SearchResponse**: Response structure for search endpoint
### Services
#### `services/wikidataService.ts`
- **WikidataService**: Handles all interactions with Wikidata API
- `fetchCases()`: Fetches cases from Wikidata
- `buildSparqlQuery()`: Constructs SPARQL query
- `parseWikidataResponse()`: Parses API response into Case objects
#### `services/caseFilterService.ts`
- **CaseFilterService**: Handles case filtering logic
- `filterCases()`: Main filtering function
- `matchesKeyword()`: Keyword matching logic
- `matchesYear()`: Year filtering logic
- `matchesJudge()`: Judge filtering logic
- `matchesCaseType()`: Case type filtering logic
- `validateYear()`: Year validation
### Controllers (`controllers/caseController.ts`)
- **CaseController**: Handles HTTP requests
- `search()`: Handles `/search` endpoint
- `filter()`: Handles `/filter` endpoint
### Main Server (`server.ts`)
- Express app configuration
- Route definitions
- Middleware setup
- Server initialization
## ๐Ÿ”Œ API Endpoints
### GET `/search?q={query}`
Basic keyword search endpoint.
### GET `/filter?keyword={keyword}&year={year}&judge={judge}&type={type}`
Advanced filtering endpoint with multiple parameters.
## ๐Ÿš€ Benefits of This Structure
1. **Separation of Concerns**: Each module has a single responsibility
2. **Maintainability**: Easy to locate and modify specific functionality
3. **Testability**: Services and controllers can be tested independently
4. **Scalability**: Easy to add new features without cluttering main server file
5. **Readability**: Clear organization makes code easier to understand

File Metadata

Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
22726742
Default Alt Text
README.md (2 KB)

Event Timeline