Skip to content

BackendParserService

reference
1 min readUpdated

Kind: Service

Source: atloria-monorepo/apps/backend-parser/src/backend-parser.service.ts

Backend Parser Service

Provides a unified interface for all backend parsers. Automatically selects the appropriate parser based on file type.

BackendParserService provides a single entry point for parsing backend source files in the Atloria monorepo. It detects the input file type, selects the matching backend parser, and returns a consistent parsing result for downstream consumers such as documentation, analysis, or code-generation workflows.

Methods

MethodSignatureReturnsDescription
onModuleInitonModuleInit()Promise<void>
onModuleDestroyonModuleDestroy()Promise<void>
initializeinitialize(config: ParserConfig)Promise<void>Initialize all parsers with configuration
getParsersgetParsers()IParser[]Get all registered parsers
getParsergetParser(name: string)`IParserundefined`
findParserForFilefindParserForFile(filePath: string)`IParserundefined`
parseFileparseFile(filePath: string, content: string)Promise<ParseResult>Parse a single file using the appropriate parser
parseFilesparseFiles(files: ParseFileInput[])Promise<ParseResult[]>Parse multiple files
parseFilesGroupedparseFilesGrouped(files: ParseFileInput[])Promise<ParseResult[]>Parse files grouped by parser type for efficiency
getSupportedPatternsgetSupportedPatterns()string[]Get supported file patterns from all parsers
getParserMetadatagetParserMetadata()`Array<{
name: string;
version: string;
supportedPatterns: string[];

}>` | Get parser metadata for registration |

Dependencies

  • NestjsParser
  • ExpressParser
  • FastAPIParser
  • DjangoParser

Where it refuses work

  • BackendParserService stops the work with an early return when !parser.

Diagram

mermaid
sequenceDiagram
  participant Client as Calling Service
  participant ParserService as BackendParserService
  participant Selector as Parser Selection
  participant Parser as Backend-Specific Parser

  Client->>ParserService: parse(filePath, sourceCode)
  ParserService->>Selector: Determine parser from file type
  Selector-->>ParserService: Matching parser
  ParserService->>Parser: parse(sourceCode, filePath)
  Parser-->>ParserService: Parsed entity metadata
  ParserService-->>Client: Unified parse result

Usage

ts
import { BackendParserService } from './backend-parser.service';

async function parseBackendFile(
  parserService: BackendParserService,
  filePath: string,
  sourceCode: string,
) {
  const result = await parserService.parse(filePath, sourceCode);

  console.log(result);
  return result;
}

// In a NestJS service or controller, inject BackendParserService
// through the constructor and pass the target file contents.

AI Coding Instructions

  • Route all backend source parsing through BackendParserService rather than instantiating individual parsers directly.
  • Add support for new backend file types by registering a dedicated parser and updating the service’s file-type selection logic.
  • Keep parser outputs consistent so consumers can handle results without knowing which parser processed the file.
  • Handle unsupported extensions and malformed source code explicitly; return actionable errors instead of silently selecting a fallback parser.
  • Preserve NestJS dependency-injection patterns when adding parser dependencies or extending this service.

Relationships

  • DEPENDS_ON → nestjsparser
  • DEPENDS_ON → expressparser
  • DEPENDS_ON → fastapiparser
  • DEPENDS_ON → djangoparser

Referenced By

  • AppModule (MODULE_PROVIDES)
  • AppModule (MODULE_EXPORTS)

Was this page helpful?

Download as PDF