How checkpoint-labs/checkpoint works
Main Components
• Providers: This is the layer responsible for interacting with blockchain networks. Notice there are subdirectories for EVM and StarkNet. Each of these includes provider logic, indexers, and utility functions, so these become distinct components.
• GraphQL API Layer: Located under src/graphql, this includes the controller, resolvers, and index that likely form the gateway through which indexed contract data is queried.
• Data Storage and ORM: The files under src/orm and the Knex configuration (src/knex.ts) indicate the project leverages a relational database abstraction. The pg.ts file also hints at managing Postgres connections or queries.
• Core Library and Utilities: The main entry points and supporting utilities, including src/index.ts, src/checkpoint.ts, and src/codegen.ts, which help tie the components together.
• Dependency Injection & Container: The container.ts file suggests that dependency injection is used to manage module lifecycles.
• Stores & Caching: The src/stores directory (e.g., checkpoints.ts) represents any in-memory or temporary storage mechanisms that may cache or manage indexed data.
Relationships and Interactions
• The Providers (EVM & StarkNet) act as data sources that index blockchain events or state changes. They interact with the data storage and ORM layers to persist data.
• The GraphQL layer consumes the stored data and exposes a read-only API to consumers. The resolvers encapsulate the business logic needed to fetch and transform data from the ORM.
• The Container/Dependency Injection layer ties together providers, GraphQL controllers, and storage components, ensuring that each module’s lifecycle and dependencies are managed coherently.
• Utility modules provide supporting functions, logging, and error-handling that are used across these layers.
• Codegen and Checkpoint configuration files likely facilitate automated type generation or schema derivation from defined entities within the ORM.
Architectural Patterns & Principles
• Modular Architecture: Each major functionality (data providers, GraphQL API, Data Storage) is isolated in its own directory. This modular approach improves clarity and reusability.
• Separation of Concerns: The design separates data ingestion (providers/indexers) from data exposure (GraphQL) and persistence (ORM/database).
• Dependency Injection: The container pattern helps manage dependencies across the various modules.
• Event-driven/Indexing Workflow: The architecture likely follows a publish-subscribe or event-based pattern where providers detect blockchain events, index data, and update the datastore in near real-time.
Relevant Technologies & Frameworks
• GraphQL: Indicated by files under src/graphql, handling queries, controllers, and resolvers.
• Knex and PostgreSQL: For ORM and database interactions.
• TypeScript: Evident from tsconfig.json and the file types (e.g., .ts files in src).
• Testing Frameworks: Jest is configured for unit tests.
• Dependency injection container, which may be internally developed or integrated through a library.
Specific Elements
• Clear labels for each component:
• “StarkNet Provider” and “EVM Provider” under a “Blockchain Data Providers” section.
• “GraphQL API” subdivided into “Controller”, “Resolvers”, and “Schema”.
• “Database & ORM” to include Knex, Postgres (pg.ts), and Model definitions.
• “Core Library/Logic” featuring Checkpoint, Codegen, and Container.
• From blockchain providers to the indexing workflow.
• From database/ORM to GraphQL components.
• From the dependency injection container to individual subsystems.
Final Assembly
• Data Ingestion (Providers, Indexers)
• Data Persistence (ORM, Database)
• API Exposure (GraphQL Interface)
• Supporting elements such as the dependency injection container and utility modules feeding into these layers.